github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/model/api_test.go (about) 1 package model_test 2 3 import ( 4 "testing" 5 6 "github.com/kyma-incubator/compass/components/director/pkg/resource" 7 8 "github.com/kyma-incubator/compass/components/director/internal/domain/api" 9 10 "github.com/kyma-incubator/compass/components/director/internal/model" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestAPIDefinitionInput_ToAPIDefinitionWithBundleID(t *testing.T) { 15 // GIVEN 16 id := "foo" 17 appID := "baz" 18 appTemplateVersionID := "naz" 19 desc := "Sample" 20 name := "sample" 21 targetURL := "https://foo.bar" 22 group := "sampleGroup" 23 24 testCases := []struct { 25 Name string 26 Input *model.APIDefinitionInput 27 ResourceType resource.Type 28 ResourceID string 29 Expected *model.APIDefinition 30 }{ 31 { 32 Name: "All properties given for App", 33 Input: &model.APIDefinitionInput{ 34 Name: name, 35 Description: &desc, 36 TargetURLs: api.ConvertTargetURLToJSONArray(targetURL), 37 Group: &group, 38 }, 39 Expected: &model.APIDefinition{ 40 ApplicationID: &appID, 41 Name: name, 42 Description: &desc, 43 TargetURLs: api.ConvertTargetURLToJSONArray(targetURL), 44 Group: &group, 45 BaseEntity: &model.BaseEntity{ 46 ID: id, 47 Ready: true, 48 }, 49 }, 50 ResourceType: resource.Application, 51 ResourceID: appID, 52 }, 53 { 54 Name: "All properties given for App Template Version", 55 Input: &model.APIDefinitionInput{ 56 Name: name, 57 Description: &desc, 58 TargetURLs: api.ConvertTargetURLToJSONArray(targetURL), 59 Group: &group, 60 }, 61 Expected: &model.APIDefinition{ 62 ApplicationTemplateVersionID: &appTemplateVersionID, 63 Name: name, 64 Description: &desc, 65 TargetURLs: api.ConvertTargetURLToJSONArray(targetURL), 66 Group: &group, 67 BaseEntity: &model.BaseEntity{ 68 ID: id, 69 Ready: true, 70 }, 71 }, 72 ResourceType: resource.ApplicationTemplateVersion, 73 ResourceID: appTemplateVersionID, 74 }, 75 { 76 Name: "Nil", 77 Input: nil, 78 Expected: nil, 79 }, 80 } 81 82 for _, testCase := range testCases { 83 t.Run(testCase.Name, func(t *testing.T) { 84 // WHEN 85 result := testCase.Input.ToAPIDefinition(id, testCase.ResourceType, testCase.ResourceID, nil, 0) 86 87 // THEN 88 assert.Equal(t, testCase.Expected, result) 89 }) 90 } 91 }