|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +package modelsdkbackend |
| 4 | + |
| 5 | +import ( |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/mendixlabs/mxcli/model" |
| 9 | + "github.com/mendixlabs/mxcli/modelsdk/codec" |
| 10 | + "github.com/mendixlabs/mxcli/sdk/microflows" |
| 11 | + "go.mongodb.org/mongo-driver/v2/bson" |
| 12 | +) |
| 13 | + |
| 14 | +// TestMicroflowObjectToGen_Annotation guards that a microflow annotation note |
| 15 | +// (from @annotation) is serialized. The modelsdk write path previously had no |
| 16 | +// case for it, so @annotation was silently dropped on the default engine. |
| 17 | +func TestMicroflowObjectToGen_Annotation(t *testing.T) { |
| 18 | + ann := µflows.Annotation{ |
| 19 | + BaseMicroflowObject: microflows.BaseMicroflowObject{ |
| 20 | + BaseElement: model.BaseElement{ID: model.ID("ann-1")}, |
| 21 | + Position: model.Point{X: 100, Y: 100}, |
| 22 | + Size: model.Size{Width: 200, Height: 50}, |
| 23 | + }, |
| 24 | + Caption: "Process products", |
| 25 | + } |
| 26 | + g := microflowObjectToGen(ann) |
| 27 | + if g == nil { |
| 28 | + t.Fatal("microflowObjectToGen(Annotation) returned nil — annotation dropped") |
| 29 | + } |
| 30 | + raw, err := (&codec.Encoder{}).Encode(g) |
| 31 | + if err != nil { |
| 32 | + t.Fatalf("encode: %v", err) |
| 33 | + } |
| 34 | + r := bson.Raw(raw) |
| 35 | + if got := r.Lookup("$Type").StringValue(); got != "Microflows$Annotation" { |
| 36 | + t.Errorf("$Type = %q, want Microflows$Annotation", got) |
| 37 | + } |
| 38 | + if got := r.Lookup("Caption").StringValue(); got != "Process products" { |
| 39 | + t.Errorf("Caption = %q, want Process products", got) |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +// TestAnnotationFlowToGen guards the AnnotationFlow that connects a note to its |
| 44 | +// activity, including the version-specific line shape (Line/BezierCurve on 10+). |
| 45 | +func TestAnnotationFlowToGen(t *testing.T) { |
| 46 | + af := µflows.AnnotationFlow{ |
| 47 | + BaseElement: model.BaseElement{ID: model.ID("af-1")}, |
| 48 | + OriginID: model.ID("ann-1"), |
| 49 | + DestinationID: model.ID("act-1"), |
| 50 | + } |
| 51 | + raw, err := (&codec.Encoder{}).Encode(annotationFlowToGen(af, 11)) |
| 52 | + if err != nil { |
| 53 | + t.Fatalf("encode: %v", err) |
| 54 | + } |
| 55 | + r := bson.Raw(raw) |
| 56 | + if got := r.Lookup("$Type").StringValue(); got != "Microflows$AnnotationFlow" { |
| 57 | + t.Errorf("$Type = %q, want Microflows$AnnotationFlow", got) |
| 58 | + } |
| 59 | + if _, err := r.LookupErr("OriginPointer"); err != nil { |
| 60 | + t.Errorf("OriginPointer missing: %v", err) |
| 61 | + } |
| 62 | + if _, err := r.LookupErr("DestinationPointer"); err != nil { |
| 63 | + t.Errorf("DestinationPointer missing: %v", err) |
| 64 | + } |
| 65 | + if _, err := r.LookupErr("Line"); err != nil { |
| 66 | + t.Errorf("Line (BezierCurve) missing on major>=10: %v", err) |
| 67 | + } |
| 68 | +} |
0 commit comments