|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +package executor |
| 4 | + |
| 5 | +import ( |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/mendixlabs/mxcli/mdl/backend/mock" |
| 9 | + "github.com/mendixlabs/mxcli/model" |
| 10 | + "github.com/mendixlabs/mxcli/sdk/domainmodel" |
| 11 | + "github.com/mendixlabs/mxcli/sdk/microflows" |
| 12 | +) |
| 13 | + |
| 14 | +func TestResolveMemberChange_BareInheritedAttributeUsesDeclaringEntity(t *testing.T) { |
| 15 | + appModuleID := model.ID("synthetic-app-module") |
| 16 | + baseModuleID := model.ID("synthetic-base-module") |
| 17 | + backend := &mock.MockBackend{ |
| 18 | + GetModuleByNameFunc: func(name string) (*model.Module, error) { |
| 19 | + switch name { |
| 20 | + case "SyntheticApp": |
| 21 | + return &model.Module{BaseElement: model.BaseElement{ID: appModuleID}, Name: name}, nil |
| 22 | + case "SyntheticBase": |
| 23 | + return &model.Module{BaseElement: model.BaseElement{ID: baseModuleID}, Name: name}, nil |
| 24 | + default: |
| 25 | + return nil, nil |
| 26 | + } |
| 27 | + }, |
| 28 | + GetDomainModelFunc: func(id model.ID) (*domainmodel.DomainModel, error) { |
| 29 | + switch id { |
| 30 | + case appModuleID: |
| 31 | + return &domainmodel.DomainModel{ |
| 32 | + ContainerID: appModuleID, |
| 33 | + Entities: []*domainmodel.Entity{ |
| 34 | + { |
| 35 | + Name: "Account", |
| 36 | + GeneralizationRef: "SyntheticBase.User", |
| 37 | + }, |
| 38 | + }, |
| 39 | + }, nil |
| 40 | + case baseModuleID: |
| 41 | + return &domainmodel.DomainModel{ |
| 42 | + ContainerID: baseModuleID, |
| 43 | + Entities: []*domainmodel.Entity{ |
| 44 | + { |
| 45 | + Name: "User", |
| 46 | + Attributes: []*domainmodel.Attribute{ |
| 47 | + {Name: "CanUseWebService", Type: &domainmodel.BooleanAttributeType{}}, |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + }, nil |
| 52 | + default: |
| 53 | + return nil, nil |
| 54 | + } |
| 55 | + }, |
| 56 | + } |
| 57 | + |
| 58 | + fb := &flowBuilder{backend: backend} |
| 59 | + mc := µflows.MemberChange{} |
| 60 | + |
| 61 | + fb.resolveMemberChange(mc, "CanUseWebService", "SyntheticApp.Account") |
| 62 | + |
| 63 | + if got, want := mc.AttributeQualifiedName, "SyntheticBase.User.CanUseWebService"; got != want { |
| 64 | + t.Fatalf("AttributeQualifiedName = %q, want %q", got, want) |
| 65 | + } |
| 66 | + if mc.AssociationQualifiedName != "" { |
| 67 | + t.Fatalf("AssociationQualifiedName = %q, want empty", mc.AssociationQualifiedName) |
| 68 | + } |
| 69 | +} |
0 commit comments