1- import '@aws-cdk/assert-internal/jest' ;
2- import { ResourcePart } from '@aws-cdk/assert-internal' ;
1+ import { Match , Template } from '@aws-cdk/assertions' ;
32import * as iam from '@aws-cdk/aws-iam' ;
43import * as cdk from '@aws-cdk/core' ;
54import * as apigateway from '../lib' ;
@@ -13,8 +12,9 @@ describe('api key', () => {
1312 new apigateway . ApiKey ( stack , 'my-api-key' ) ;
1413
1514 // 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+ } ) ;
1818 } ) ;
1919
2020
@@ -29,7 +29,7 @@ describe('api key', () => {
2929 } ) ;
3030
3131 // THEN
32- expect ( stack ) . toHaveResource ( 'AWS::ApiGateway::ApiKey' , {
32+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::ApiKey' , {
3333 Enabled : false ,
3434 Value : 'arandomstringwithmorethantwentycharacters' ,
3535 } ) ;
@@ -53,7 +53,7 @@ describe('api key', () => {
5353 } ) ;
5454
5555 // THEN
56- expect ( stack ) . toHaveResource ( 'AWS::ApiGateway::ApiKey' , {
56+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::ApiKey' , {
5757 CustomerId : 'test-customer' ,
5858 StageKeys : [
5959 {
@@ -76,7 +76,7 @@ describe('api key', () => {
7676 } ) ;
7777
7878 // THEN
79- expect ( stack ) . toHaveResource ( 'AWS::ApiGateway::ApiKey' , {
79+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::ApiKey' , {
8080 Description : 'The most secret api key' ,
8181 } ) ;
8282 } ) ;
@@ -97,7 +97,7 @@ describe('api key', () => {
9797 usagePlan . addApiKey ( importedKey ) ;
9898
9999 // THEN
100- expect ( stack ) . toHaveResourceLike ( 'AWS::ApiGateway::UsagePlanKey' , {
100+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::UsagePlanKey' , {
101101 KeyId : 'KeyIdabc' ,
102102 KeyType : 'API_KEY' ,
103103 UsagePlanId : {
@@ -125,7 +125,7 @@ describe('api key', () => {
125125 apiKey . grantRead ( user ) ;
126126
127127 // THEN
128- expect ( stack ) . toHaveResource ( 'AWS::IAM::Policy' , {
128+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::IAM::Policy' , {
129129 PolicyDocument : {
130130 Statement : [
131131 {
@@ -176,7 +176,7 @@ describe('api key', () => {
176176 apiKey . grantWrite ( user ) ;
177177
178178 // THEN
179- expect ( stack ) . toHaveResource ( 'AWS::IAM::Policy' , {
179+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::IAM::Policy' , {
180180 PolicyDocument : {
181181 Statement : [
182182 {
@@ -232,7 +232,7 @@ describe('api key', () => {
232232 apiKey . grantReadWrite ( user ) ;
233233
234234 // THEN
235- expect ( stack ) . toHaveResource ( 'AWS::IAM::Policy' , {
235+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::IAM::Policy' , {
236236 PolicyDocument : {
237237 Statement : [
238238 {
@@ -282,11 +282,11 @@ describe('api key', () => {
282282
283283 // THEN
284284 // 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 ( ) ) ;
286286 // should not have a usage plan.
287- expect ( stack ) . not . toHaveResource ( 'AWS::ApiGateway::UsagePlan' ) ;
287+ Template . fromStack ( stack ) . resourceCountIs ( 'AWS::ApiGateway::UsagePlan' , 0 ) ;
288288 // should not have a usage plan key.
289- expect ( stack ) . not . toHaveResource ( 'AWS::ApiGateway::UsagePlanKey' ) ;
289+ Template . fromStack ( stack ) . resourceCountIs ( 'AWS::ApiGateway::UsagePlanKey' , 0 ) ;
290290 } ) ;
291291
292292 test ( 'only api key is created when rate limiting properties are not provided' , ( ) => {
@@ -306,7 +306,7 @@ describe('api key', () => {
306306 } ) ;
307307
308308 // THEN
309- expect ( stack ) . toHaveResource ( 'AWS::ApiGateway::ApiKey' , {
309+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::ApiKey' , {
310310 CustomerId : 'test-customer' ,
311311 StageKeys : [
312312 {
@@ -316,9 +316,9 @@ describe('api key', () => {
316316 ] ,
317317 } ) ;
318318 // should not have a usage plan.
319- expect ( stack ) . not . toHaveResource ( 'AWS::ApiGateway::UsagePlan' ) ;
319+ Template . fromStack ( stack ) . resourceCountIs ( 'AWS::ApiGateway::UsagePlan' , 0 ) ;
320320 // should not have a usage plan key.
321- expect ( stack ) . not . toHaveResource ( 'AWS::ApiGateway::UsagePlanKey' ) ;
321+ Template . fromStack ( stack ) . resourceCountIs ( 'AWS::ApiGateway::UsagePlanKey' , 0 ) ;
322322 } ) ;
323323
324324 test ( 'api key and usage plan are created and linked when rate limiting properties are provided' , ( ) => {
@@ -343,7 +343,7 @@ describe('api key', () => {
343343
344344 // THEN
345345 // should have an api key
346- expect ( stack ) . toHaveResource ( 'AWS::ApiGateway::ApiKey' , {
346+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::ApiKey' , {
347347 CustomerId : 'test-customer' ,
348348 StageKeys : [
349349 {
@@ -353,22 +353,22 @@ describe('api key', () => {
353353 ] ,
354354 } ) ;
355355 // should have a usage plan with specified quota.
356- expect ( stack ) . toHaveResource ( 'AWS::ApiGateway::UsagePlan' , {
356+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ApiGateway::UsagePlan' , {
357357 Quota : {
358358 Limit : 10000 ,
359359 Period : 'MONTH' ,
360360 } ,
361- } , ResourcePart . Properties ) ;
361+ } ) ;
362362 // 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' , {
364364 KeyId : {
365365 Ref : 'testapikey998028B6' ,
366366 } ,
367367 KeyType : 'API_KEY' ,
368368 UsagePlanId : {
369369 Ref : 'testapikeyUsagePlanResource66DB63D6' ,
370370 } ,
371- } , ResourcePart . Properties ) ;
371+ } ) ;
372372 } ) ;
373373 } ) ;
374374} ) ;
0 commit comments