|
8 | 8 | "github.com/mendixlabs/mxcli/model" |
9 | 9 | "github.com/mendixlabs/mxcli/sdk/microflows" |
10 | 10 | "go.mongodb.org/mongo-driver/bson" |
| 11 | + "go.mongodb.org/mongo-driver/bson/primitive" |
11 | 12 | ) |
12 | 13 |
|
13 | 14 | // TestShowPageAction_Roundtrip verifies that a ShowPageAction with parameters |
@@ -62,6 +63,59 @@ func TestShowPageAction_Roundtrip(t *testing.T) { |
62 | 63 | } |
63 | 64 | } |
64 | 65 |
|
| 66 | +func TestShowPageAction_WritesValidPageParameterMapping(t *testing.T) { |
| 67 | + action := µflows.ShowPageAction{ |
| 68 | + BaseElement: model.BaseElement{ID: "test-action-id"}, |
| 69 | + PageName: "Sales.Product_NewEdit", |
| 70 | + PageParameterMappings: []*microflows.PageParameterMapping{ |
| 71 | + { |
| 72 | + BaseElement: model.BaseElement{ID: "test-mapping-id"}, |
| 73 | + Parameter: "Sales.Product_NewEdit.Product", |
| 74 | + Argument: "$Product", |
| 75 | + }, |
| 76 | + }, |
| 77 | + } |
| 78 | + |
| 79 | + doc := serializeMicroflowAction(action) |
| 80 | + data, err := bson.Marshal(doc) |
| 81 | + if err != nil { |
| 82 | + t.Fatalf("failed to marshal BSON: %v", err) |
| 83 | + } |
| 84 | + |
| 85 | + var raw map[string]any |
| 86 | + if err := bson.Unmarshal(data, &raw); err != nil { |
| 87 | + t.Fatalf("failed to unmarshal BSON: %v", err) |
| 88 | + } |
| 89 | + |
| 90 | + formSettings := toMap(raw["FormSettings"]) |
| 91 | + if formSettings == nil { |
| 92 | + t.Fatal("FormSettings missing") |
| 93 | + } |
| 94 | + |
| 95 | + mappings, ok := formSettings["ParameterMappings"].(primitive.A) |
| 96 | + if !ok { |
| 97 | + t.Fatalf("ParameterMappings type = %T, want primitive.A", formSettings["ParameterMappings"]) |
| 98 | + } |
| 99 | + if len(mappings) != 2 { |
| 100 | + t.Fatalf("ParameterMappings length = %d, want marker plus one mapping", len(mappings)) |
| 101 | + } |
| 102 | + if marker, ok := mappings[0].(int32); !ok || marker != 2 { |
| 103 | + t.Fatalf("ParameterMappings marker = %#v, want int32(2)", mappings[0]) |
| 104 | + } |
| 105 | + |
| 106 | + mapping := toMap(mappings[1]) |
| 107 | + if mapping == nil { |
| 108 | + t.Fatal("PageParameterMapping missing") |
| 109 | + } |
| 110 | + variable := toMap(mapping["Variable"]) |
| 111 | + if variable == nil { |
| 112 | + t.Fatal("Variable is nil; Studio Pro rejects null page parameter mapping variables") |
| 113 | + } |
| 114 | + if got := extractString(variable["$Type"]); got != "Forms$PageVariable" { |
| 115 | + t.Fatalf("Variable $Type = %q, want Forms$PageVariable", got) |
| 116 | + } |
| 117 | +} |
| 118 | + |
65 | 119 | // TestShowPageAction_RoundtripNoParams verifies that a ShowPageAction without parameters |
66 | 120 | // survives BSON serialization/deserialization. |
67 | 121 | func TestShowPageAction_RoundtripNoParams(t *testing.T) { |
|
0 commit comments