github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/formationtemplate/fixtures_test.go (about) 1 package formationtemplate_test 2 3 import ( 4 "encoding/json" 5 6 "github.com/kyma-incubator/compass/components/director/internal/domain/formationconstraint/operators" 7 8 "github.com/kyma-incubator/compass/components/director/internal/domain/formationtemplate" 9 "github.com/kyma-incubator/compass/components/director/internal/domain/formationtemplate/automock" 10 "github.com/kyma-incubator/compass/components/director/internal/model" 11 "github.com/kyma-incubator/compass/components/director/internal/repo" 12 "github.com/kyma-incubator/compass/components/director/pkg/graphql" 13 "github.com/kyma-incubator/compass/components/director/pkg/pagination" 14 "github.com/kyma-incubator/compass/components/director/pkg/str" 15 "github.com/kyma-incubator/compass/components/director/pkg/tenant" 16 ) 17 18 const ( 19 testID = "d1fddec6-5456-4a1e-9ae0-74447f5d6ae9" 20 formationTemplateName = "formation-template-name" 21 applicationTypesAsString = "[\"some-application-type\"]" 22 runtimeTypesAsString = "[\"some-runtime-type\"]" 23 testTenantID = "d9fddec6-5456-4a1e-9ae0-74447f5d6ae9" 24 testParentTenantID = "d8fddec6-5456-4a1e-9ae0-74447f5d6ae9" 25 testWebhookID = "test-wh-id" 26 leadingProductIDsAsString = "[\"leading-product-id\",\"leading-product-id-2\"]" 27 ) 28 29 var ( 30 runtimeTypeDisplayName = "display-name-for-runtime" 31 artifactKindAsString = "SUBSCRIPTION" 32 runtimeArtifactKind = model.RuntimeArtifactKindSubscription 33 artifactKind = graphql.ArtifactTypeSubscription 34 nilModelEntity *model.FormationTemplate 35 emptyTemplate = `{}` 36 url = "http://foo.com" 37 modelWebhookMode = model.WebhookModeSync 38 graphqlWebhookMode = graphql.WebhookModeSync 39 applicationTypes = []string{"some-application-type"} 40 runtimeTypes = []string{"some-runtime-type"} 41 leadingProductIDs = []string{"leading-product-id", "leading-product-id-2"} 42 formationTemplateModelInput = model.FormationTemplateInput{ 43 Name: formationTemplateName, 44 ApplicationTypes: applicationTypes, 45 RuntimeTypes: runtimeTypes, 46 RuntimeTypeDisplayName: &runtimeTypeDisplayName, 47 RuntimeArtifactKind: &runtimeArtifactKind, 48 LeadingProductIDs: leadingProductIDs, 49 Webhooks: fixModelWebhookInput(), 50 } 51 formationTemplateGraphQLInput = graphql.FormationTemplateInput{ 52 Name: formationTemplateName, 53 ApplicationTypes: applicationTypes, 54 RuntimeTypes: runtimeTypes, 55 RuntimeTypeDisplayName: str.Ptr(runtimeTypeDisplayName), 56 RuntimeArtifactKind: &artifactKind, 57 LeadingProductIDs: leadingProductIDs, 58 Webhooks: fixGQLWebhookInput(), 59 } 60 61 formationTemplateModelInputAppOnly = model.FormationTemplateInput{ 62 Name: formationTemplateName, 63 ApplicationTypes: applicationTypes, 64 LeadingProductIDs: leadingProductIDs, 65 Webhooks: fixModelWebhookInput(), 66 } 67 formationTemplateGraphQLInputAppOnly = graphql.FormationTemplateInput{ 68 Name: formationTemplateName, 69 ApplicationTypes: applicationTypes, 70 LeadingProductIDs: leadingProductIDs, 71 Webhooks: fixGQLWebhookInput(), 72 } 73 formationTemplateModelAppOnly = model.FormationTemplate{ 74 ID: testID, 75 Name: formationTemplateName, 76 ApplicationTypes: applicationTypes, 77 LeadingProductIDs: leadingProductIDs, 78 TenantID: str.Ptr(testTenantID), 79 Webhooks: []*model.Webhook{fixFormationTemplateModelWebhook()}, 80 } 81 82 formationTemplateModel = model.FormationTemplate{ 83 ID: testID, 84 Name: formationTemplateName, 85 ApplicationTypes: applicationTypes, 86 RuntimeTypes: runtimeTypes, 87 RuntimeTypeDisplayName: &runtimeTypeDisplayName, 88 RuntimeArtifactKind: &runtimeArtifactKind, 89 LeadingProductIDs: leadingProductIDs, 90 TenantID: str.Ptr(testTenantID), 91 Webhooks: []*model.Webhook{fixFormationTemplateModelWebhook()}, 92 } 93 formationTemplateModelNullTenant = model.FormationTemplate{ 94 ID: testID, 95 Name: formationTemplateName, 96 ApplicationTypes: applicationTypes, 97 RuntimeTypes: runtimeTypes, 98 RuntimeTypeDisplayName: &runtimeTypeDisplayName, 99 RuntimeArtifactKind: &runtimeArtifactKind, 100 LeadingProductIDs: leadingProductIDs, 101 TenantID: nil, 102 } 103 formationTemplateEntity = formationtemplate.Entity{ 104 ID: testID, 105 Name: formationTemplateName, 106 ApplicationTypes: applicationTypesAsString, 107 RuntimeTypes: repo.NewValidNullableString(runtimeTypesAsString), 108 RuntimeTypeDisplayName: repo.NewValidNullableString(runtimeTypeDisplayName), 109 RuntimeArtifactKind: repo.NewValidNullableString(artifactKindAsString), 110 LeadingProductIDs: repo.NewNullableStringFromJSONRawMessage(json.RawMessage(leadingProductIDsAsString)), 111 TenantID: repo.NewValidNullableString(testTenantID), 112 } 113 formationTemplateEntityNullTenant = formationtemplate.Entity{ 114 ID: testID, 115 Name: formationTemplateName, 116 ApplicationTypes: applicationTypesAsString, 117 RuntimeTypes: repo.NewValidNullableString(runtimeTypesAsString), 118 RuntimeTypeDisplayName: repo.NewValidNullableString(runtimeTypeDisplayName), 119 RuntimeArtifactKind: repo.NewValidNullableString(artifactKindAsString), 120 LeadingProductIDs: repo.NewNullableStringFromJSONRawMessage(json.RawMessage(leadingProductIDsAsString)), 121 TenantID: repo.NewValidNullableString(""), 122 } 123 graphQLFormationTemplate = graphql.FormationTemplate{ 124 ID: testID, 125 Name: formationTemplateName, 126 ApplicationTypes: applicationTypes, 127 RuntimeTypes: runtimeTypes, 128 RuntimeTypeDisplayName: &runtimeTypeDisplayName, 129 RuntimeArtifactKind: &artifactKind, 130 LeadingProductIDs: leadingProductIDs, 131 Webhooks: []*graphql.Webhook{fixFormationTemplateGQLWebhook()}, 132 } 133 formationTemplateModelPage = model.FormationTemplatePage{ 134 Data: []*model.FormationTemplate{&formationTemplateModel}, 135 PageInfo: &pagination.Page{ 136 StartCursor: "start", 137 EndCursor: "end", 138 HasNextPage: false, 139 }, 140 TotalCount: 1, 141 } 142 formationTemplateModelNullTenantPage = model.FormationTemplatePage{ 143 Data: []*model.FormationTemplate{&formationTemplateModelNullTenant}, 144 PageInfo: &pagination.Page{ 145 StartCursor: "start", 146 EndCursor: "end", 147 HasNextPage: false, 148 }, 149 TotalCount: 1, 150 } 151 graphQLFormationTemplatePage = graphql.FormationTemplatePage{ 152 Data: []*graphql.FormationTemplate{&graphQLFormationTemplate}, 153 PageInfo: &graphql.PageInfo{ 154 StartCursor: "start", 155 EndCursor: "end", 156 HasNextPage: false, 157 }, 158 TotalCount: 1, 159 } 160 161 constraintID1 = "constraintID1" 162 constraintID2 = "constraintID2" 163 operatorName = operators.IsNotAssignedToAnyFormationOfTypeOperator 164 formationConstraintName = "constraint-name" 165 resourceSubtype = "test subtype" 166 inputTemplate = `{"formation_template_id": "{{.FormationTemplateID}}","resource_type": "{{.ResourceType}}","resource_subtype": "{{.ResourceSubtype}}","resource_id": "{{.ResourceID}}","tenant": "{{.TenantID}}"}` 167 168 formationConstraint1 = &model.FormationConstraint{ 169 ID: constraintID1, 170 Name: formationConstraintName, 171 ConstraintType: model.PreOperation, 172 TargetOperation: model.AssignFormationOperation, 173 Operator: operatorName, 174 ResourceType: model.ApplicationResourceType, 175 ResourceSubtype: resourceSubtype, 176 InputTemplate: inputTemplate, 177 ConstraintScope: model.FormationTypeFormationConstraintScope, 178 } 179 formationConstraint2 = &model.FormationConstraint{ 180 ID: constraintID2, 181 Name: formationConstraintName, 182 ConstraintType: model.PreOperation, 183 TargetOperation: model.AssignFormationOperation, 184 Operator: operatorName, 185 ResourceType: model.ApplicationResourceType, 186 ResourceSubtype: resourceSubtype, 187 InputTemplate: inputTemplate, 188 ConstraintScope: model.FormationTypeFormationConstraintScope, 189 } 190 191 formationConstraintGql1 = &graphql.FormationConstraint{ 192 ID: constraintID1, 193 Name: formationConstraintName, 194 ConstraintType: graphql.ConstraintTypePre.String(), 195 TargetOperation: graphql.TargetOperationAssignFormation.String(), 196 Operator: operatorName, 197 ResourceType: graphql.ResourceTypeApplication.String(), 198 ResourceSubtype: resourceSubtype, 199 InputTemplate: inputTemplate, 200 ConstraintScope: graphql.ConstraintScopeFormationType.String(), 201 } 202 formationConstraintGql2 = &graphql.FormationConstraint{ 203 ID: constraintID2, 204 Name: formationConstraintName, 205 ConstraintType: graphql.ConstraintTypePre.String(), 206 TargetOperation: graphql.TargetOperationAssignFormation.String(), 207 Operator: operatorName, 208 ResourceType: graphql.ResourceTypeApplication.String(), 209 ResourceSubtype: resourceSubtype, 210 InputTemplate: inputTemplate, 211 ConstraintScope: graphql.ConstraintScopeFormationType.String(), 212 } 213 ) 214 215 func newModelBusinessTenantMappingWithType(tenantType tenant.Type) *model.BusinessTenantMapping { 216 return &model.BusinessTenantMapping{ 217 ID: testTenantID, 218 Name: "name", 219 ExternalTenant: "external", 220 Parent: testParentTenantID, 221 Type: tenantType, 222 Provider: "test-provider", 223 Status: tenant.Active, 224 } 225 } 226 227 func fixModelWebhookInput() []*model.WebhookInput { 228 return []*model.WebhookInput{ 229 { 230 Type: model.WebhookTypeFormationLifecycle, 231 URL: &url, 232 Auth: &model.AuthInput{}, 233 Mode: &modelWebhookMode, 234 URLTemplate: &emptyTemplate, 235 InputTemplate: &emptyTemplate, 236 HeaderTemplate: &emptyTemplate, 237 OutputTemplate: &emptyTemplate, 238 }, 239 } 240 } 241 242 func fixGQLWebhookInput() []*graphql.WebhookInput { 243 return []*graphql.WebhookInput{ 244 { 245 Type: graphql.WebhookTypeFormationLifecycle, 246 URL: &url, 247 Auth: &graphql.AuthInput{}, 248 Mode: &graphqlWebhookMode, 249 URLTemplate: &emptyTemplate, 250 InputTemplate: &emptyTemplate, 251 HeaderTemplate: &emptyTemplate, 252 OutputTemplate: &emptyTemplate, 253 }, 254 } 255 } 256 257 func fixFormationTemplateModelWebhook() *model.Webhook { 258 return &model.Webhook{ 259 ID: testWebhookID, 260 ObjectID: testID, 261 ObjectType: model.FormationTemplateWebhookReference, 262 Type: model.WebhookTypeFormationLifecycle, 263 URL: &url, 264 Auth: &model.Auth{}, 265 Mode: &modelWebhookMode, 266 URLTemplate: &emptyTemplate, 267 InputTemplate: &emptyTemplate, 268 HeaderTemplate: &emptyTemplate, 269 OutputTemplate: &emptyTemplate, 270 } 271 } 272 273 func fixFormationTemplateGQLWebhook() *graphql.Webhook { 274 return &graphql.Webhook{ 275 ID: testWebhookID, 276 FormationTemplateID: str.Ptr(testID), 277 Type: graphql.WebhookTypeFormationLifecycle, 278 URL: &url, 279 Auth: &graphql.Auth{}, 280 Mode: &graphqlWebhookMode, 281 URLTemplate: &emptyTemplate, 282 InputTemplate: &emptyTemplate, 283 HeaderTemplate: &emptyTemplate, 284 OutputTemplate: &emptyTemplate, 285 CreatedAt: &graphql.Timestamp{}, 286 } 287 } 288 289 func fixColumns() []string { 290 return []string{"id", "name", "application_types", "runtime_types", "runtime_type_display_name", "runtime_artifact_kind", "leading_product_ids", "tenant_id"} 291 } 292 293 func UnusedFormationTemplateService() *automock.FormationTemplateService { 294 return &automock.FormationTemplateService{} 295 } 296 297 func UnusedFormationTemplateRepository() *automock.FormationTemplateRepository { 298 return &automock.FormationTemplateRepository{} 299 } 300 301 func UnusedFormationTemplateConverter() *automock.FormationTemplateConverter { 302 return &automock.FormationTemplateConverter{} 303 } 304 305 func UnusedTenantService() *automock.TenantService { 306 return &automock.TenantService{} 307 } 308 309 func UnusedWebhookService() *automock.WebhookService { 310 return &automock.WebhookService{} 311 } 312 313 func UnusedFormationConstraintService() *automock.FormationConstraintService { 314 return &automock.FormationConstraintService{} 315 } 316 317 func UnusedFormationConstraintConverter() *automock.FormationConstraintConverter { 318 return &automock.FormationConstraintConverter{} 319 }