|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +package executor |
| 4 | + |
| 5 | +import ( |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/mendixlabs/mxcli/mdl/ast" |
| 9 | + "github.com/mendixlabs/mxcli/sdk/microflows" |
| 10 | +) |
| 11 | + |
| 12 | +func TestAddToListBuilderUsesExpressionValue(t *testing.T) { |
| 13 | + fb := &flowBuilder{} |
| 14 | + |
| 15 | + fb.addAddToListAction(&ast.AddToListStmt{ |
| 16 | + Value: &ast.AttributePathExpr{ |
| 17 | + Variable: "Order", |
| 18 | + Path: []string{"Number"}, |
| 19 | + }, |
| 20 | + List: "Numbers", |
| 21 | + }) |
| 22 | + |
| 23 | + action := lastChangeListAction(t, fb) |
| 24 | + if action.Value != "$Order/Number" { |
| 25 | + t.Fatalf("Value = %q, want $Order/Number", action.Value) |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +func TestAddToListBuilderKeepsSimpleVariableFallback(t *testing.T) { |
| 30 | + fb := &flowBuilder{} |
| 31 | + |
| 32 | + fb.addAddToListAction(&ast.AddToListStmt{ |
| 33 | + Item: "Order", |
| 34 | + List: "Orders", |
| 35 | + }) |
| 36 | + |
| 37 | + action := lastChangeListAction(t, fb) |
| 38 | + if action.Value != "$Order" { |
| 39 | + t.Fatalf("Value = %q, want $Order", action.Value) |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +func lastChangeListAction(t *testing.T, fb *flowBuilder) *microflows.ChangeListAction { |
| 44 | + t.Helper() |
| 45 | + |
| 46 | + if len(fb.objects) == 0 { |
| 47 | + t.Fatal("Expected builder to create an action activity") |
| 48 | + } |
| 49 | + activity, ok := fb.objects[len(fb.objects)-1].(*microflows.ActionActivity) |
| 50 | + if !ok { |
| 51 | + t.Fatalf("Last object = %T, want ActionActivity", fb.objects[len(fb.objects)-1]) |
| 52 | + } |
| 53 | + action, ok := activity.Action.(*microflows.ChangeListAction) |
| 54 | + if !ok { |
| 55 | + t.Fatalf("Action = %T, want ChangeListAction", activity.Action) |
| 56 | + } |
| 57 | + return action |
| 58 | +} |
0 commit comments