|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +package executor |
| 4 | + |
| 5 | +import ( |
| 6 | + "fmt" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/mendixlabs/mxcli/mdl/ast" |
| 10 | + "github.com/mendixlabs/mxcli/mdl/backend/mock" |
| 11 | + mdltypes "github.com/mendixlabs/mxcli/mdl/types" |
| 12 | + "github.com/mendixlabs/mxcli/model" |
| 13 | +) |
| 14 | + |
| 15 | +func TestAddImportFromMappingRegistersSingleResultType(t *testing.T) { |
| 16 | + fb := importMappingFlowBuilder(t, "Object") |
| 17 | + |
| 18 | + fb.addImportFromMappingAction(&ast.ImportFromMappingStmt{ |
| 19 | + OutputVariable: "ImportedOrder", |
| 20 | + SourceVariable: "Payload", |
| 21 | + Mapping: ast.QualifiedName{Module: "Integration", Name: "ImportOrder"}, |
| 22 | + }) |
| 23 | + |
| 24 | + if got := fb.varTypes["ImportedOrder"]; got != "Sales.Order" { |
| 25 | + t.Fatalf("ImportedOrder type = %q, want Sales.Order", got) |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +func TestAddImportFromMappingRegistersListResultType(t *testing.T) { |
| 30 | + fb := importMappingFlowBuilder(t, "Array") |
| 31 | + |
| 32 | + fb.addImportFromMappingAction(&ast.ImportFromMappingStmt{ |
| 33 | + OutputVariable: "ImportedOrders", |
| 34 | + SourceVariable: "Payload", |
| 35 | + Mapping: ast.QualifiedName{Module: "Integration", Name: "ImportOrderList"}, |
| 36 | + }) |
| 37 | + |
| 38 | + if got := fb.varTypes["ImportedOrders"]; got != "List of Sales.Order" { |
| 39 | + t.Fatalf("ImportedOrders type = %q, want list of Sales.Order", got) |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +func importMappingFlowBuilder(t *testing.T, rootElementType string) *flowBuilder { |
| 44 | + t.Helper() |
| 45 | + |
| 46 | + return &flowBuilder{ |
| 47 | + varTypes: map[string]string{}, |
| 48 | + backend: &mock.MockBackend{ |
| 49 | + GetImportMappingByQualifiedNameFunc: func(moduleName, name string) (*model.ImportMapping, error) { |
| 50 | + if moduleName != "Integration" { |
| 51 | + return nil, fmt.Errorf("unexpected module %q", moduleName) |
| 52 | + } |
| 53 | + return &model.ImportMapping{ |
| 54 | + JsonStructure: "Integration.OrderPayload", |
| 55 | + Elements: []*model.ImportMappingElement{ |
| 56 | + {Entity: "Sales.Order"}, |
| 57 | + }, |
| 58 | + }, nil |
| 59 | + }, |
| 60 | + GetJsonStructureByQualifiedNameFunc: func(moduleName, name string) (*mdltypes.JsonStructure, error) { |
| 61 | + if moduleName != "Integration" || name != "OrderPayload" { |
| 62 | + return nil, fmt.Errorf("unexpected json structure %s.%s", moduleName, name) |
| 63 | + } |
| 64 | + return &mdltypes.JsonStructure{ |
| 65 | + Elements: []*mdltypes.JsonElement{ |
| 66 | + {ElementType: rootElementType}, |
| 67 | + }, |
| 68 | + }, nil |
| 69 | + }, |
| 70 | + }, |
| 71 | + } |
| 72 | +} |
0 commit comments