github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/pkg/scenario/directive_test.go (about) 1 package scenario_test 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/kyma-incubator/compass/components/director/pkg/str" 8 9 "github.com/kyma-incubator/compass/components/director/pkg/persistence/txtest" 10 11 "github.com/kyma-incubator/compass/components/director/internal/domain/tenant" 12 "github.com/kyma-incubator/compass/components/director/pkg/persistence" 13 14 "github.com/kyma-incubator/compass/components/director/internal/model" 15 "github.com/kyma-incubator/compass/components/director/pkg/resource" 16 17 "github.com/99designs/gqlgen/graphql" 18 bndl_mock "github.com/kyma-incubator/compass/components/director/internal/domain/bundle/automock" 19 bndl_auth_mock "github.com/kyma-incubator/compass/components/director/internal/domain/bundleinstanceauth/automock" 20 lbl_mock "github.com/kyma-incubator/compass/components/director/internal/domain/label/automock" 21 "github.com/kyma-incubator/compass/components/director/pkg/apperrors" 22 23 "github.com/kyma-incubator/compass/components/director/pkg/consumer" 24 25 "github.com/kyma-incubator/compass/components/director/pkg/scenario" 26 "github.com/stretchr/testify/assert" 27 "github.com/stretchr/testify/require" 28 ) 29 30 func TestHasScenario(t *testing.T) { 31 t.Run("could not extract consumer information, should return error", func(t *testing.T) { 32 // GIVEN 33 directive := scenario.NewDirective(nil, nil, nil, nil) 34 // WHEN 35 res, err := directive.HasScenario(context.TODO(), nil, nil, "", "") 36 // THEN 37 require.Error(t, err) 38 assert.EqualError(t, err, consumer.NoConsumerError.Error()) 39 assert.Equal(t, res, nil) 40 }) 41 42 t.Run("consumer is of type user, should proceed with next resolver", func(t *testing.T) { 43 // GIVEN 44 directive := scenario.NewDirective(nil, nil, nil, nil) 45 ctx := context.WithValue(context.TODO(), consumer.ConsumerKey, consumer.Consumer{ConsumerType: consumer.User}) 46 dummyResolver := &dummyResolver{} 47 // WHEN 48 res, err := directive.HasScenario(ctx, nil, dummyResolver.SuccessResolve, "", "") 49 // THEN 50 require.NoError(t, err) 51 assert.Equal(t, res, mockedNextOutput()) 52 }) 53 54 t.Run("consumer is of type application, should proceed with next resolver", func(t *testing.T) { 55 // GIVEN 56 directive := scenario.NewDirective(nil, nil, nil, nil) 57 ctx := context.WithValue(context.TODO(), consumer.ConsumerKey, consumer.Consumer{ConsumerType: consumer.Application}) 58 dummyResolver := &dummyResolver{} 59 // WHEN 60 res, err := directive.HasScenario(ctx, nil, dummyResolver.SuccessResolve, "", "") 61 // THEN 62 require.NoError(t, err) 63 assert.Equal(t, res, mockedNextOutput()) 64 }) 65 66 t.Run("consumer is of type integration system, should proceed with next resolver", func(t *testing.T) { 67 // GIVEN 68 directive := scenario.NewDirective(nil, nil, nil, nil) 69 ctx := context.WithValue(context.TODO(), consumer.ConsumerKey, consumer.Consumer{ConsumerType: consumer.IntegrationSystem}) 70 dummyResolver := &dummyResolver{} 71 // WHEN 72 res, err := directive.HasScenario(ctx, nil, dummyResolver.SuccessResolve, "", "") 73 // THEN 74 require.NoError(t, err) 75 assert.Equal(t, res, mockedNextOutput()) 76 }) 77 78 t.Run("could not extract tenant from context, should return error", func(t *testing.T) { 79 // GIVEN 80 directive := scenario.NewDirective(nil, nil, nil, nil) 81 ctx := context.WithValue(context.TODO(), consumer.ConsumerKey, consumer.Consumer{ConsumerType: consumer.Runtime}) 82 dummyResolver := &dummyResolver{} 83 // WHEN 84 res, err := directive.HasScenario(ctx, nil, dummyResolver.SuccessResolve, "", "") 85 // THEN 86 require.Error(t, err) 87 assert.Contains(t, err.Error(), apperrors.NewCannotReadTenantError().Error()) 88 assert.Equal(t, res, nil) 89 }) 90 91 t.Run("runtime requests non-existent application", func(t *testing.T) { 92 // GIVEN 93 const ( 94 idField = "id" 95 tenantID = "42" 96 applicationID = "24" 97 runtimeID = "23" 98 ) 99 100 lblRepo := &lbl_mock.LabelRepository{} 101 defer lblRepo.AssertExpectations(t) 102 103 mockedTx, mockedTransactioner := txtest.NewTransactionContextGenerator(nil).ThatSucceeds() 104 defer mockedTx.AssertExpectations(t) 105 defer mockedTransactioner.AssertExpectations(t) 106 107 directive := scenario.NewDirective(mockedTransactioner, lblRepo, nil, nil) 108 ctx := context.WithValue(context.TODO(), consumer.ConsumerKey, consumer.Consumer{ConsumerType: consumer.Runtime, ConsumerID: runtimeID}) 109 ctx = context.WithValue(ctx, tenant.TenantContextKey, tenant.TenantCtx{InternalID: tenantID}) 110 rCtx := &graphql.FieldContext{ 111 Object: "Application", 112 Field: graphql.CollectedField{}, 113 Args: map[string]interface{}{idField: applicationID}, 114 IsMethod: false, 115 } 116 ctx = graphql.WithFieldContext(ctx, rCtx) 117 ctxWithTx := persistence.SaveToContext(ctx, mockedTx) 118 119 notFoundErr := apperrors.NewNotFoundError(resource.Label, model.ScenariosKey) 120 lblRepo.On("GetByKey", ctxWithTx, tenantID, model.ApplicationLabelableObject, applicationID, model.ScenariosKey).Return(nil, notFoundErr) 121 lblRepo.On("GetByKey", ctxWithTx, tenantID, model.RuntimeLabelableObject, runtimeID, model.ScenariosKey).Return(nil, notFoundErr) 122 // WHEN 123 res, err := directive.HasScenario(ctx, nil, nil, scenario.GetApplicationID, idField) 124 // THEN 125 require.Error(t, err) 126 assert.Error(t, err, notFoundErr) 127 assert.Equal(t, res, nil) 128 }) 129 130 t.Run("runtime requests bundle instance auth creation for non-existent bundle", func(t *testing.T) { 131 // GIVEN 132 const ( 133 bundleIDField = "bundleID" 134 tenantID = "42" 135 bundleID = "24" 136 ) 137 138 bndlRepo := &bndl_mock.BundleRepository{} 139 defer bndlRepo.AssertExpectations(t) 140 141 mockedTx, mockedTransactioner := txtest.NewTransactionContextGenerator(nil).ThatDoesntExpectCommit() 142 defer mockedTx.AssertExpectations(t) 143 defer mockedTransactioner.AssertExpectations(t) 144 145 directive := scenario.NewDirective(mockedTransactioner, nil, bndlRepo, nil) 146 ctx := context.WithValue(context.TODO(), consumer.ConsumerKey, consumer.Consumer{ConsumerType: consumer.Runtime}) 147 ctx = context.WithValue(ctx, tenant.TenantContextKey, tenant.TenantCtx{InternalID: tenantID}) 148 rCtx := &graphql.FieldContext{ 149 Object: "BundleInstanceAuth", 150 Field: graphql.CollectedField{}, 151 Args: map[string]interface{}{bundleIDField: bundleID}, 152 IsMethod: false, 153 } 154 ctx = graphql.WithFieldContext(ctx, rCtx) 155 ctxWithTx := persistence.SaveToContext(ctx, mockedTx) 156 157 notFoundErr := apperrors.NewNotFoundErrorWithType(resource.Bundle) 158 bndlRepo.On("GetByID", ctxWithTx, tenantID, bundleID).Return(nil, notFoundErr) 159 // WHEN 160 res, err := directive.HasScenario(ctx, nil, nil, scenario.GetApplicationIDByBundle, bundleIDField) 161 // THEN 162 require.Error(t, err) 163 assert.Error(t, err, notFoundErr) 164 assert.Equal(t, res, nil) 165 }) 166 167 t.Run("runtime requests bundle instance auth deletion for non-existent system auth ID", func(t *testing.T) { 168 // GIVEN 169 const ( 170 bndlAuthIDField = "authID" 171 tenantID = "42" 172 bndlAuthID = "24" 173 ) 174 175 bndlAuthRepo := &bndl_auth_mock.Repository{} 176 defer bndlAuthRepo.AssertExpectations(t) 177 178 mockedTx, mockedTransactioner := txtest.NewTransactionContextGenerator(nil).ThatDoesntExpectCommit() 179 defer mockedTx.AssertExpectations(t) 180 defer mockedTransactioner.AssertExpectations(t) 181 182 directive := scenario.NewDirective(mockedTransactioner, nil, nil, bndlAuthRepo) 183 ctx := context.WithValue(context.TODO(), consumer.ConsumerKey, consumer.Consumer{ConsumerType: consumer.Runtime}) 184 ctx = context.WithValue(ctx, tenant.TenantContextKey, tenant.TenantCtx{InternalID: tenantID}) 185 rCtx := &graphql.FieldContext{ 186 Object: "BundleInstanceAuth", 187 Field: graphql.CollectedField{}, 188 Args: map[string]interface{}{bndlAuthIDField: bndlAuthID}, 189 IsMethod: false, 190 } 191 ctx = graphql.WithFieldContext(ctx, rCtx) 192 ctxWithTx := persistence.SaveToContext(ctx, mockedTx) 193 194 notFoundErr := apperrors.NewNotFoundErrorWithType(resource.BundleInstanceAuth) 195 bndlAuthRepo.On("GetByID", ctxWithTx, tenantID, bndlAuthID).Return(nil, notFoundErr) 196 // WHEN 197 res, err := directive.HasScenario(ctx, nil, nil, scenario.GetApplicationIDByBundleInstanceAuth, bndlAuthIDField) 198 // THEN 199 require.Error(t, err) 200 assert.Error(t, err, notFoundErr) 201 assert.Equal(t, res, nil) 202 }) 203 204 t.Run("runtime is in formation with application in application query", func(t *testing.T) { 205 // GIVEN 206 const ( 207 idField = "id" 208 tenantID = "42" 209 runtimeID = "23" 210 applicationID = "24" 211 ) 212 213 lblRepo := &lbl_mock.LabelRepository{} 214 defer lblRepo.AssertExpectations(t) 215 216 mockedTx, mockedTransactioner := txtest.NewTransactionContextGenerator(nil).ThatSucceeds() 217 defer mockedTx.AssertExpectations(t) 218 defer mockedTransactioner.AssertExpectations(t) 219 220 directive := scenario.NewDirective(mockedTransactioner, lblRepo, nil, nil) 221 ctx := context.WithValue(context.TODO(), consumer.ConsumerKey, consumer.Consumer{ConsumerID: runtimeID, ConsumerType: consumer.Runtime}) 222 ctx = context.WithValue(ctx, tenant.TenantContextKey, tenant.TenantCtx{InternalID: tenantID}) 223 rCtx := &graphql.FieldContext{ 224 Object: "Application", 225 Field: graphql.CollectedField{}, 226 Args: map[string]interface{}{idField: applicationID}, 227 IsMethod: false, 228 } 229 ctx = graphql.WithFieldContext(ctx, rCtx) 230 ctxWithTx := persistence.SaveToContext(ctx, mockedTx) 231 232 mockedLabel := &model.Label{Value: []interface{}{"DEFAULT"}} 233 lblRepo.On("GetByKey", ctxWithTx, tenantID, model.ApplicationLabelableObject, applicationID, model.ScenariosKey).Return(mockedLabel, nil) 234 lblRepo.On("GetByKey", ctxWithTx, tenantID, model.RuntimeLabelableObject, runtimeID, model.ScenariosKey).Return(mockedLabel, nil) 235 236 dummyResolver := &dummyResolver{} 237 // WHEN 238 res, err := directive.HasScenario(ctx, nil, dummyResolver.SuccessResolve, scenario.GetApplicationID, idField) 239 // THEN 240 require.NoError(t, err) 241 assert.Equal(t, res, mockedNextOutput()) 242 }) 243 244 t.Run("runtime is NOT in formation with application in application query", func(t *testing.T) { 245 // GIVEN 246 const ( 247 idField = "id" 248 tenantID = "42" 249 runtimeID = "23" 250 applicationID = "24" 251 ) 252 253 lblRepo := &lbl_mock.LabelRepository{} 254 defer lblRepo.AssertExpectations(t) 255 256 mockedTx, mockedTransactioner := txtest.NewTransactionContextGenerator(nil).ThatSucceeds() 257 defer mockedTx.AssertExpectations(t) 258 defer mockedTransactioner.AssertExpectations(t) 259 260 directive := scenario.NewDirective(mockedTransactioner, lblRepo, nil, nil) 261 ctx := context.WithValue(context.TODO(), consumer.ConsumerKey, consumer.Consumer{ConsumerID: runtimeID, ConsumerType: consumer.Runtime}) 262 ctx = context.WithValue(ctx, tenant.TenantContextKey, tenant.TenantCtx{InternalID: tenantID}) 263 rCtx := &graphql.FieldContext{ 264 Object: "Application", 265 Field: graphql.CollectedField{}, 266 Args: map[string]interface{}{idField: applicationID}, 267 IsMethod: false, 268 } 269 ctx = graphql.WithFieldContext(ctx, rCtx) 270 ctxWithTx := persistence.SaveToContext(ctx, mockedTx) 271 272 mockedAppLabel := &model.Label{Value: []interface{}{"DEFAULT"}} 273 mockedRuntimeLabel := &model.Label{Value: []interface{}{"TEST"}} 274 lblRepo.On("GetByKey", ctxWithTx, tenantID, model.ApplicationLabelableObject, applicationID, model.ScenariosKey).Return(mockedAppLabel, nil) 275 lblRepo.On("GetByKey", ctxWithTx, tenantID, model.RuntimeLabelableObject, runtimeID, model.ScenariosKey).Return(mockedRuntimeLabel, nil) 276 // WHEN 277 res, err := directive.HasScenario(ctx, nil, nil, scenario.GetApplicationID, idField) 278 // THEN 279 require.Error(t, err) 280 assert.Error(t, err, scenario.ErrMissingScenario) 281 assert.Equal(t, res, nil) 282 }) 283 284 t.Run("runtime is in formation with owning application in request bundle instance auth flow ", func(t *testing.T) { 285 // GIVEN 286 const ( 287 bundleIDField = "bundleID" 288 tenantID = "42" 289 bundleID = "24" 290 runtimeID = "23" 291 applicationID = "22" 292 ) 293 294 bndlRepo := &bndl_mock.BundleRepository{} 295 defer bndlRepo.AssertExpectations(t) 296 297 lblRepo := &lbl_mock.LabelRepository{} 298 defer lblRepo.AssertExpectations(t) 299 300 mockedTx, mockedTransactioner := txtest.NewTransactionContextGenerator(nil).ThatSucceeds() 301 defer mockedTx.AssertExpectations(t) 302 defer mockedTransactioner.AssertExpectations(t) 303 304 directive := scenario.NewDirective(mockedTransactioner, lblRepo, bndlRepo, nil) 305 ctx := context.WithValue(context.TODO(), consumer.ConsumerKey, consumer.Consumer{ConsumerID: runtimeID, ConsumerType: consumer.Runtime}) 306 ctx = context.WithValue(ctx, tenant.TenantContextKey, tenant.TenantCtx{InternalID: tenantID}) 307 rCtx := &graphql.FieldContext{ 308 Object: "BundleInstanceAuth", 309 Field: graphql.CollectedField{}, 310 Args: map[string]interface{}{bundleIDField: bundleID}, 311 IsMethod: false, 312 } 313 ctx = graphql.WithFieldContext(ctx, rCtx) 314 ctxWithTx := persistence.SaveToContext(ctx, mockedTx) 315 316 mockedBndl := &model.Bundle{ApplicationID: str.Ptr(applicationID)} 317 bndlRepo.On("GetByID", ctxWithTx, tenantID, bundleID).Return(mockedBndl, nil) 318 319 mockedLabel := &model.Label{Value: []interface{}{"DEFAULT"}} 320 lblRepo.On("GetByKey", ctxWithTx, tenantID, model.ApplicationLabelableObject, *mockedBndl.ApplicationID, model.ScenariosKey).Return(mockedLabel, nil) 321 lblRepo.On("GetByKey", ctxWithTx, tenantID, model.RuntimeLabelableObject, runtimeID, model.ScenariosKey).Return(mockedLabel, nil) 322 323 dummyResolver := &dummyResolver{} 324 // WHEN 325 res, err := directive.HasScenario(ctx, nil, dummyResolver.SuccessResolve, scenario.GetApplicationIDByBundle, bundleIDField) 326 // THEN 327 require.NoError(t, err) 328 assert.Equal(t, res, mockedNextOutput()) 329 }) 330 t.Run("runtime is NOT in formation with owning application in request bundle instance auth flow ", func(t *testing.T) { 331 // GIVEN 332 const ( 333 bundleIDField = "bundleID" 334 tenantID = "42" 335 bundleID = "24" 336 runtimeID = "23" 337 applicationID = "22" 338 ) 339 340 bndlRepo := &bndl_mock.BundleRepository{} 341 defer bndlRepo.AssertExpectations(t) 342 343 lblRepo := &lbl_mock.LabelRepository{} 344 defer lblRepo.AssertExpectations(t) 345 346 mockedTx, mockedTransactioner := txtest.NewTransactionContextGenerator(nil).ThatSucceeds() 347 defer mockedTx.AssertExpectations(t) 348 defer mockedTransactioner.AssertExpectations(t) 349 350 directive := scenario.NewDirective(mockedTransactioner, lblRepo, bndlRepo, nil) 351 ctx := context.WithValue(context.TODO(), consumer.ConsumerKey, consumer.Consumer{ConsumerID: runtimeID, ConsumerType: consumer.Runtime}) 352 ctx = context.WithValue(ctx, tenant.TenantContextKey, tenant.TenantCtx{InternalID: tenantID}) 353 rCtx := &graphql.FieldContext{ 354 Object: "BundleInstanceAuth", 355 Field: graphql.CollectedField{}, 356 Args: map[string]interface{}{bundleIDField: bundleID}, 357 IsMethod: false, 358 } 359 ctx = graphql.WithFieldContext(ctx, rCtx) 360 ctxWithTx := persistence.SaveToContext(ctx, mockedTx) 361 362 mockedBndl := &model.Bundle{ApplicationID: str.Ptr(applicationID)} 363 bndlRepo.On("GetByID", ctxWithTx, tenantID, bundleID).Return(mockedBndl, nil) 364 365 mockedAppLabel := &model.Label{Value: []interface{}{"DEFAULT"}} 366 mockedRuntimeLabel := &model.Label{Value: []interface{}{"TEST"}} 367 lblRepo.On("GetByKey", ctxWithTx, tenantID, model.ApplicationLabelableObject, applicationID, model.ScenariosKey).Return(mockedAppLabel, nil) 368 lblRepo.On("GetByKey", ctxWithTx, tenantID, model.RuntimeLabelableObject, runtimeID, model.ScenariosKey).Return(mockedRuntimeLabel, nil) 369 // WHEN 370 res, err := directive.HasScenario(ctx, nil, nil, scenario.GetApplicationIDByBundle, bundleIDField) 371 // THEN 372 require.Error(t, err) 373 assert.Error(t, err, scenario.ErrMissingScenario) 374 assert.Equal(t, res, nil) 375 }) 376 377 t.Run("runtime is in formation with owning application in delete bundle instance auth flow", func(t *testing.T) { 378 // GIVEN 379 const ( 380 bndlAuthIDField = "authID" 381 tenantID = "42" 382 bndlAuthID = "24" 383 runtimeID = "23" 384 applicationID = "22" 385 bundleID = "21" 386 ) 387 388 bndlAuthRepo := &bndl_auth_mock.Repository{} 389 defer bndlAuthRepo.AssertExpectations(t) 390 391 bndlRepo := &bndl_mock.BundleRepository{} 392 defer bndlRepo.AssertExpectations(t) 393 394 lblRepo := &lbl_mock.LabelRepository{} 395 defer lblRepo.AssertExpectations(t) 396 397 mockedTx, mockedTransactioner := txtest.NewTransactionContextGenerator(nil).ThatSucceeds() 398 defer mockedTx.AssertExpectations(t) 399 defer mockedTransactioner.AssertExpectations(t) 400 401 directive := scenario.NewDirective(mockedTransactioner, lblRepo, bndlRepo, bndlAuthRepo) 402 ctx := context.WithValue(context.TODO(), consumer.ConsumerKey, consumer.Consumer{ConsumerID: runtimeID, ConsumerType: consumer.Runtime}) 403 ctx = context.WithValue(ctx, tenant.TenantContextKey, tenant.TenantCtx{InternalID: tenantID}) 404 rCtx := &graphql.FieldContext{ 405 Object: "BundleInstanceAuth", 406 Field: graphql.CollectedField{}, 407 Args: map[string]interface{}{bndlAuthIDField: bndlAuthID}, 408 IsMethod: false, 409 } 410 ctx = graphql.WithFieldContext(ctx, rCtx) 411 ctxWithTx := persistence.SaveToContext(ctx, mockedTx) 412 413 mockedBndlAuth := &model.BundleInstanceAuth{BundleID: bundleID} 414 bndlAuthRepo.On("GetByID", ctxWithTx, tenantID, bndlAuthID).Return(mockedBndlAuth, nil) 415 416 mockedBndl := &model.Bundle{ApplicationID: str.Ptr(applicationID)} 417 bndlRepo.On("GetByID", ctxWithTx, tenantID, mockedBndlAuth.BundleID).Return(mockedBndl, nil) 418 419 mockedLabel := &model.Label{Value: []interface{}{"DEFAULT"}} 420 lblRepo.On("GetByKey", ctxWithTx, tenantID, model.ApplicationLabelableObject, *mockedBndl.ApplicationID, model.ScenariosKey).Return(mockedLabel, nil) 421 lblRepo.On("GetByKey", ctxWithTx, tenantID, model.RuntimeLabelableObject, runtimeID, model.ScenariosKey).Return(mockedLabel, nil) 422 423 dummyResolver := &dummyResolver{} 424 // WHEN 425 res, err := directive.HasScenario(ctx, nil, dummyResolver.SuccessResolve, scenario.GetApplicationIDByBundleInstanceAuth, bndlAuthIDField) 426 // THEN 427 require.NoError(t, err) 428 assert.Equal(t, res, mockedNextOutput()) 429 }) 430 t.Run("runtime is NOT in formation with owning application in delete bundle instance auth flow", func(t *testing.T) { 431 // GIVEN 432 const ( 433 bndlAuthIDField = "authID" 434 tenantID = "42" 435 bndlAuthID = "24" 436 runtimeID = "23" 437 applicationID = "22" 438 bundleID = "21" 439 ) 440 441 bndlAuthRepo := &bndl_auth_mock.Repository{} 442 defer bndlAuthRepo.AssertExpectations(t) 443 444 bndlRepo := &bndl_mock.BundleRepository{} 445 defer bndlRepo.AssertExpectations(t) 446 447 lblRepo := &lbl_mock.LabelRepository{} 448 defer lblRepo.AssertExpectations(t) 449 450 mockedTx, mockedTransactioner := txtest.NewTransactionContextGenerator(nil).ThatSucceeds() 451 defer mockedTx.AssertExpectations(t) 452 defer mockedTransactioner.AssertExpectations(t) 453 454 directive := scenario.NewDirective(mockedTransactioner, lblRepo, bndlRepo, bndlAuthRepo) 455 ctx := context.WithValue(context.TODO(), consumer.ConsumerKey, consumer.Consumer{ConsumerID: runtimeID, ConsumerType: consumer.Runtime}) 456 ctx = context.WithValue(ctx, tenant.TenantContextKey, tenant.TenantCtx{InternalID: tenantID}) 457 rCtx := &graphql.FieldContext{ 458 Object: "BundleInstanceAuth", 459 Field: graphql.CollectedField{}, 460 Args: map[string]interface{}{bndlAuthIDField: bndlAuthID}, 461 IsMethod: false, 462 } 463 ctx = graphql.WithFieldContext(ctx, rCtx) 464 ctxWithTx := persistence.SaveToContext(ctx, mockedTx) 465 466 mockedBndlAuth := &model.BundleInstanceAuth{BundleID: bundleID} 467 bndlAuthRepo.On("GetByID", ctxWithTx, tenantID, bndlAuthID).Return(mockedBndlAuth, nil) 468 469 mockedBndl := &model.Bundle{ApplicationID: str.Ptr(applicationID)} 470 bndlRepo.On("GetByID", ctxWithTx, tenantID, mockedBndlAuth.BundleID).Return(mockedBndl, nil) 471 472 mockedAppLabel := &model.Label{Value: []interface{}{"DEFAULT"}} 473 mockedRuntimeLabel := &model.Label{Value: []interface{}{"TEST"}} 474 lblRepo.On("GetByKey", ctxWithTx, tenantID, model.ApplicationLabelableObject, *mockedBndl.ApplicationID, model.ScenariosKey).Return(mockedAppLabel, nil) 475 lblRepo.On("GetByKey", ctxWithTx, tenantID, model.RuntimeLabelableObject, runtimeID, model.ScenariosKey).Return(mockedRuntimeLabel, nil) 476 // WHEN 477 res, err := directive.HasScenario(ctx, nil, nil, scenario.GetApplicationIDByBundleInstanceAuth, bndlAuthIDField) 478 // THEN 479 require.Error(t, err) 480 assert.Error(t, err, scenario.ErrMissingScenario) 481 assert.Equal(t, res, nil) 482 }) 483 } 484 485 type dummyResolver struct { 486 called bool 487 } 488 489 func (d *dummyResolver) SuccessResolve(_ context.Context) (res interface{}, err error) { 490 d.called = true 491 return mockedNextOutput(), nil 492 } 493 494 func mockedNextOutput() string { 495 return "nextOutput" 496 }