From ad86acd056af791a2b62d2a4d77722aa3513ff2c Mon Sep 17 00:00:00 2001 From: Otavio Macedo Date: Mon, 24 Jan 2022 11:45:49 +0000 Subject: [PATCH] chore(apigateway): migrated tests to `assertions` (#18562) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-apigateway/package.json | 2 +- .../aws-apigateway/test/access-log.test.ts | 1 - .../test/api-definition.test.ts | 7 +- .../aws-apigateway/test/api-key.test.ts | 44 +++++----- .../test/authorizers/cognito.test.ts | 6 +- .../test/authorizers/lambda.test.ts | 35 ++++---- .../test/base-path-mapping.test.ts | 8 +- .../@aws-cdk/aws-apigateway/test/cors.test.ts | 44 +++++----- .../aws-apigateway/test/deployment.test.ts | 80 +++++++++++-------- .../aws-apigateway/test/domains.test.ts | 57 +++++++------ .../test/gateway-response.test.ts | 19 +++-- .../@aws-cdk/aws-apigateway/test/http.test.ts | 6 +- .../aws-apigateway/test/integration.test.ts | 15 ++-- .../test/integrations/lambda.test.ts | 20 ++--- .../test/integrations/stepfunctions.test.ts | 55 +++++++------ .../aws-apigateway/test/lambda-api.test.ts | 22 ++--- .../aws-apigateway/test/method.test.ts | 59 +++++++------- .../aws-apigateway/test/model.test.ts | 6 +- .../test/requestvalidator.test.ts | 6 +- .../aws-apigateway/test/resource.test.ts | 20 ++--- .../aws-apigateway/test/restapi.test.ts | 69 ++++++++-------- .../aws-apigateway/test/stage.test.ts | 23 +++--- .../test/stepfunctions-api.test.ts | 4 +- .../aws-apigateway/test/usage-plan.test.ts | 43 +++++----- .../@aws-cdk/aws-apigateway/test/util.test.ts | 1 - .../aws-apigateway/test/vpc-link.test.ts | 8 +- 26 files changed, 332 insertions(+), 328 deletions(-) diff --git a/packages/@aws-cdk/aws-apigateway/package.json b/packages/@aws-cdk/aws-apigateway/package.json index dcab23ccc050e..cff64a652688b 100644 --- a/packages/@aws-cdk/aws-apigateway/package.json +++ b/packages/@aws-cdk/aws-apigateway/package.json @@ -79,7 +79,7 @@ }, "license": "Apache-2.0", "devDependencies": { - "@aws-cdk/assert-internal": "0.0.0", + "@aws-cdk/assertions": "0.0.0", "@aws-cdk/cdk-build-tools": "0.0.0", "@aws-cdk/cdk-integ-tools": "0.0.0", "@aws-cdk/cfn2ts": "0.0.0", diff --git a/packages/@aws-cdk/aws-apigateway/test/access-log.test.ts b/packages/@aws-cdk/aws-apigateway/test/access-log.test.ts index 6509cc24b614b..3262207317c38 100644 --- a/packages/@aws-cdk/aws-apigateway/test/access-log.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/access-log.test.ts @@ -1,4 +1,3 @@ -import '@aws-cdk/assert-internal/jest'; import * as apigateway from '../lib'; describe('access log', () => { diff --git a/packages/@aws-cdk/aws-apigateway/test/api-definition.test.ts b/packages/@aws-cdk/aws-apigateway/test/api-definition.test.ts index c4af056038451..a74b3664dae26 100644 --- a/packages/@aws-cdk/aws-apigateway/test/api-definition.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/api-definition.test.ts @@ -1,6 +1,5 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as path from 'path'; -import { ResourcePart } from '@aws-cdk/assert-internal'; import * as s3 from '@aws-cdk/aws-s3'; import * as cdk from '@aws-cdk/core'; import * as cxapi from '@aws-cdk/cx-api'; @@ -84,12 +83,12 @@ describe('api definition', () => { apiDefinition: assetApiDefinition, }); - expect(stack).toHaveResource('AWS::ApiGateway::RestApi', { + Template.fromStack(stack).hasResource('AWS::ApiGateway::RestApi', { Metadata: { 'aws:asset:path': 'asset.68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fb.yaml', 'aws:asset:property': 'BodyS3Location', }, - }, ResourcePart.CompleteDefinition); + }); }); }); diff --git a/packages/@aws-cdk/aws-apigateway/test/api-key.test.ts b/packages/@aws-cdk/aws-apigateway/test/api-key.test.ts index 3008568ce2de4..46620128f7977 100644 --- a/packages/@aws-cdk/aws-apigateway/test/api-key.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/api-key.test.ts @@ -1,5 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; -import { ResourcePart } from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import * as iam from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; import * as apigateway from '../lib'; @@ -13,8 +12,9 @@ describe('api key', () => { new apigateway.ApiKey(stack, 'my-api-key'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::ApiKey', undefined, ResourcePart.CompleteDefinition); - // should have an api key with no props defined. + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::ApiKey', { + Enabled: true, + }); }); @@ -29,7 +29,7 @@ describe('api key', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::ApiKey', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::ApiKey', { Enabled: false, Value: 'arandomstringwithmorethantwentycharacters', }); @@ -53,7 +53,7 @@ describe('api key', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::ApiKey', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::ApiKey', { CustomerId: 'test-customer', StageKeys: [ { @@ -76,7 +76,7 @@ describe('api key', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::ApiKey', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::ApiKey', { Description: 'The most secret api key', }); }); @@ -97,7 +97,7 @@ describe('api key', () => { usagePlan.addApiKey(importedKey); // THEN - expect(stack).toHaveResourceLike('AWS::ApiGateway::UsagePlanKey', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::UsagePlanKey', { KeyId: 'KeyIdabc', KeyType: 'API_KEY', UsagePlanId: { @@ -125,7 +125,7 @@ describe('api key', () => { apiKey.grantRead(user); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -176,7 +176,7 @@ describe('api key', () => { apiKey.grantWrite(user); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -232,7 +232,7 @@ describe('api key', () => { apiKey.grantReadWrite(user); // THEN - expect(stack).toHaveResource('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -282,11 +282,11 @@ describe('api key', () => { // THEN // should have an api key with no props defined. - expect(stack).toHaveResource('AWS::ApiGateway::ApiKey', undefined, ResourcePart.CompleteDefinition); + Template.fromStack(stack).hasResource('AWS::ApiGateway::ApiKey', Match.anyValue()); // should not have a usage plan. - expect(stack).not.toHaveResource('AWS::ApiGateway::UsagePlan'); + Template.fromStack(stack).resourceCountIs('AWS::ApiGateway::UsagePlan', 0); // should not have a usage plan key. - expect(stack).not.toHaveResource('AWS::ApiGateway::UsagePlanKey'); + Template.fromStack(stack).resourceCountIs('AWS::ApiGateway::UsagePlanKey', 0); }); test('only api key is created when rate limiting properties are not provided', () => { @@ -306,7 +306,7 @@ describe('api key', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::ApiKey', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::ApiKey', { CustomerId: 'test-customer', StageKeys: [ { @@ -316,9 +316,9 @@ describe('api key', () => { ], }); // should not have a usage plan. - expect(stack).not.toHaveResource('AWS::ApiGateway::UsagePlan'); + Template.fromStack(stack).resourceCountIs('AWS::ApiGateway::UsagePlan', 0); // should not have a usage plan key. - expect(stack).not.toHaveResource('AWS::ApiGateway::UsagePlanKey'); + Template.fromStack(stack).resourceCountIs('AWS::ApiGateway::UsagePlanKey', 0); }); test('api key and usage plan are created and linked when rate limiting properties are provided', () => { @@ -343,7 +343,7 @@ describe('api key', () => { // THEN // should have an api key - expect(stack).toHaveResource('AWS::ApiGateway::ApiKey', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::ApiKey', { CustomerId: 'test-customer', StageKeys: [ { @@ -353,14 +353,14 @@ describe('api key', () => { ], }); // should have a usage plan with specified quota. - expect(stack).toHaveResource('AWS::ApiGateway::UsagePlan', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::UsagePlan', { Quota: { Limit: 10000, Period: 'MONTH', }, - }, ResourcePart.Properties); + }); // should have a usage plan key linking the api key and usage plan - expect(stack).toHaveResource('AWS::ApiGateway::UsagePlanKey', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::UsagePlanKey', { KeyId: { Ref: 'testapikey998028B6', }, @@ -368,7 +368,7 @@ describe('api key', () => { UsagePlanId: { Ref: 'testapikeyUsagePlanResource66DB63D6', }, - }, ResourcePart.Properties); + }); }); }); }); diff --git a/packages/@aws-cdk/aws-apigateway/test/authorizers/cognito.test.ts b/packages/@aws-cdk/aws-apigateway/test/authorizers/cognito.test.ts index 1956c69dbb149..906f772a8505b 100644 --- a/packages/@aws-cdk/aws-apigateway/test/authorizers/cognito.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/authorizers/cognito.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as cognito from '@aws-cdk/aws-cognito'; import { Duration, Stack } from '@aws-cdk/core'; import { AuthorizationType, CognitoUserPoolsAuthorizer, RestApi } from '../../lib'; @@ -21,7 +21,7 @@ describe('Cognito Authorizer', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Authorizer', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Authorizer', { Type: 'COGNITO_USER_POOLS', RestApiId: stack.resolve(restApi.restApiId), IdentitySource: 'method.request.header.Authorization', @@ -52,7 +52,7 @@ describe('Cognito Authorizer', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Authorizer', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Authorizer', { Type: 'COGNITO_USER_POOLS', Name: 'myauthorizer', RestApiId: stack.resolve(restApi.restApiId), diff --git a/packages/@aws-cdk/aws-apigateway/test/authorizers/lambda.test.ts b/packages/@aws-cdk/aws-apigateway/test/authorizers/lambda.test.ts index 6728e0204ed37..a4eea0f56892d 100644 --- a/packages/@aws-cdk/aws-apigateway/test/authorizers/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/authorizers/lambda.test.ts @@ -1,5 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; -import { ResourcePart } from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import * as iam from '@aws-cdk/aws-iam'; import * as lambda from '@aws-cdk/aws-lambda'; import { Duration, Stack } from '@aws-cdk/core'; @@ -25,7 +24,7 @@ describe('lambda authorizer', () => { authorizationType: AuthorizationType.CUSTOM, }); - expect(stack).toHaveResource('AWS::ApiGateway::Authorizer', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Authorizer', { Type: 'TOKEN', RestApiId: stack.resolve(restApi.restApiId), IdentitySource: 'method.request.header.Authorization', @@ -71,7 +70,7 @@ describe('lambda authorizer', () => { }, }); - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { Action: 'lambda:InvokeFunction', Principal: 'apigateway.amazonaws.com', }); @@ -100,7 +99,7 @@ describe('lambda authorizer', () => { authorizationType: AuthorizationType.CUSTOM, }); - expect(stack).toHaveResource('AWS::ApiGateway::Authorizer', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Authorizer', { Type: 'REQUEST', RestApiId: stack.resolve(restApi.restApiId), AuthorizerUri: { @@ -145,7 +144,7 @@ describe('lambda authorizer', () => { }, }); - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { Action: 'lambda:InvokeFunction', Principal: 'apigateway.amazonaws.com', }); @@ -194,7 +193,7 @@ describe('lambda authorizer', () => { authorizationType: AuthorizationType.CUSTOM, }); - expect(stack).toHaveResource('AWS::ApiGateway::Authorizer', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Authorizer', { Type: 'TOKEN', RestApiId: stack.resolve(restApi.restApiId), IdentitySource: 'method.request.header.whoami', @@ -266,7 +265,7 @@ describe('lambda authorizer', () => { authorizationType: AuthorizationType.CUSTOM, }); - expect(stack).toHaveResource('AWS::ApiGateway::Authorizer', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Authorizer', { Type: 'REQUEST', RestApiId: stack.resolve(restApi.restApiId), IdentitySource: 'method.request.header.whoami', @@ -340,7 +339,7 @@ describe('lambda authorizer', () => { authorizationType: AuthorizationType.CUSTOM, }); - expect(stack).toHaveResource('AWS::ApiGateway::Authorizer', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Authorizer', { Type: 'TOKEN', RestApiId: stack.resolve(restApi.restApiId), AuthorizerUri: { @@ -385,9 +384,9 @@ describe('lambda authorizer', () => { }, }); - expect(stack).toHaveResource('AWS::IAM::Role'); + Template.fromStack(stack).hasResource('AWS::IAM::Role', Match.anyValue()); - expect(stack).toHaveResourceLike('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { Roles: [ stack.resolve(role.roleName), ], @@ -400,9 +399,9 @@ describe('lambda authorizer', () => { }, ], }, - }, ResourcePart.Properties); + }); - expect(stack).not.toHaveResource('AWS::Lambda::Permission'); + Template.fromStack(stack).resourceCountIs('AWS::Lambda::Permission', 0); }); test('request authorizer with assume role', () => { @@ -432,7 +431,7 @@ describe('lambda authorizer', () => { authorizationType: AuthorizationType.CUSTOM, }); - expect(stack).toHaveResource('AWS::ApiGateway::Authorizer', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Authorizer', { Type: 'REQUEST', RestApiId: stack.resolve(restApi.restApiId), AuthorizerUri: { @@ -477,9 +476,9 @@ describe('lambda authorizer', () => { }, }); - expect(stack).toHaveResource('AWS::IAM::Role'); + Template.fromStack(stack).hasResource('AWS::IAM::Role', Match.anyValue()); - expect(stack).toHaveResourceLike('AWS::IAM::Policy', { + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { Roles: [ stack.resolve(role.roleName), ], @@ -492,9 +491,9 @@ describe('lambda authorizer', () => { }, ], }, - }, ResourcePart.Properties); + }); - expect(stack).not.toHaveResource('AWS::Lambda::Permission'); + Template.fromStack(stack).resourceCountIs('AWS::Lambda::Permission', 0); }); test('token authorizer throws when not attached to a rest api', () => { diff --git a/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts b/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts index 6e57ce68d1394..a886b3c957dad 100644 --- a/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/base-path-mapping.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as acm from '@aws-cdk/aws-certificatemanager'; import * as cdk from '@aws-cdk/core'; import * as apigw from '../lib'; @@ -22,7 +22,7 @@ describe('BasePathMapping', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { DomainName: { Ref: 'MyDomainE4943FBC' }, RestApiId: { Ref: 'MyApi49610EDF' }, }); @@ -47,7 +47,7 @@ describe('BasePathMapping', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { BasePath: 'My_B45E-P4th', }); }); @@ -100,7 +100,7 @@ describe('BasePathMapping', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { Stage: { Ref: 'MyStage572B0482' }, }); }); diff --git a/packages/@aws-cdk/aws-apigateway/test/cors.test.ts b/packages/@aws-cdk/aws-apigateway/test/cors.test.ts index 42879b562df18..581b8af3e6c53 100644 --- a/packages/@aws-cdk/aws-apigateway/test/cors.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/cors.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as lambda from '@aws-cdk/aws-lambda'; import { Duration, Stack } from '@aws-cdk/core'; import * as apigw from '../lib'; @@ -16,7 +16,7 @@ describe('cors', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { Ref: 'apiMyResourceD5CDB490' }, Integration: { @@ -63,7 +63,7 @@ describe('cors', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { Ref: 'apiMyResourceD5CDB490' }, Integration: { @@ -112,7 +112,7 @@ describe('cors', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { Ref: 'apiMyResourceD5CDB490' }, Integration: { @@ -159,7 +159,7 @@ describe('cors', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { Ref: 'apiMyResourceD5CDB490' }, Integration: { @@ -219,7 +219,7 @@ describe('cors', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { Ref: 'apiMyResourceD5CDB490' }, Integration: { @@ -277,7 +277,7 @@ describe('cors', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { Ref: 'apiMyResourceD5CDB490' }, Integration: { @@ -327,7 +327,7 @@ describe('cors', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { Ref: 'apiMyResourceD5CDB490' }, Integration: { @@ -376,7 +376,7 @@ describe('cors', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { Ref: 'apiMyResourceD5CDB490' }, Integration: { @@ -439,7 +439,7 @@ describe('cors', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { Ref: 'apiMyResourceD5CDB490' }, Integration: { @@ -489,12 +489,12 @@ describe('cors', () => { resource.addResource('MyChildResource'); // THEN - expect(stack).toCountResources('AWS::ApiGateway::Method', 2); // on both resources - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).resourceCountIs('AWS::ApiGateway::Method', 2); // on both resources + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { Ref: 'apiMyResourceD5CDB490' }, }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { Ref: 'apiMyResourceMyChildResource2DC010C5' }, }); @@ -515,15 +515,15 @@ describe('cors', () => { child1.addResource('child2'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { 'Fn::GetAtt': ['apiC8550315', 'RootResourceId'] }, }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { Ref: 'apichild1841A5840' }, }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { Ref: 'apichild1child26A9A7C47' }, }); @@ -548,7 +548,7 @@ describe('cors', () => { }); // THENB - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { ResourceId: { Ref: 'apiAllowAll2F5BC564', }, @@ -579,7 +579,7 @@ describe('cors', () => { }, ], }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { ResourceId: { Ref: 'apiAllowSpecific77DD8AF1', }, @@ -646,8 +646,8 @@ describe('cors', () => { }); // THEN - expect(stack).toCountResources('AWS::ApiGateway::Method', 4); // two ANY and two OPTIONS resources - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).resourceCountIs('AWS::ApiGateway::Method', 4); // two ANY and two OPTIONS resources + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { 'Fn::GetAtt': [ @@ -656,7 +656,7 @@ describe('cors', () => { ], }, }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { Ref: 'lambdarestapiproxyE3AE07E3', @@ -676,7 +676,7 @@ describe('cors', () => { api.root.addProxy(); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', }); }); diff --git a/packages/@aws-cdk/aws-apigateway/test/deployment.test.ts b/packages/@aws-cdk/aws-apigateway/test/deployment.test.ts index 3f431bfb29f2a..ef537a848c070 100644 --- a/packages/@aws-cdk/aws-apigateway/test/deployment.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/deployment.test.ts @@ -1,6 +1,5 @@ import * as path from 'path'; -import '@aws-cdk/assert-internal/jest'; -import { ResourcePart, SynthUtils } from '@aws-cdk/assert-internal'; +import { Template } from '@aws-cdk/assertions'; import * as lambda from '@aws-cdk/aws-lambda'; import { CfnResource, Lazy, Stack } from '@aws-cdk/core'; import * as apigateway from '../lib'; @@ -16,7 +15,7 @@ describe('deployment', () => { new apigateway.Deployment(stack, 'deployment', { api }); // THEN - expect(stack).toMatchTemplate({ + Template.fromStack(stack).templateMatches({ Resources: { apiGETECF0BD67: { Type: 'AWS::ApiGateway::Method', @@ -68,7 +67,7 @@ describe('deployment', () => { new apigateway.Deployment(stack, 'deployment', { api, retainDeployments: true }); // THEN - expect(stack).toMatchTemplate({ + Template.fromStack(stack).templateMatches({ Resources: { apiGETECF0BD67: { Type: 'AWS::ApiGateway::Method', @@ -122,39 +121,54 @@ describe('deployment', () => { new apigateway.Deployment(stack, 'deployment', { api, description: 'this is my deployment' }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Deployment', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Deployment', { Description: 'this is my deployment', }); }); - test('logical ID of the deployment resource is salted', () => { - // GIVEN - const stack = new Stack(); - const api = new apigateway.RestApi(stack, 'api', { deploy: false, cloudWatchRole: false }); - const deployment = new apigateway.Deployment(stack, 'deployment', { api }); - api.root.addMethod('GET'); + describe('logical ID of the deployment resource is salted', () => { + test('before salting', () => { + // GIVEN + const stack = new Stack(); + const api = new apigateway.RestApi(stack, 'api', { deploy: false, cloudWatchRole: false }); + new apigateway.Deployment(stack, 'deployment', { api }); + api.root.addMethod('GET'); + + const resources = Template.fromStack(stack).findResources('AWS::ApiGateway::Deployment'); + expect(resources.deployment33381975bba46c5132329b81e7befcbbba5a0e75).toBeDefined(); + }); + + test('after salting with a resolved value', () => { + const stack = new Stack(); + const api = new apigateway.RestApi(stack, 'api', { deploy: false, cloudWatchRole: false }); + const deployment = new apigateway.Deployment(stack, 'deployment', { api }); + api.root.addMethod('GET'); - const resources = synthesize().Resources; - expect(resources.deployment33381975bba46c5132329b81e7befcbbba5a0e75).toBeDefined(); + // adding some salt + deployment.addToLogicalId({ foo: 123 }); // add some data to the logical ID - // adding some salt - deployment.addToLogicalId({ foo: 123 }); // add some data to the logical ID + // the logical ID changed + const template = Template.fromStack(stack).findResources('AWS::ApiGateway::Deployment'); + expect(template.deployment33381975bba46c5132329b81e7befcbbba5a0e75).toBeUndefined(); + expect(template.deployment333819758aa4cdb9d204502b959c4903f4d5d29f).toBeDefined(); + }); - // the logical ID changed - const template = synthesize(); - expect(template.Resources.deployment33381975bba46c5132329b81e7befcbbba5a0e75).toBeUndefined(); - expect(template.Resources.deployment333819758aa4cdb9d204502b959c4903f4d5d29f).toBeDefined(); + test('after salting with a resolved value and a token', () => { + const stack = new Stack(); + const api = new apigateway.RestApi(stack, 'api', { deploy: false, cloudWatchRole: false }); + const deployment = new apigateway.Deployment(stack, 'deployment', { api }); + api.root.addMethod('GET'); - // tokens supported, and are resolved upon synthesis - const value = 'hello hello'; - deployment.addToLogicalId({ foo: Lazy.string({ produce: () => value }) }); + // adding some salt + deployment.addToLogicalId({ foo: 123 }); // add some data to the logical ID - const template2 = synthesize(); - expect(template2.Resources.deployment333819758d91bed959c6bd6268ba84f6d33e888e).toBeDefined(); + // tokens supported, and are resolved upon synthesis + const value = 'hello hello'; + deployment.addToLogicalId({ foo: Lazy.string({ produce: () => value }) }); - function synthesize() { - return SynthUtils.synthesize(stack).template; - } + const template = Template.fromStack(stack).findResources('AWS::ApiGateway::Deployment'); + expect(template.deployment333819758d91bed959c6bd6268ba84f6d33e888e).toBeDefined(); + }); }); test('"addDependency" can be used to add a resource as a dependency', () => { @@ -169,12 +183,12 @@ describe('deployment', () => { // WHEN deployment.node.addDependency(dep); - expect(stack).toHaveResource('AWS::ApiGateway::Deployment', { + Template.fromStack(stack).hasResource('AWS::ApiGateway::Deployment', { DependsOn: [ 'apiGETECF0BD67', 'MyResource', ], - }, ResourcePart.CompleteDefinition); + }); }); @@ -205,10 +219,10 @@ describe('deployment', () => { api2.root.addMethod('GET'); // THEN - expect(stack1).toHaveResource('AWS::ApiGateway::Stage', { + Template.fromStack(stack1).hasResourceProperties('AWS::ApiGateway::Stage', { DeploymentId: { Ref: 'myapiDeploymentB7EF8EB74c5295c27fa87ff13f4d04e13f67662d' }, }); - expect(stack2).toHaveResource('AWS::ApiGateway::Stage', { + Template.fromStack(stack2).hasResourceProperties('AWS::ApiGateway::Stage', { DeploymentId: { Ref: 'myapiDeploymentB7EF8EB7b50d305057ba109c118e4aafd4509355' }, }); @@ -233,12 +247,12 @@ describe('deployment', () => { const resource = restapi.root.addResource('myresource'); resource.addMethod('GET'); - expect(stack).toHaveResource('AWS::ApiGateway::Deployment', { + Template.fromStack(stack).hasResource('AWS::ApiGateway::Deployment', { DependsOn: [ 'myapiGET9B7CD29E', 'myapimyresourceGET732851A5', 'myapiPOST23417BD2', ], - }, ResourcePart.CompleteDefinition); + }); }); }); diff --git a/packages/@aws-cdk/aws-apigateway/test/domains.test.ts b/packages/@aws-cdk/aws-apigateway/test/domains.test.ts index 31c553ad9c973..7e054c83d7102 100644 --- a/packages/@aws-cdk/aws-apigateway/test/domains.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/domains.test.ts @@ -1,5 +1,4 @@ -import { ABSENT } from '@aws-cdk/assert-internal'; -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as acm from '@aws-cdk/aws-certificatemanager'; import { Bucket } from '@aws-cdk/aws-s3'; import { Stack } from '@aws-cdk/core'; @@ -27,13 +26,13 @@ describe('domains', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::DomainName', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::DomainName', { 'DomainName': 'example.com', 'EndpointConfiguration': { 'Types': ['REGIONAL'] }, 'RegionalCertificateArn': { 'Ref': 'Cert5C9FAEC1' }, }); - expect(stack).toHaveResource('AWS::ApiGateway::DomainName', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::DomainName', { 'DomainName': 'example.com', 'EndpointConfiguration': { 'Types': ['EDGE'] }, 'CertificateArn': { 'Ref': 'Cert5C9FAEC1' }, @@ -57,7 +56,7 @@ describe('domains', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::DomainName', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::DomainName', { 'DomainName': 'example.com', 'EndpointConfiguration': { 'Types': ['REGIONAL'] }, 'RegionalCertificateArn': { 'Ref': 'Cert5C9FAEC1' }, @@ -88,25 +87,25 @@ describe('domains', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::DomainName', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::DomainName', { 'DomainName': 'old.example.com', 'EndpointConfiguration': { 'Types': ['REGIONAL'] }, 'RegionalCertificateArn': { 'Ref': 'Cert5C9FAEC1' }, 'SecurityPolicy': 'TLS_1_0', }); - expect(stack).toHaveResource('AWS::ApiGateway::DomainName', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::DomainName', { 'DomainName': 'new.example.com', 'EndpointConfiguration': { 'Types': ['REGIONAL'] }, 'RegionalCertificateArn': { 'Ref': 'Cert5C9FAEC1' }, 'SecurityPolicy': 'TLS_1_2', }); - expect(stack).toHaveResource('AWS::ApiGateway::DomainName', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::DomainName', { 'DomainName': 'default.example.com', 'EndpointConfiguration': { 'Types': ['REGIONAL'] }, 'RegionalCertificateArn': { 'Ref': 'Cert5C9FAEC1' }, - 'SecurityPolicy': ABSENT, + 'SecurityPolicy': Match.absent(), }); }); @@ -125,7 +124,7 @@ describe('domains', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { 'DomainName': { 'Ref': 'Domain66AC69E0', }, @@ -156,7 +155,7 @@ describe('domains', () => { domain.addBasePathMapping(api2, { basePath: 'api2' }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { 'DomainName': { 'Ref': 'mydomain592C948B', }, @@ -169,7 +168,7 @@ describe('domains', () => { }, }); - expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { 'DomainName': { 'Ref': 'mydomain592C948B', }, @@ -197,7 +196,7 @@ describe('domains', () => { api.root.addMethod('GET'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::DomainName', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::DomainName', { 'DomainName': 'my.domain.com', 'EndpointConfiguration': { 'Types': [ @@ -208,7 +207,7 @@ describe('domains', () => { 'Ref': 'cert56CA94EB', }, }); - expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { 'DomainName': { 'Ref': 'apiCustomDomain64773C4F', }, @@ -235,7 +234,7 @@ describe('domains', () => { api.addDomainName('domainId', { domainName, certificate }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::DomainName', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::DomainName', { 'DomainName': domainName, 'EndpointConfiguration': { 'Types': [ @@ -246,7 +245,7 @@ describe('domains', () => { 'Ref': 'cert56CA94EB', }, }); - expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { 'DomainName': { 'Ref': 'apidomainId102F8DAA', }, @@ -274,7 +273,7 @@ describe('domains', () => { api.addDomainName('domainId', { domainName, certificate, basePath }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { 'BasePath': 'users', 'RestApiId': { 'Ref': 'apiC8550315', @@ -300,13 +299,13 @@ describe('domains', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { 'BasePath': 'users', 'RestApiId': { 'Ref': 'apiC8550315', }, }); - expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { 'BasePath': 'books', 'RestApiId': { 'Ref': 'apiC8550315', @@ -361,7 +360,7 @@ describe('domains', () => { expect(api.domainName).toEqual(domainName1); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::DomainName', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::DomainName', { 'DomainName': 'my.domain.com', 'EndpointConfiguration': { 'Types': [ @@ -372,7 +371,7 @@ describe('domains', () => { 'Ref': 'cert56CA94EB', }, }); - expect(stack).toHaveResource('AWS::ApiGateway::DomainName', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::DomainName', { 'DomainName': 'your.domain.com', 'EndpointConfiguration': { 'Types': [ @@ -383,7 +382,7 @@ describe('domains', () => { 'Ref': 'cert56CA94EB', }, }); - expect(stack).toHaveResource('AWS::ApiGateway::DomainName', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::DomainName', { 'DomainName': 'our.domain.com', 'EndpointConfiguration': { 'Types': [ @@ -394,7 +393,7 @@ describe('domains', () => { 'Ref': 'cert56CA94EB', }, }); - expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { 'DomainName': { 'Ref': 'apidomainId102F8DAA', }, @@ -433,7 +432,7 @@ describe('domains', () => { domain.addBasePathMapping(api2, { basePath: 'api2' }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { 'DomainName': { 'Ref': 'mydomain592C948B', }, @@ -444,7 +443,7 @@ describe('domains', () => { 'Stage': stack.resolve(testStage.stageName), }); - expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { 'DomainName': { 'Ref': 'mydomain592C948B', }, @@ -471,7 +470,7 @@ describe('domains', () => { certificate: acm.Certificate.fromCertificateArn(stack, 'cert', 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d'), }); - expect(stack).toHaveResource('AWS::ApiGateway::DomainName', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::DomainName', { 'DomainName': 'example.com', 'EndpointConfiguration': { 'Types': ['REGIONAL'] }, 'RegionalCertificateArn': 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d', @@ -492,7 +491,7 @@ describe('domains', () => { version: 'version', }, }); - expect(stack).toHaveResource('AWS::ApiGateway::DomainName', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::DomainName', { 'DomainName': 'example.com', 'EndpointConfiguration': { 'Types': ['REGIONAL'] }, 'RegionalCertificateArn': 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d', @@ -512,7 +511,7 @@ describe('domains', () => { }).root.addMethod('GET'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { 'DomainName': { 'Ref': 'restApiWithStageCustomDomainC4749625', }, @@ -543,7 +542,7 @@ describe('domains', () => { }).root.addMethod('GET'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::BasePathMapping', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::BasePathMapping', { 'DomainName': { 'Ref': 'specRestApiWithStageCustomDomain8A36A5C9', }, diff --git a/packages/@aws-cdk/aws-apigateway/test/gateway-response.test.ts b/packages/@aws-cdk/aws-apigateway/test/gateway-response.test.ts index 7a02ca17b6ca0..80093aba04de1 100644 --- a/packages/@aws-cdk/aws-apigateway/test/gateway-response.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/gateway-response.test.ts @@ -1,5 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; -import { ABSENT } from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import { Stack } from '@aws-cdk/core'; import { ResponseType, RestApi } from '../lib'; @@ -20,12 +19,12 @@ describe('gateway response', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::GatewayResponse', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::GatewayResponse', { ResponseType: 'ACCESS_DENIED', RestApiId: stack.resolve(api.restApiId), - StatusCode: ABSENT, - ResponseParameters: ABSENT, - ResponseTemplates: ABSENT, + StatusCode: Match.absent(), + ResponseParameters: Match.absent(), + ResponseTemplates: Match.absent(), }); }); @@ -50,7 +49,7 @@ describe('gateway response', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::GatewayResponse', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::GatewayResponse', { ResponseType: 'AUTHORIZER_FAILURE', RestApiId: stack.resolve(api.restApiId), StatusCode: '500', @@ -58,7 +57,7 @@ describe('gateway response', () => { 'gatewayresponse.header.Access-Control-Allow-Origin': 'test.com', 'gatewayresponse.header.test-key': 'test-value', }, - ResponseTemplates: ABSENT, + ResponseTemplates: Match.absent(), }); }); @@ -82,11 +81,11 @@ describe('gateway response', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::GatewayResponse', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::GatewayResponse', { ResponseType: 'AUTHORIZER_FAILURE', RestApiId: stack.resolve(api.restApiId), StatusCode: '500', - ResponseParameters: ABSENT, + ResponseParameters: Match.absent(), ResponseTemplates: { 'application/json': '{ "message": $context.error.messageString, "statusCode": "488" }', }, diff --git a/packages/@aws-cdk/aws-apigateway/test/http.test.ts b/packages/@aws-cdk/aws-apigateway/test/http.test.ts index 15714ca988087..4d687da1546b7 100644 --- a/packages/@aws-cdk/aws-apigateway/test/http.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/http.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as cdk from '@aws-cdk/core'; import * as apigateway from '../lib'; @@ -14,7 +14,7 @@ describe('http integration', () => { api.root.addMethod('GET', integ); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { IntegrationHttpMethod: 'GET', Type: 'HTTP_PROXY', @@ -40,7 +40,7 @@ describe('http integration', () => { api.root.addMethod('GET', integ); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { CacheNamespace: 'hey', IntegrationHttpMethod: 'POST', diff --git a/packages/@aws-cdk/aws-apigateway/test/integration.test.ts b/packages/@aws-cdk/aws-apigateway/test/integration.test.ts index f89a1fdf042ed..0ae46986bcc93 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integration.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/integration.test.ts @@ -1,5 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; -import { ABSENT } from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2'; import * as iam from '@aws-cdk/aws-iam'; @@ -52,7 +51,7 @@ describe('integration', () => { }); api.root.addMethod('GET', integration); - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { Uri: { 'Fn::Join': [ @@ -133,7 +132,7 @@ describe('integration', () => { })).toThrow(/cannot set 'vpcLink' where 'connectionType' is INTERNET/); }); - test('connectionType is ABSENT when vpcLink is not specified', () => { + test('connectionType is Match.absent() when vpcLink is not specified', () => { // GIVEN const stack = new cdk.Stack(); const api = new apigw.RestApi(stack, 'restapi'); @@ -146,10 +145,10 @@ describe('integration', () => { api.root.addMethod('ANY', integration); // THEN - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'ANY', Integration: { - ConnectionType: ABSENT, + ConnectionType: Match.absent(), }, }); }); @@ -177,7 +176,7 @@ describe('integration', () => { api.root.addMethod('ANY', integration); // THEN - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'ANY', Integration: { ConnectionType: 'VPC_LINK', @@ -221,7 +220,7 @@ describe('integration', () => { api.root.addMethod('ANY', integration); // THEN - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'ANY', Integration: { TimeoutInMillis: 1000, diff --git a/packages/@aws-cdk/aws-apigateway/test/integrations/lambda.test.ts b/packages/@aws-cdk/aws-apigateway/test/integrations/lambda.test.ts index 7c5b9e60e85d6..187e15e2b09cf 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integrations/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/integrations/lambda.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as lambda from '@aws-cdk/aws-lambda'; import * as cdk from '@aws-cdk/core'; import * as apigateway from '../../lib'; @@ -19,7 +19,7 @@ describe('lambda', () => { api.root.addMethod('GET', integ); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { IntegrationHttpMethod: 'POST', Type: 'AWS_PROXY', @@ -66,7 +66,7 @@ describe('lambda', () => { api.root.addMethod('GET', integ); // THEN - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { SourceArn: { 'Fn::Join': [ '', @@ -78,7 +78,7 @@ describe('lambda', () => { }, }); - expect(stack).not.toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', Match.not({ SourceArn: { 'Fn::Join': [ '', @@ -95,7 +95,7 @@ describe('lambda', () => { ], ], }, - }); + })); }); test('"allowTestInvoke" set to true allows calling the API from the test UI', () => { @@ -114,7 +114,7 @@ describe('lambda', () => { api.root.addMethod('GET', integ); // THEN - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { SourceArn: { 'Fn::Join': [ '', @@ -150,7 +150,7 @@ describe('lambda', () => { api.root.addMethod('GET', integ); // THEN - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { Type: 'AWS', }, @@ -171,7 +171,7 @@ describe('lambda', () => { api.root.addMethod('ANY', target); - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { SourceArn: { 'Fn::Join': [ '', @@ -190,7 +190,7 @@ describe('lambda', () => { }, }); - expect(stack).toHaveResource('AWS::Lambda::Permission', { + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { SourceArn: { 'Fn::Join': [ '', @@ -235,7 +235,7 @@ describe('lambda', () => { api.root.addMethod('ANY', new apigateway.LambdaIntegration(handler)); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { RestApiId: 'imported-rest-api-id', ResourceId: 'imported-root-resource-id', HttpMethod: 'ANY', diff --git a/packages/@aws-cdk/aws-apigateway/test/integrations/stepfunctions.test.ts b/packages/@aws-cdk/aws-apigateway/test/integrations/stepfunctions.test.ts index c803fa974f7f6..830ca2a8e2000 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integrations/stepfunctions.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/integrations/stepfunctions.test.ts @@ -1,5 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; -import { stringLike, anything } from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import * as sfn from '@aws-cdk/aws-stepfunctions'; import { StateMachine, StateMachineType } from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; @@ -16,7 +15,7 @@ describe('StepFunctionsIntegration', () => { api.root.addMethod('GET', integ); //THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { ResourceId: { 'Fn::GetAtt': [ 'myrestapiBAC2BF45', @@ -74,16 +73,16 @@ describe('StepFunctionsIntegration', () => { const integ = apigw.StepFunctionsIntegration.startExecution(stateMachine); api.root.addMethod('GET', integ); - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { RequestTemplates: { 'application/json': { 'Fn::Join': [ '', [ - stringLike('*includeHeaders = false*'), + Match.stringLikeRegexp('includeHeaders = false'), { Ref: 'StateMachine2E01A3A5' }, - anything(), + Match.anyValue(), ], ], }, @@ -102,16 +101,16 @@ describe('StepFunctionsIntegration', () => { }); api.root.addMethod('GET', integ); - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { RequestTemplates: { 'application/json': { 'Fn::Join': [ '', [ - stringLike('*#set($includeHeaders = true)*'), + Match.stringLikeRegexp('#set\\(\\$includeHeaders = true\\)'), { Ref: 'StateMachine2E01A3A5' }, - anything(), + Match.anyValue(), ], ], }, @@ -128,16 +127,16 @@ describe('StepFunctionsIntegration', () => { const integ = apigw.StepFunctionsIntegration.startExecution(stateMachine); api.root.addMethod('GET', integ); - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { RequestTemplates: { 'application/json': { 'Fn::Join': [ '', [ - stringLike('*#set($includeQueryString = true)*'), + Match.stringLikeRegexp('#set\\(\\$includeQueryString = true\\)'), { Ref: 'StateMachine2E01A3A5' }, - anything(), + Match.anyValue(), ], ], }, @@ -145,16 +144,16 @@ describe('StepFunctionsIntegration', () => { }, }); - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { RequestTemplates: { 'application/json': { 'Fn::Join': [ '', [ - stringLike('*#set($includePath = true)*'), + Match.stringLikeRegexp('#set\\(\\$includePath = true\\)'), { Ref: 'StateMachine2E01A3A5' }, - anything(), + Match.anyValue(), ], ], }, @@ -174,16 +173,16 @@ describe('StepFunctionsIntegration', () => { }); api.root.addMethod('GET', integ); - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { RequestTemplates: { 'application/json': { 'Fn::Join': [ '', [ - stringLike('*#set($includeQueryString = false)*'), + Match.stringLikeRegexp('#set\\(\\$includeQueryString = false\\)'), { Ref: 'StateMachine2E01A3A5' }, - anything(), + Match.anyValue(), ], ], }, @@ -191,16 +190,16 @@ describe('StepFunctionsIntegration', () => { }, }); - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { RequestTemplates: { 'application/json': { 'Fn::Join': [ '', [ - stringLike('*#set($includePath = false)*'), + Match.stringLikeRegexp('#set\\(\\$includePath = false\\)'), { Ref: 'StateMachine2E01A3A5' }, - anything(), + Match.anyValue(), ], ], }, @@ -217,16 +216,16 @@ describe('StepFunctionsIntegration', () => { const integ = apigw.StepFunctionsIntegration.startExecution(stateMachine, {}); api.root.addMethod('GET', integ); - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { RequestTemplates: { 'application/json': { 'Fn::Join': [ '', [ - anything(), + Match.anyValue(), { Ref: 'StateMachine2E01A3A5' }, - stringLike('*#set($requestContext = \"\")*'), + Match.stringLikeRegexp('#set\\(\\$requestContext = \"\"\\)'), ], ], }, @@ -247,16 +246,16 @@ describe('StepFunctionsIntegration', () => { }); api.root.addMethod('GET', integ); - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { RequestTemplates: { 'application/json': { 'Fn::Join': [ '', [ - anything(), + Match.anyValue(), { Ref: 'StateMachine2E01A3A5' }, - stringLike('*#set($requestContext = \"{@@accountId@@:@@$context.identity.accountId@@}\"*'), + Match.stringLikeRegexp('#set\\(\\$requestContext = \"{@@accountId@@:@@\\$context.identity.accountId@@}\"'), ], ], }, @@ -283,7 +282,7 @@ describe('StepFunctionsIntegration', () => { api.root.addMethod('ANY', apigw.StepFunctionsIntegration.startExecution(stateMachine)); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { ResourceId: 'imported-root-resource-id', RestApiId: 'imported-rest-api-id', }); diff --git a/packages/@aws-cdk/aws-apigateway/test/lambda-api.test.ts b/packages/@aws-cdk/aws-apigateway/test/lambda-api.test.ts index 7e412c549e897..314225d3afe34 100644 --- a/packages/@aws-cdk/aws-apigateway/test/lambda-api.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/lambda-api.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import * as lambda from '@aws-cdk/aws-lambda'; import * as cdk from '@aws-cdk/core'; import * as apigw from '../lib'; @@ -23,11 +23,11 @@ describe('lambda api', () => { }).toThrow(); // THEN -- template proxies everything - expect(stack).toHaveResource('AWS::ApiGateway::Resource', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { PathPart: '{proxy+}', }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'ANY', ResourceId: { Ref: 'lambdarestapiproxyE3AE07E3', @@ -91,11 +91,11 @@ describe('lambda api', () => { }).toThrow(); // THEN -- template proxies everything - expect(stack).toHaveResource('AWS::ApiGateway::Resource', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { PathPart: '{proxy+}', }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'ANY', ResourceId: { Ref: 'lambdarestapiproxyE3AE07E3', @@ -149,20 +149,20 @@ describe('lambda api', () => { tasks.addMethod('POST'); // THEN - expect(stack).not.toHaveResource('AWS::ApiGateway::Resource', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', Match.not({ PathPart: '{proxy+}', - }); + })); - expect(stack).toHaveResource('AWS::ApiGateway::Resource', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { PathPart: 'tasks', }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'GET', ResourceId: { Ref: 'lambdarestapitasks224418C8' }, }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'POST', ResourceId: { Ref: 'lambdarestapitasks224418C8' }, }); @@ -209,7 +209,7 @@ describe('lambda api', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'OPTIONS', ResourceId: { Ref: 'lambdarestapiproxyE3AE07E3' }, Integration: { diff --git a/packages/@aws-cdk/aws-apigateway/test/method.test.ts b/packages/@aws-cdk/aws-apigateway/test/method.test.ts index f1037e550e23a..de41b0dfe363f 100644 --- a/packages/@aws-cdk/aws-apigateway/test/method.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/method.test.ts @@ -1,5 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; -import { ABSENT } from '@aws-cdk/assert-internal'; +import { Match, Template } from '@aws-cdk/assertions'; import * as iam from '@aws-cdk/aws-iam'; import * as lambda from '@aws-cdk/aws-lambda'; import { testDeprecated } from '@aws-cdk/cdk-build-tools'; @@ -24,7 +23,7 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'POST', AuthorizationType: 'NONE', Integration: { @@ -51,7 +50,7 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { ApiKeyRequired: true, OperationName: 'MyOperation', }); @@ -72,7 +71,7 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { IntegrationHttpMethod: 'POST', Type: 'AWS', @@ -104,7 +103,7 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { IntegrationHttpMethod: 'POST', Type: 'AWS', @@ -133,7 +132,7 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { IntegrationHttpMethod: 'GET', }, @@ -159,7 +158,7 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { Type: 'HTTP_PROXY', Uri: 'https://amazon.com', @@ -325,7 +324,7 @@ describe('method', () => { })); // THEN - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { Credentials: { 'Fn::GetAtt': ['MyRoleF48FFE04', 'Arn'] }, }, @@ -347,7 +346,7 @@ describe('method', () => { })); // THEN - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { Credentials: { 'Fn::Join': ['', ['arn:', { Ref: 'AWS::Partition' }, ':iam::*:user/*']] }, }, @@ -386,7 +385,7 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'GET', MethodResponses: [{ StatusCode: '200', @@ -435,7 +434,7 @@ describe('method', () => { })); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { Integration: { IntegrationHttpMethod: 'POST', IntegrationResponses: [ @@ -467,9 +466,9 @@ describe('method', () => { api.root.addMethod('PUT'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { HttpMethod: 'POST' }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { HttpMethod: 'GET' }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { HttpMethod: 'PUT' }); + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'POST' }); + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'GET' }); + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'PUT' }); }); @@ -499,7 +498,7 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'GET', RequestModels: { 'application/json': { Ref: stack.getLogicalId(model.node.findChild('Resource') as cdk.CfnElement) }, @@ -549,7 +548,7 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'GET', MethodResponses: [{ StatusCode: '200', @@ -593,10 +592,10 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { RequestValidatorId: { Ref: stack.getLogicalId(validator.node.findChild('Resource') as cdk.CfnElement) }, }); - expect(stack).toHaveResource('AWS::ApiGateway::RequestValidator', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RequestValidator', { RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as cdk.CfnElement) }, ValidateRequestBody: true, ValidateRequestParameters: false, @@ -626,7 +625,7 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { OperationName: 'defaultRequestParameters', RequestParameters: { 'method.request.path.proxy': true, @@ -644,7 +643,7 @@ describe('method', () => { authorizer: DUMMY_AUTHORIZER, }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'ANY', AuthorizationType: 'CUSTOM', AuthorizerId: DUMMY_AUTHORIZER.authorizerId, @@ -674,7 +673,7 @@ describe('method', () => { }); restApi.root.addMethod('ANY'); - expect(stack).toHaveResource('AWS::ApiGateway::Authorizer', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Authorizer', { Name: 'myauthorizer1', Type: 'TOKEN', RestApiId: stack.resolve(restApi.restApiId), @@ -732,7 +731,7 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { ApiKeyRequired: true, AuthorizationScopes: ['AuthScope1', 'AuthScope2'], }); @@ -761,7 +760,7 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { OperationName: 'defaultAuthScopes', AuthorizationScopes: ['DefaultAuth'], }); @@ -791,7 +790,7 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { ApiKeyRequired: true, AuthorizationScopes: ['MethodAuthScope'], }); @@ -817,9 +816,9 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { OperationName: 'authScopesAbsent', - AuthorizationScopes: ABSENT, + AuthorizationScopes: Match.absent(), }); @@ -844,7 +843,7 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::RequestValidator', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RequestValidator', { RestApiId: stack.resolve(api.restApiId), ValidateRequestBody: true, ValidateRequestParameters: false, @@ -866,8 +865,8 @@ describe('method', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { - RequestValidatorId: ABSENT, + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { + RequestValidatorId: Match.absent(), }); diff --git a/packages/@aws-cdk/aws-apigateway/test/model.test.ts b/packages/@aws-cdk/aws-apigateway/test/model.test.ts index 62602ef353959..4318f3c5b0093 100644 --- a/packages/@aws-cdk/aws-apigateway/test/model.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/model.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as cdk from '@aws-cdk/core'; import * as apigw from '../lib'; @@ -24,7 +24,7 @@ describe('model', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Model', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Model', { RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as cdk.CfnElement) }, Schema: { $schema: 'http://json-schema.org/draft-04/schema#', @@ -57,7 +57,7 @@ describe('model', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Model', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Model', { RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as cdk.CfnElement) }, Schema: { $schema: 'http://json-schema.org/draft-04/schema#', diff --git a/packages/@aws-cdk/aws-apigateway/test/requestvalidator.test.ts b/packages/@aws-cdk/aws-apigateway/test/requestvalidator.test.ts index ec29752b47b6a..061c7853d3392 100644 --- a/packages/@aws-cdk/aws-apigateway/test/requestvalidator.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/requestvalidator.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as cdk from '@aws-cdk/core'; import * as apigateway from '../lib'; @@ -20,7 +20,7 @@ describe('request validator', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::RequestValidator', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RequestValidator', { RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as cdk.CfnElement) }, ValidateRequestBody: true, ValidateRequestParameters: false, @@ -45,7 +45,7 @@ describe('request validator', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::RequestValidator', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RequestValidator', { RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as cdk.CfnElement) }, Name: 'my-model', ValidateRequestBody: false, diff --git a/packages/@aws-cdk/aws-apigateway/test/resource.test.ts b/packages/@aws-cdk/aws-apigateway/test/resource.test.ts index b118c328073cb..3c97221b56339 100644 --- a/packages/@aws-cdk/aws-apigateway/test/resource.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/resource.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Match, Template } from '@aws-cdk/assertions'; import { Stack } from '@aws-cdk/core'; import * as apigw from '../lib'; @@ -16,7 +16,7 @@ describe('resource', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Resource', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { 'ParentId': { 'Fn::GetAtt': [ 'apiC8550315', @@ -29,7 +29,7 @@ describe('resource', () => { }, }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { 'HttpMethod': 'ANY', 'ResourceId': { 'Ref': 'proxy3A1DA9C7', @@ -60,9 +60,9 @@ describe('resource', () => { proxy.addMethod('GET'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Resource'); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { 'HttpMethod': 'GET' }); - expect(stack).not.toHaveResource('AWS::ApiGateway::Method', { 'HttpMethod': 'ANY' }); + Template.fromStack(stack).resourceCountIs('AWS::ApiGateway::Resource', 1); + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { 'HttpMethod': 'GET' }); + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', Match.not({ 'HttpMethod': 'ANY' })); }); @@ -78,7 +78,7 @@ describe('resource', () => { const v2 = api.root.addResource('v2'); v2.addProxy(); - expect(stack).toMatchTemplate({ + Template.fromStack(stack).templateMatches({ 'Resources': { 'apiC8550315': { 'Type': 'AWS::ApiGateway::RestApi', @@ -154,7 +154,7 @@ describe('resource', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'DELETE', ResourceId: { Ref: 'apiproxy4EA44110' }, Integration: { @@ -164,7 +164,7 @@ describe('resource', () => { OperationName: 'DeleteMe', }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'DELETE', ResourceId: { 'Fn::GetAtt': ['apiC8550315', 'RootResourceId'] }, Integration: { @@ -251,7 +251,7 @@ describe('resource', () => { imported.addMethod('GET'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'GET', ResourceId: resourceId, }); diff --git a/packages/@aws-cdk/aws-apigateway/test/restapi.test.ts b/packages/@aws-cdk/aws-apigateway/test/restapi.test.ts index 7a9f117afe126..f873c6c643f5d 100644 --- a/packages/@aws-cdk/aws-apigateway/test/restapi.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/restapi.test.ts @@ -1,5 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; -import { ResourcePart, SynthUtils } from '@aws-cdk/assert-internal'; +import { Template } from '@aws-cdk/assertions'; import { GatewayVpcEndpoint } from '@aws-cdk/aws-ec2'; import { testDeprecated } from '@aws-cdk/cdk-build-tools'; import { App, CfnElement, CfnResource, Stack } from '@aws-cdk/core'; @@ -15,7 +14,7 @@ describe('restapi', () => { api.root.addMethod('GET'); // must have at least one method or an API definition // THEN - expect(stack).toMatchTemplate({ + Template.fromStack(stack).templateMatches({ Resources: { myapi4C7BF186: { Type: 'AWS::ApiGateway::RestApi', @@ -132,7 +131,7 @@ describe('restapi', () => { api.root.addMethod('GET'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::RestApi', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', { Name: 'restapi', }); }); @@ -168,17 +167,17 @@ describe('restapi', () => { foo.addResource('{hello}'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Resource', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { PathPart: 'foo', ParentId: { 'Fn::GetAtt': ['restapiC5611D27', 'RootResourceId'] }, }); - expect(stack).toHaveResource('AWS::ApiGateway::Resource', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { PathPart: 'bar', ParentId: { 'Fn::GetAtt': ['restapiC5611D27', 'RootResourceId'] }, }); - expect(stack).toHaveResource('AWS::ApiGateway::Resource', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { PathPart: '{hello}', ParentId: { Ref: 'restapifooF697E056' }, }); @@ -198,7 +197,7 @@ describe('restapi', () => { proxy.addMethod('ANY'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Resource', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { PathPart: '{proxy+}', ParentId: { 'Fn::GetAtt': ['restapiC5611D27', 'RootResourceId'] }, }); @@ -216,7 +215,7 @@ describe('restapi', () => { r1.addMethod('POST'); // THEN - expect(stack).toMatchTemplate({ + Template.fromStack(stack).templateMatches({ Resources: { restapiC5611D27: { Type: 'AWS::ApiGateway::RestApi', @@ -330,8 +329,8 @@ describe('restapi', () => { api.root.addMethod('GET'); // THEN - expect(stack).toHaveResource('AWS::IAM::Role'); - expect(stack).toHaveResource('AWS::ApiGateway::Account'); + Template.fromStack(stack).resourceCountIs('AWS::IAM::Role', 1); + Template.fromStack(stack).resourceCountIs('AWS::ApiGateway::Account', 1); }); test('"url" and "urlForPath" return the URL endpoints of the deployed API', () => { @@ -462,7 +461,7 @@ describe('restapi', () => { api.root.addMethod('GET'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::RestApi', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', { EndpointConfiguration: { Types: [ 'EDGE', @@ -486,7 +485,7 @@ describe('restapi', () => { api.root.addMethod('GET'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::RestApi', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', { EndpointConfiguration: { Types: ['EDGE', 'PRIVATE'], }, @@ -511,7 +510,7 @@ describe('restapi', () => { api.root.addMethod('GET'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::RestApi', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', { EndpointConfiguration: { Types: [ 'EDGE', @@ -551,7 +550,7 @@ describe('restapi', () => { api.root.addMethod('GET'); - expect(stack).toHaveResource('AWS::ApiGateway::RestApi', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', { CloneFrom: 'foobar', Name: 'api', }); @@ -568,7 +567,7 @@ describe('restapi', () => { resource.node.addDependency(api); // THEN - expect(stack).toHaveResource('My::Resource', { + Template.fromStack(stack).hasResource('My::Resource', { DependsOn: [ 'myapiAccountC3A4750C', 'myapiCloudWatchRoleEB425128', @@ -577,7 +576,7 @@ describe('restapi', () => { 'myapiDeploymentStageprod329F21FF', 'myapi162F20B8', ], - }, ResourcePart.CompleteDefinition); + }); }); test('defaultIntegration and defaultMethodOptions can be used at any level', () => { @@ -624,7 +623,7 @@ describe('restapi', () => { // THEN // CASE #1 - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'GET', ResourceId: { 'Fn::GetAtt': ['myapi162F20B8', 'RootResourceId'] }, Integration: { Type: 'AWS' }, @@ -633,7 +632,7 @@ describe('restapi', () => { }); // CASE #2 - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'POST', ResourceId: { Ref: 'myapichildA0A65412' }, Integration: { Type: 'AWS' }, @@ -642,7 +641,7 @@ describe('restapi', () => { }); // CASE #3 - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'DELETE', Integration: { Type: 'MOCK' }, AuthorizerId: 'AUTHID2', @@ -650,7 +649,7 @@ describe('restapi', () => { }); // CASE #4 - expect(stack).toHaveResourceLike('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'PUT', Integration: { Type: 'AWS' }, AuthorizerId: 'AUTHID2', @@ -671,7 +670,7 @@ describe('restapi', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::ApiKey', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::ApiKey', { Enabled: true, Name: 'myApiKey1', StageKeys: [ @@ -701,7 +700,7 @@ describe('restapi', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Model', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Model', { RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as CfnElement) }, Schema: { $schema: 'http://json-schema.org/draft-04/schema#', @@ -731,14 +730,14 @@ describe('restapi', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::RequestValidator', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RequestValidator', { RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as CfnElement) }, Name: 'Parameters', ValidateRequestBody: false, ValidateRequestParameters: true, }); - expect(stack).toHaveResource('AWS::ApiGateway::RequestValidator', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RequestValidator', { RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as CfnElement) }, Name: 'Body', ValidateRequestBody: true, @@ -755,7 +754,8 @@ describe('restapi', () => { api.root.addMethod('GET'); // THEN - expect(SynthUtils.toCloudFormation(stack).Outputs).toEqual({ + const outputs = Template.fromStack(stack).findOutputs('myapiEndpoint8EB17201'); + expect(outputs).toEqual({ myapiEndpoint8EB17201: { Value: { 'Fn::Join': [ @@ -787,7 +787,8 @@ describe('restapi', () => { api.root.addMethod('GET'); // THEN - expect(SynthUtils.toCloudFormation(stack).Outputs).toEqual({ + const outputs = Template.fromStack(stack).findOutputs('myapiEndpoint8EB17201'); + expect(outputs).toEqual({ myapiEndpoint8EB17201: { Value: { 'Fn::Join': [ @@ -864,11 +865,11 @@ describe('restapi', () => { resource.addMethod('GET'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Resource', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { PathPart: 'pets', ParentId: stack.resolve(imported.restApiRootResourceId), }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'GET', ResourceId: stack.resolve(resource.resourceId), }); @@ -888,11 +889,11 @@ describe('restapi', () => { resource.addMethod('GET'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Resource', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { PathPart: 'pets', ParentId: stack.resolve(api.restApiRootResourceId), }); - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'GET', ResourceId: stack.resolve(resource.resourceId), }); @@ -911,7 +912,7 @@ describe('restapi', () => { api.root.addMethod('GET'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::RestApi', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', { EndpointConfiguration: { Types: [ 'EDGE', @@ -936,7 +937,7 @@ describe('restapi', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::ApiKey', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::ApiKey', { Enabled: true, Name: 'myApiKey1', StageKeys: [ @@ -1081,7 +1082,7 @@ describe('restapi', () => { api.root.addMethod('GET'); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::RestApi', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', { DisableExecuteApiEndpoint: true, }); }); diff --git a/packages/@aws-cdk/aws-apigateway/test/stage.test.ts b/packages/@aws-cdk/aws-apigateway/test/stage.test.ts index a9b030ebba07d..76d07c6e2b4b3 100644 --- a/packages/@aws-cdk/aws-apigateway/test/stage.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/stage.test.ts @@ -1,5 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; -import { ResourcePart } from '@aws-cdk/assert-internal'; +import { Template } from '@aws-cdk/assertions'; import * as logs from '@aws-cdk/aws-logs'; import * as cdk from '@aws-cdk/core'; import * as apigateway from '../lib'; @@ -16,7 +15,7 @@ describe('stage', () => { new apigateway.Stage(stack, 'my-stage', { deployment }); // THEN - expect(stack).toMatchTemplate({ + Template.fromStack(stack).templateMatches({ Resources: { testapiD6451F70: { Type: 'AWS::ApiGateway::RestApi', @@ -80,9 +79,9 @@ describe('stage', () => { // WHEN new apigateway.Stage(stack, 'my-stage', { deployment }); - expect(stack).toHaveResourceLike('AWS::ApiGateway::Stage', { + Template.fromStack(stack).hasResource('AWS::ApiGateway::Stage', { DependsOn: ['testapiAccount9B907665'], - }, ResourcePart.CompleteDefinition); + }); }); test('common method settings can be set at the stage level', () => { @@ -100,7 +99,7 @@ describe('stage', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Stage', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Stage', { MethodSettings: [ { DataTraceEnabled: false, @@ -165,7 +164,7 @@ describe('stage', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Stage', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Stage', { MethodSettings: [ { DataTraceEnabled: false, @@ -198,7 +197,7 @@ describe('stage', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Stage', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Stage', { CacheClusterEnabled: true, CacheClusterSize: '0.5', }); @@ -218,7 +217,7 @@ describe('stage', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Stage', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Stage', { CacheClusterEnabled: true, CacheClusterSize: '0.5', }); @@ -253,7 +252,7 @@ describe('stage', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Stage', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Stage', { CacheClusterEnabled: true, CacheClusterSize: '0.5', MethodSettings: [ @@ -298,7 +297,7 @@ describe('stage', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Stage', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Stage', { AccessLogSetting: { DestinationArn: { 'Fn::GetAtt': [ @@ -329,7 +328,7 @@ describe('stage', () => { }); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::Stage', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Stage', { AccessLogSetting: { DestinationArn: { 'Fn::GetAtt': [ diff --git a/packages/@aws-cdk/aws-apigateway/test/stepfunctions-api.test.ts b/packages/@aws-cdk/aws-apigateway/test/stepfunctions-api.test.ts index 30a1769b8965b..51426a4ffe6c3 100644 --- a/packages/@aws-cdk/aws-apigateway/test/stepfunctions-api.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/stepfunctions-api.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as sfn from '@aws-cdk/aws-stepfunctions'; import { StateMachine } from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; @@ -17,7 +17,7 @@ describe('Step Functions api', () => { }).toThrow(); //THEN - expect(stack).toHaveResource('AWS::ApiGateway::Method', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { HttpMethod: 'ANY', MethodResponses: getMethodResponse(), AuthorizationType: 'NONE', diff --git a/packages/@aws-cdk/aws-apigateway/test/usage-plan.test.ts b/packages/@aws-cdk/aws-apigateway/test/usage-plan.test.ts index 195e17a0b7fbf..b31e3c90b256b 100644 --- a/packages/@aws-cdk/aws-apigateway/test/usage-plan.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/usage-plan.test.ts @@ -1,5 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; -import { ResourcePart } from '@aws-cdk/assert-internal'; +import { Template } from '@aws-cdk/assertions'; import * as cdk from '@aws-cdk/core'; import * as cxapi from '@aws-cdk/cx-api'; import { testFutureBehavior } from '@aws-cdk/cdk-build-tools/lib/feature-flag'; @@ -22,10 +21,10 @@ describe('usage plan', () => { }); // THEN - expect(stack).toHaveResource(RESOURCE_TYPE, { + Template.fromStack(stack).hasResourceProperties(RESOURCE_TYPE, { UsagePlanName: usagePlanName, Description: usagePlanDescription, - }, ResourcePart.Properties); + }); }); test('usage plan with throttling limits', () => { @@ -57,7 +56,7 @@ describe('usage plan', () => { }); // THEN - expect(stack).toHaveResource(RESOURCE_TYPE, { + Template.fromStack(stack).hasResourceProperties(RESOURCE_TYPE, { UsagePlanName: usagePlanName, Description: usagePlanDescription, ApiStages: [ @@ -76,7 +75,7 @@ describe('usage plan', () => { }, }, ], - }, ResourcePart.Properties); + }); }); test('usage plan with blocked methods', () => { @@ -108,7 +107,7 @@ describe('usage plan', () => { }); // THEN - expect(stack).toHaveResource(RESOURCE_TYPE, { + Template.fromStack(stack).hasResourceProperties(RESOURCE_TYPE, { UsagePlanName: usagePlanName, Description: usagePlanDescription, ApiStages: [ @@ -127,7 +126,7 @@ describe('usage plan', () => { }, }, ], - }, ResourcePart.Properties); + }); }); test('usage plan with quota limits', () => { @@ -143,12 +142,12 @@ describe('usage plan', () => { }); // THEN - expect(stack).toHaveResource(RESOURCE_TYPE, { + Template.fromStack(stack).hasResourceProperties(RESOURCE_TYPE, { Quota: { Limit: 10000, Period: 'MONTH', }, - }, ResourcePart.Properties); + }); }); describe('UsagePlanKey', () => { @@ -165,7 +164,7 @@ describe('usage plan', () => { usagePlan.addApiKey(apiKey); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::UsagePlanKey', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::UsagePlanKey', { KeyId: { Ref: 'myapikey1B052F70', }, @@ -173,7 +172,7 @@ describe('usage plan', () => { UsagePlanId: { Ref: 'myusageplan23AA1E32', }, - }, ResourcePart.Properties); + }); }); @@ -187,13 +186,13 @@ describe('usage plan', () => { usagePlan.addApiKey(apiKey); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::UsagePlanKey', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::UsagePlanKey', { KeyId: { Ref: 'myapikey1B052F70', }, KeyType: 'API_KEY', UsagePlanId: 'imported-id', - }, ResourcePart.Properties); + }); }); test('multiple keys', () => { @@ -212,22 +211,22 @@ describe('usage plan', () => { usagePlan.addApiKey(apiKey2); // THEN - expect(stack).toHaveResource('AWS::ApiGateway::ApiKey', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::ApiKey', { Name: 'my-api-key-1', - }, ResourcePart.Properties); - expect(stack).toHaveResource('AWS::ApiGateway::ApiKey', { + }); + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::ApiKey', { Name: 'my-api-key-2', - }, ResourcePart.Properties); - expect(stack).toHaveResource('AWS::ApiGateway::UsagePlanKey', { + }); + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::UsagePlanKey', { KeyId: { Ref: 'myapikey11F723FC7', }, - }, ResourcePart.Properties); - expect(stack).toHaveResource('AWS::ApiGateway::UsagePlanKey', { + }); + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::UsagePlanKey', { KeyId: { Ref: 'myapikey2ABDEF012', }, - }, ResourcePart.Properties); + }); }); test('overrideLogicalId', () => { diff --git a/packages/@aws-cdk/aws-apigateway/test/util.test.ts b/packages/@aws-cdk/aws-apigateway/test/util.test.ts index 07c8a2cef379d..30861de05dad1 100644 --- a/packages/@aws-cdk/aws-apigateway/test/util.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/util.test.ts @@ -1,4 +1,3 @@ -import '@aws-cdk/assert-internal/jest'; import { JsonSchema, JsonSchemaType } from '../lib'; import { JsonSchemaMapper, parseAwsApiCall, parseMethodOptionsPath } from '../lib/util'; diff --git a/packages/@aws-cdk/aws-apigateway/test/vpc-link.test.ts b/packages/@aws-cdk/aws-apigateway/test/vpc-link.test.ts index ba2b82464141d..b41e1a4d19471 100644 --- a/packages/@aws-cdk/aws-apigateway/test/vpc-link.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/vpc-link.test.ts @@ -1,4 +1,4 @@ -import '@aws-cdk/assert-internal/jest'; +import { Template } from '@aws-cdk/assertions'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2'; import * as cdk from '@aws-cdk/core'; @@ -20,7 +20,7 @@ describe('vpc link', () => { }); // THEN - expect(stack).toHaveResourceLike('AWS::ApiGateway::VpcLink', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::VpcLink', { Name: 'MyLink', TargetArns: [{ Ref: 'NLB55158F82' }], }); @@ -43,7 +43,7 @@ describe('vpc link', () => { link.addTargets(nlb3); // THEN - expect(stack).toHaveResourceLike('AWS::ApiGateway::VpcLink', { + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::VpcLink', { Name: 'VpcLink', TargetArns: [ { Ref: 'NLB03D178991' }, @@ -62,7 +62,7 @@ describe('vpc link', () => { apigateway.VpcLink.fromVpcLinkId(stack, 'ImportedVpcLink', 'vpclink-id'); // THEN - expect(stack).not.toHaveResource('AWS::ApiGateway::VpcLink'); + Template.fromStack(stack).resourceCountIs('AWS::ApiGateway::VpcLink', 0); }); test('validation error if vpc link is created and no targets are added', () => {