@@ -37,6 +37,7 @@ import { fakePlan } from '../../../entities/plan/plan.fixture';
37
37
import { CreateSubscription , Subscription } from '../../../entities/subscription/subscription' ;
38
38
import { fakeSubscription , fakeSubscriptionResponse } from '../../../entities/subscription/subscription.fixture' ;
39
39
import { SubscriptionsResponse } from '../../../entities/subscription/subscriptions-response' ;
40
+ import { ConfigService } from '../../../services/config.service' ;
40
41
import { AppTestingModule , TESTING_BASE_URL } from '../../../testing/app-testing.module' ;
41
42
42
43
describe ( 'SubscribeToApiComponent' , ( ) => {
@@ -59,9 +60,26 @@ describe('SubscribeToApiComponent', () => {
59
60
const APP_ID_NO_SUBSCRIPTIONS = 'app-id-no-subscriptions' ;
60
61
const APP_ID_ONE_API_KEY_SUBSCRIPTION = 'app-id-one-api-key-subscription' ;
61
62
62
- beforeEach ( async ( ) => {
63
+ const init = async ( sharedApiKeyModeEnabled : boolean ) => {
63
64
await TestBed . configureTestingModule ( {
64
65
imports : [ SubscribeToApiComponent , AppTestingModule ] ,
66
+ providers : [
67
+ {
68
+ provide : ConfigService ,
69
+ useValue : {
70
+ baseURL : TESTING_BASE_URL ,
71
+ configuration : {
72
+ plan : {
73
+ security : {
74
+ sharedApiKey : {
75
+ enabled : sharedApiKeyModeEnabled ,
76
+ } ,
77
+ } ,
78
+ } ,
79
+ } ,
80
+ } ,
81
+ } ,
82
+ ] ,
65
83
} ) . compileComponents ( ) ;
66
84
67
85
fixture = TestBed . createComponent ( SubscribeToApiComponent ) ;
@@ -84,13 +102,16 @@ describe('SubscribeToApiComponent', () => {
84
102
] ,
85
103
} ) ;
86
104
fixture . detectChanges ( ) ;
87
- } ) ;
105
+ } ;
88
106
89
107
afterEach ( ( ) => {
90
108
httpTestingController . verify ( ) ;
91
109
} ) ;
92
110
93
111
describe ( 'User subscribes to Keyless plan' , ( ) => {
112
+ beforeEach ( async ( ) => {
113
+ await init ( true ) ;
114
+ } ) ;
94
115
describe ( 'Step 1 -- Choose a plan' , ( ) => {
95
116
it ( 'should be able to go to step 3 once plan chosen' , async ( ) => {
96
117
const step1 = await harnessLoader . getHarness ( SubscribeToApiChoosePlanHarness ) ;
@@ -132,6 +153,10 @@ describe('SubscribeToApiComponent', () => {
132
153
133
154
describe ( 'User subscribes to API Key plan' , ( ) => {
134
155
describe ( 'Step 1 -- Choose a plan' , ( ) => {
156
+ beforeEach ( async ( ) => {
157
+ await init ( true ) ;
158
+ } ) ;
159
+
135
160
it ( 'should choose API Key plan and go to step 2' , async ( ) => {
136
161
const step1 = await harnessLoader . getHarness ( SubscribeToApiChoosePlanHarness ) ;
137
162
expect ( step1 ) . toBeTruthy ( ) ;
@@ -153,6 +178,8 @@ describe('SubscribeToApiComponent', () => {
153
178
} ) ;
154
179
describe ( 'Step 2 -- Choose an application' , ( ) => {
155
180
beforeEach ( async ( ) => {
181
+ await init ( true ) ;
182
+
156
183
const step1 = await harnessLoader . getHarness ( SubscribeToApiChoosePlanHarness ) ;
157
184
await step1 . selectPlanByPlanId ( API_KEY_PLAN_ID ) ;
158
185
await goToNextStep ( ) ;
@@ -313,6 +340,7 @@ describe('SubscribeToApiComponent', () => {
313
340
describe ( 'Step 3 -- Checkout' , ( ) => {
314
341
describe ( 'When comment is required' , ( ) => {
315
342
beforeEach ( async ( ) => {
343
+ await init ( true ) ;
316
344
await selectPlan ( API_KEY_PLAN_ID_COMMENT_REQUIRED ) ;
317
345
await selectApplication ( ) ;
318
346
@@ -346,6 +374,7 @@ describe('SubscribeToApiComponent', () => {
346
374
contentRevisionId : { revision : 2 , pageId : GENERAL_CONDITIONS_ID } ,
347
375
} ) ;
348
376
beforeEach ( async ( ) => {
377
+ await init ( true ) ;
349
378
await selectPlan ( API_KEY_PLAN_ID_GENERAL_CONDITIONS ) ;
350
379
await selectApplication ( ) ;
351
380
@@ -388,6 +417,7 @@ describe('SubscribeToApiComponent', () => {
388
417
describe ( 'API Key Management' , ( ) => {
389
418
describe ( 'When a chosen application has no existing subscriptions' , ( ) => {
390
419
beforeEach ( async ( ) => {
420
+ await init ( true ) ;
391
421
await selectPlan ( API_KEY_PLAN_ID ) ;
392
422
await selectApplication ( APP_ID_NO_SUBSCRIPTIONS ) ;
393
423
@@ -411,49 +441,86 @@ describe('SubscribeToApiComponent', () => {
411
441
} ) ;
412
442
describe ( 'When a chosen application has one existing API Key subscription' , ( ) => {
413
443
describe ( 'When the existing API Key subscription is with current API' , ( ) => {
414
- beforeEach ( async ( ) => {
415
- await selectPlan ( API_KEY_PLAN_ID ) ;
416
- await selectApplication ( APP_ID_ONE_API_KEY_SUBSCRIPTION ) ;
417
-
418
- expectGetApi ( ) ;
419
- expectGetSubscriptionsForApplication (
420
- APP_ID_ONE_API_KEY_SUBSCRIPTION ,
421
- fakeSubscriptionResponse ( {
422
- data : [ fakeSubscription ( { plan : 'plan-id' , api : API_ID } ) ] ,
423
- metadata : {
424
- 'plan-id' : { securityType : 'API_KEY' } ,
425
- } ,
426
- } ) ,
427
- ) ;
428
- fixture . detectChanges ( ) ;
429
- } ) ;
430
- it ( 'should show api key mode choice + only allow exclusive' , async ( ) => {
431
- const step3 = await harnessLoader . getHarness ( SubscribeToApiCheckoutHarness ) ;
432
- expect ( await step3 . isChooseApiKeyModeVisible ( ) ) . toBeTruthy ( ) ;
444
+ describe ( 'When Shared API Key mode is enabled' , ( ) => {
445
+ beforeEach ( async ( ) => {
446
+ await init ( true ) ;
447
+ await selectPlan ( API_KEY_PLAN_ID ) ;
448
+ await selectApplication ( APP_ID_ONE_API_KEY_SUBSCRIPTION ) ;
449
+
450
+ expectGetApi ( ) ;
451
+ expectGetSubscriptionsForApplication (
452
+ APP_ID_ONE_API_KEY_SUBSCRIPTION ,
453
+ fakeSubscriptionResponse ( {
454
+ data : [ fakeSubscription ( { plan : 'plan-id' , api : API_ID } ) ] ,
455
+ metadata : {
456
+ 'plan-id' : { securityType : 'API_KEY' } ,
457
+ } ,
458
+ } ) ,
459
+ ) ;
460
+ fixture . detectChanges ( ) ;
461
+ } ) ;
462
+ it ( 'should show api key mode choice + only allow exclusive' , async ( ) => {
463
+ const step3 = await harnessLoader . getHarness ( SubscribeToApiCheckoutHarness ) ;
464
+ expect ( await step3 . isChooseApiKeyModeVisible ( ) ) . toBeTruthy ( ) ;
433
465
434
- const sharedApiKeyOption = await step3 . getSharedApiKeyRadio ( ) ;
435
- expect ( await sharedApiKeyOption . isDisabled ( ) ) . toEqual ( true ) ;
466
+ const sharedApiKeyOption = await step3 . getSharedApiKeyRadio ( ) ;
467
+ expect ( await sharedApiKeyOption . isDisabled ( ) ) . toEqual ( true ) ;
436
468
437
- const generatedApiKeyOption = await step3 . getGeneratedApiKeyRadio ( ) ;
438
- expect ( await generatedApiKeyOption . isDisabled ( ) ) . toEqual ( false ) ;
469
+ const generatedApiKeyOption = await step3 . getGeneratedApiKeyRadio ( ) ;
470
+ expect ( await generatedApiKeyOption . isDisabled ( ) ) . toEqual ( false ) ;
471
+ } ) ;
472
+ it ( 'should create subscription' , async ( ) => {
473
+ const step3 = await harnessLoader . getHarness ( SubscribeToApiCheckoutHarness ) ;
474
+ const generatedApiKeyOption = await step3 . getGeneratedApiKeyRadio ( ) ;
475
+ await generatedApiKeyOption . select ( ) ;
476
+
477
+ const subscribe = await getSubscribeButton ( ) ;
478
+ await subscribe ?. click ( ) ;
479
+
480
+ expectPostCreateSubscription ( {
481
+ plan : API_KEY_PLAN_ID ,
482
+ application : APP_ID_ONE_API_KEY_SUBSCRIPTION ,
483
+ api_key_mode : 'EXCLUSIVE' ,
484
+ } ) ;
485
+ } ) ;
439
486
} ) ;
440
- it ( 'should create subscription' , async ( ) => {
441
- const step3 = await harnessLoader . getHarness ( SubscribeToApiCheckoutHarness ) ;
442
- const generatedApiKeyOption = await step3 . getGeneratedApiKeyRadio ( ) ;
443
- await generatedApiKeyOption . select ( ) ;
444
-
445
- const subscribe = await getSubscribeButton ( ) ;
446
- await subscribe ?. click ( ) ;
487
+ describe ( 'When Shared API Key mode is disabled' , ( ) => {
488
+ beforeEach ( async ( ) => {
489
+ await init ( false ) ;
490
+ await selectPlan ( API_KEY_PLAN_ID ) ;
491
+ await selectApplication ( APP_ID_ONE_API_KEY_SUBSCRIPTION ) ;
492
+
493
+ expectGetApi ( ) ;
494
+ expectGetSubscriptionsForApplication (
495
+ APP_ID_ONE_API_KEY_SUBSCRIPTION ,
496
+ fakeSubscriptionResponse ( {
497
+ data : [ fakeSubscription ( { plan : 'plan-id' , api : API_ID } ) ] ,
498
+ metadata : {
499
+ 'plan-id' : { securityType : 'API_KEY' } ,
500
+ } ,
501
+ } ) ,
502
+ ) ;
503
+ fixture . detectChanges ( ) ;
504
+ } ) ;
447
505
448
- expectPostCreateSubscription ( {
449
- plan : API_KEY_PLAN_ID ,
450
- application : APP_ID_ONE_API_KEY_SUBSCRIPTION ,
451
- api_key_mode : 'EXCLUSIVE' ,
506
+ it ( 'should not show api key mode selection' , async ( ) => {
507
+ const step3 = await harnessLoader . getHarness ( SubscribeToApiCheckoutHarness ) ;
508
+ expect ( await step3 . isChooseApiKeyModeVisible ( ) ) . toBeFalsy ( ) ;
509
+ } ) ;
510
+ it ( 'should create subscription' , async ( ) => {
511
+ const subscribe = await getSubscribeButton ( ) ;
512
+ await subscribe ?. click ( ) ;
513
+
514
+ expectPostCreateSubscription ( {
515
+ plan : API_KEY_PLAN_ID ,
516
+ application : APP_ID_ONE_API_KEY_SUBSCRIPTION ,
517
+ } ) ;
452
518
} ) ;
453
519
} ) ;
454
520
} ) ;
455
521
describe ( 'When the existing API Key subscription is for a different API' , ( ) => {
456
522
beforeEach ( async ( ) => {
523
+ await init ( true ) ;
457
524
await selectPlan ( API_KEY_PLAN_ID ) ;
458
525
await selectApplication ( APP_ID_ONE_API_KEY_SUBSCRIPTION ) ;
459
526
@@ -499,6 +566,7 @@ describe('SubscribeToApiComponent', () => {
499
566
} ) ;
500
567
describe ( 'When the API is Federated' , ( ) => {
501
568
beforeEach ( async ( ) => {
569
+ await init ( true ) ;
502
570
await selectPlan ( API_KEY_PLAN_ID ) ;
503
571
await selectApplication ( APP_ID_ONE_API_KEY_SUBSCRIPTION ) ;
504
572
@@ -523,6 +591,7 @@ describe('SubscribeToApiComponent', () => {
523
591
524
592
describe ( 'When comment is NOT required + Terms and conditions NOT required' , ( ) => {
525
593
beforeEach ( async ( ) => {
594
+ await init ( true ) ;
526
595
await selectPlan ( API_KEY_PLAN_ID ) ;
527
596
await selectApplication ( ) ;
528
597
@@ -552,6 +621,9 @@ describe('SubscribeToApiComponent', () => {
552
621
} ) ;
553
622
554
623
describe ( 'User subscribes to OAuth2 plan' , ( ) => {
624
+ beforeEach ( async ( ) => {
625
+ await init ( true ) ;
626
+ } ) ;
555
627
describe ( 'Step 1 -- Choose a plan' , ( ) => {
556
628
it ( 'should be disabled' , async ( ) => {
557
629
const step1 = await harnessLoader . getHarness ( SubscribeToApiChoosePlanHarness ) ;
@@ -565,6 +637,9 @@ describe('SubscribeToApiComponent', () => {
565
637
} ) ;
566
638
567
639
describe ( 'User subscribes to JWT plan' , ( ) => {
640
+ beforeEach ( async ( ) => {
641
+ await init ( true ) ;
642
+ } ) ;
568
643
describe ( 'Step 1 -- Choose a plan' , ( ) => {
569
644
it ( 'should be disabled' , async ( ) => {
570
645
const step1 = await harnessLoader . getHarness ( SubscribeToApiChoosePlanHarness ) ;
0 commit comments