Fix user creation via wf
This commit is contained in:
parent
cfb757230e
commit
ec6ecf1132
@ -175,7 +175,7 @@ func (set ExprSet) Eval(ctx context.Context, in *expr.Vars) (*expr.Vars, error)
|
||||
}
|
||||
}
|
||||
} else if typedValue, err = e.typ.Cast(value); err != nil {
|
||||
return nil, fmt.Errorf("cannot cast value %T to %s (target %s)", value, e.typ.Type(), e.Target)
|
||||
return nil, fmt.Errorf("cannot cast value %T to %s (target %s): %w", value, e.typ.Type(), e.Target, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -31,6 +31,8 @@ func CastToUser(val interface{}) (out *types.User, err error) {
|
||||
switch val := expr.UntypedValue(val).(type) {
|
||||
case *types.User:
|
||||
return val, nil
|
||||
case nil:
|
||||
return &types.User{}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unable to cast type %T to %T", val, out)
|
||||
}
|
||||
@ -48,6 +50,8 @@ func CastToRole(val interface{}) (out *types.Role, err error) {
|
||||
switch val := expr.UntypedValue(val).(type) {
|
||||
case *types.Role:
|
||||
return val, nil
|
||||
case nil:
|
||||
return &types.Role{}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unable to cast type %T to %T", val, out)
|
||||
}
|
||||
@ -84,6 +88,8 @@ func CastToTemplateMeta(val interface{}) (out types.TemplateMeta, err error) {
|
||||
switch val := expr.UntypedValue(val).(type) {
|
||||
case types.TemplateMeta:
|
||||
return val, nil
|
||||
case nil:
|
||||
return types.TemplateMeta{}, nil
|
||||
default:
|
||||
return types.TemplateMeta{}, fmt.Errorf("unable to cast type %T to %T", val, out)
|
||||
}
|
||||
@ -144,6 +150,8 @@ func CastToQueueMessage(val interface{}) (out *types.QueueMessage, err error) {
|
||||
switch val := expr.UntypedValue(val).(type) {
|
||||
case *types.QueueMessage:
|
||||
return val, nil
|
||||
case nil:
|
||||
return &types.QueueMessage{}, nil
|
||||
default:
|
||||
return &types.QueueMessage{}, fmt.Errorf("unable to cast type %T to %T", val, out)
|
||||
}
|
||||
|
||||
28
tests/workflows/0003_create_user_test.go
Normal file
28
tests/workflows/0003_create_user_test.go
Normal file
@ -0,0 +1,28 @@
|
||||
package workflows
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
autTypes "github.com/cortezaproject/corteza-server/automation/types"
|
||||
sysTypes "github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test0003_create_user(t *testing.T) {
|
||||
var (
|
||||
ctx = bypassRBAC(context.Background())
|
||||
req = require.New(t)
|
||||
)
|
||||
|
||||
loadScenario(ctx, t)
|
||||
|
||||
var (
|
||||
aux = struct {
|
||||
User *sysTypes.User
|
||||
}{}
|
||||
vars, _ = mustExecWorkflow(ctx, t, "create-user", autTypes.WorkflowExecParams{})
|
||||
)
|
||||
|
||||
req.NoError(vars.Decode(&aux))
|
||||
}
|
||||
24
tests/workflows/testdata/S0003_create_user/workflow.yaml
vendored
Normal file
24
tests/workflows/testdata/S0003_create_user/workflow.yaml
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
workflows:
|
||||
create-user:
|
||||
enabled: true
|
||||
trace: true
|
||||
triggers:
|
||||
- enabled: true
|
||||
stepID: 1
|
||||
|
||||
steps:
|
||||
- stepID: 1
|
||||
kind: expressions
|
||||
arguments:
|
||||
- { target: dummy, type: User }
|
||||
- { target: dummy.email, type: String, value: "some.email@domain.tld" }
|
||||
- { target: dummy.name, type: String, value: "Not Sure" }
|
||||
|
||||
- stepID: 2
|
||||
kind: function
|
||||
ref: usersCreate
|
||||
arguments:
|
||||
- { target: user, type: User, expr: "dummy" }
|
||||
|
||||
paths:
|
||||
- { parentID: 1, childID: 2 }
|
||||
Loading…
x
Reference in New Issue
Block a user