1
- import '@aws-cdk/assert-internal/jest' ;
2
- import { ResourcePart } from '@aws-cdk/assert-internal' ;
1
+ import { Match , Template } from '@aws-cdk/assertions' ;
3
2
import * as iam from '@aws-cdk/aws-iam' ;
4
3
import * as cdk from '@aws-cdk/core' ;
5
4
import * as apigateway from '../lib' ;
@@ -13,8 +12,9 @@ describe('api key', () => {
13
12
new apigateway . ApiKey ( stack , 'my-api-key' ) ;
14
13
15
14
// THEN
16
- expect ( stack ) . toHaveResource ( 'AWS::ApiGateway::ApiKey' , undefined , ResourcePart . CompleteDefinition ) ;
17
- // should have an api key with no props defined.
15
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::ApiKey' , {
16
+ Enabled : true ,
17
+ } ) ;
18
18
} ) ;
19
19
20
20
@@ -29,7 +29,7 @@ describe('api key', () => {
29
29
} ) ;
30
30
31
31
// THEN
32
- expect ( stack ) . toHaveResource ( 'AWS::ApiGateway::ApiKey' , {
32
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::ApiKey' , {
33
33
Enabled : false ,
34
34
Value : 'arandomstringwithmorethantwentycharacters' ,
35
35
} ) ;
@@ -53,7 +53,7 @@ describe('api key', () => {
53
53
} ) ;
54
54
55
55
// THEN
56
- expect ( stack ) . toHaveResource ( 'AWS::ApiGateway::ApiKey' , {
56
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::ApiKey' , {
57
57
CustomerId : 'test-customer' ,
58
58
StageKeys : [
59
59
{
@@ -76,7 +76,7 @@ describe('api key', () => {
76
76
} ) ;
77
77
78
78
// THEN
79
- expect ( stack ) . toHaveResource ( 'AWS::ApiGateway::ApiKey' , {
79
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::ApiKey' , {
80
80
Description : 'The most secret api key' ,
81
81
} ) ;
82
82
} ) ;
@@ -97,7 +97,7 @@ describe('api key', () => {
97
97
usagePlan . addApiKey ( importedKey ) ;
98
98
99
99
// THEN
100
- expect ( stack ) . toHaveResourceLike ( 'AWS::ApiGateway::UsagePlanKey' , {
100
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::UsagePlanKey' , {
101
101
KeyId : 'KeyIdabc' ,
102
102
KeyType : 'API_KEY' ,
103
103
UsagePlanId : {
@@ -125,7 +125,7 @@ describe('api key', () => {
125
125
apiKey . grantRead ( user ) ;
126
126
127
127
// THEN
128
- expect ( stack ) . toHaveResource ( 'AWS::IAM::Policy' , {
128
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::IAM::Policy' , {
129
129
PolicyDocument : {
130
130
Statement : [
131
131
{
@@ -176,7 +176,7 @@ describe('api key', () => {
176
176
apiKey . grantWrite ( user ) ;
177
177
178
178
// THEN
179
- expect ( stack ) . toHaveResource ( 'AWS::IAM::Policy' , {
179
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::IAM::Policy' , {
180
180
PolicyDocument : {
181
181
Statement : [
182
182
{
@@ -232,7 +232,7 @@ describe('api key', () => {
232
232
apiKey . grantReadWrite ( user ) ;
233
233
234
234
// THEN
235
- expect ( stack ) . toHaveResource ( 'AWS::IAM::Policy' , {
235
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::IAM::Policy' , {
236
236
PolicyDocument : {
237
237
Statement : [
238
238
{
@@ -282,11 +282,11 @@ describe('api key', () => {
282
282
283
283
// THEN
284
284
// should have an api key with no props defined.
285
- expect ( stack ) . toHaveResource ( 'AWS::ApiGateway::ApiKey' , undefined , ResourcePart . CompleteDefinition ) ;
285
+ Template . fromStack ( stack ) . hasResource ( 'AWS::ApiGateway::ApiKey' , Match . anyValue ( ) ) ;
286
286
// should not have a usage plan.
287
- expect ( stack ) . not . toHaveResource ( 'AWS::ApiGateway::UsagePlan' ) ;
287
+ Template . fromStack ( stack ) . resourceCountIs ( 'AWS::ApiGateway::UsagePlan' , 0 ) ;
288
288
// should not have a usage plan key.
289
- expect ( stack ) . not . toHaveResource ( 'AWS::ApiGateway::UsagePlanKey' ) ;
289
+ Template . fromStack ( stack ) . resourceCountIs ( 'AWS::ApiGateway::UsagePlanKey' , 0 ) ;
290
290
} ) ;
291
291
292
292
test ( 'only api key is created when rate limiting properties are not provided' , ( ) => {
@@ -306,7 +306,7 @@ describe('api key', () => {
306
306
} ) ;
307
307
308
308
// THEN
309
- expect ( stack ) . toHaveResource ( 'AWS::ApiGateway::ApiKey' , {
309
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::ApiKey' , {
310
310
CustomerId : 'test-customer' ,
311
311
StageKeys : [
312
312
{
@@ -316,9 +316,9 @@ describe('api key', () => {
316
316
] ,
317
317
} ) ;
318
318
// should not have a usage plan.
319
- expect ( stack ) . not . toHaveResource ( 'AWS::ApiGateway::UsagePlan' ) ;
319
+ Template . fromStack ( stack ) . resourceCountIs ( 'AWS::ApiGateway::UsagePlan' , 0 ) ;
320
320
// should not have a usage plan key.
321
- expect ( stack ) . not . toHaveResource ( 'AWS::ApiGateway::UsagePlanKey' ) ;
321
+ Template . fromStack ( stack ) . resourceCountIs ( 'AWS::ApiGateway::UsagePlanKey' , 0 ) ;
322
322
} ) ;
323
323
324
324
test ( 'api key and usage plan are created and linked when rate limiting properties are provided' , ( ) => {
@@ -343,7 +343,7 @@ describe('api key', () => {
343
343
344
344
// THEN
345
345
// should have an api key
346
- expect ( stack ) . toHaveResource ( 'AWS::ApiGateway::ApiKey' , {
346
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::ApiKey' , {
347
347
CustomerId : 'test-customer' ,
348
348
StageKeys : [
349
349
{
@@ -353,22 +353,22 @@ describe('api key', () => {
353
353
] ,
354
354
} ) ;
355
355
// should have a usage plan with specified quota.
356
- expect ( stack ) . toHaveResource ( 'AWS::ApiGateway::UsagePlan' , {
356
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::UsagePlan' , {
357
357
Quota : {
358
358
Limit : 10000 ,
359
359
Period : 'MONTH' ,
360
360
} ,
361
- } , ResourcePart . Properties ) ;
361
+ } ) ;
362
362
// should have a usage plan key linking the api key and usage plan
363
- expect ( stack ) . toHaveResource ( 'AWS::ApiGateway::UsagePlanKey' , {
363
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::UsagePlanKey' , {
364
364
KeyId : {
365
365
Ref : 'testapikey998028B6' ,
366
366
} ,
367
367
KeyType : 'API_KEY' ,
368
368
UsagePlanId : {
369
369
Ref : 'testapikeyUsagePlanResource66DB63D6' ,
370
370
} ,
371
- } , ResourcePart . Properties ) ;
371
+ } ) ;
372
372
} ) ;
373
373
} ) ;
374
374
} ) ;
0 commit comments