|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +package mpr |
| 4 | + |
| 5 | +import ( |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/mendixlabs/mxcli/model" |
| 9 | + "github.com/mendixlabs/mxcli/sdk/microflows" |
| 10 | + "go.mongodb.org/mongo-driver/bson" |
| 11 | +) |
| 12 | + |
| 13 | +func TestSerializeCreateObjectActionItemsUseStorageListMarker(t *testing.T) { |
| 14 | + action := µflows.CreateObjectAction{ |
| 15 | + BaseElement: model.BaseElement{ID: "create-1"}, |
| 16 | + EntityQualifiedName: "SampleModule.Order", |
| 17 | + OutputVariable: "Order", |
| 18 | + Commit: microflows.CommitTypeNo, |
| 19 | + InitialMembers: []*microflows.MemberChange{ |
| 20 | + { |
| 21 | + BaseElement: model.BaseElement{ID: "member-1"}, |
| 22 | + AttributeQualifiedName: "SampleModule.Order.Name", |
| 23 | + Type: microflows.MemberChangeTypeSet, |
| 24 | + Value: "'Sample'", |
| 25 | + }, |
| 26 | + }, |
| 27 | + } |
| 28 | + |
| 29 | + doc := serializeMicroflowAction(action) |
| 30 | + |
| 31 | + items, ok := getBSONField(doc, "Items").(bson.A) |
| 32 | + if !ok { |
| 33 | + t.Fatalf("Items is %T, want bson.A", getBSONField(doc, "Items")) |
| 34 | + } |
| 35 | + if len(items) != 2 { |
| 36 | + t.Fatalf("Items length = %d, want marker plus one item", len(items)) |
| 37 | + } |
| 38 | + if marker, ok := items[0].(int32); !ok || marker != 2 { |
| 39 | + t.Fatalf("Items marker = %#v, want int32(2)", items[0]) |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +func TestSerializeChangeObjectActionItemsUseStorageListMarkerAndDefaultErrorHandling(t *testing.T) { |
| 44 | + action := µflows.ChangeObjectAction{ |
| 45 | + BaseElement: model.BaseElement{ID: "change-1"}, |
| 46 | + ChangeVariable: "Order", |
| 47 | + Commit: microflows.CommitTypeNo, |
| 48 | + Changes: []*microflows.MemberChange{ |
| 49 | + { |
| 50 | + BaseElement: model.BaseElement{ID: "member-1"}, |
| 51 | + AttributeQualifiedName: "SampleModule.Order.Status", |
| 52 | + Type: microflows.MemberChangeTypeSet, |
| 53 | + Value: "'Processed'", |
| 54 | + }, |
| 55 | + }, |
| 56 | + } |
| 57 | + |
| 58 | + doc := serializeMicroflowAction(action) |
| 59 | + |
| 60 | + if got := getBSONField(doc, "ErrorHandlingType"); got != "Rollback" { |
| 61 | + t.Fatalf("ErrorHandlingType = %#v, want Rollback", got) |
| 62 | + } |
| 63 | + items, ok := getBSONField(doc, "Items").(bson.A) |
| 64 | + if !ok { |
| 65 | + t.Fatalf("Items is %T, want bson.A", getBSONField(doc, "Items")) |
| 66 | + } |
| 67 | + if len(items) != 2 { |
| 68 | + t.Fatalf("Items length = %d, want marker plus one item", len(items)) |
| 69 | + } |
| 70 | + if marker, ok := items[0].(int32); !ok || marker != 2 { |
| 71 | + t.Fatalf("Items marker = %#v, want int32(2)", items[0]) |
| 72 | + } |
| 73 | +} |
0 commit comments