Skip to content

Commit

Permalink
fix: vpc endpoints -> endpoint configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaeldeem-acorns committed Aug 24, 2022
1 parent c843043 commit 61d4528
Showing 1 changed file with 37 additions and 24 deletions.
61 changes: 37 additions & 24 deletions lib/deploy/events/apiGateway/restApi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,31 @@ describe('#compileRestApi()', () => {
let serverless;
let serverlessStepFunctions;

const serviceresourcesawsresourcesprivateobjectmock = {
resources: {
apigatewayrestapi: {
type: 'aws::apigateway::restapi',
properties: {
name: 'dev-new-service',
endpointconfiguration: {
vpcEndpointIds: ["vpc-0a60eb65b4foo", "vpc-0a60eb65b4bar"],
types: ['private'],
const serviceResourcesAwsResourcesPrivateObjectMock = {
Resources: {
ApiGatewayRestApi: {
Type: 'AWS::ApiGateway::RestApi',
Properties: {
Name: 'dev-new-service',
EndpointConfiguration: {
Types: ['PRIVATE'],
VpcEndpointIds: [
'vpc-11abcdefgh',
],
},
},
},
},
};

const serviceresourcesawsresourcesobjectmock = {
resources: {
apigatewayrestapi: {
type: 'aws::apigateway::restapi',
properties: {
name: 'dev-new-service',
endpointconfiguration: {
types: ['edge'],
const serviceResourcesAwsResourcesObjectMock = {
Resources: {
ApiGatewayRestApi: {
Type: 'AWS::ApiGateway::RestApi',
Properties: {
Name: 'dev-new-service',
EndpointConfiguration: {
Types: ['EDGE'],
},
},
},
Expand Down Expand Up @@ -140,6 +142,23 @@ describe('#compileRestApi()', () => {
});
});

it('throw error if vpcEndpointIds and endpointType is not PRIVATE', () => {
serverlessStepFunctions.serverless.service.provider.vpcEndpointIds = ['vpc-11abcdefgh'];
serverlessStepFunctions.serverless.service.provider.endpointType = 'EDGE';
expect(() => serverlessStepFunctions.compileRestApi()).to.throw(Error);
});

it('should create a Private REST API Resource with VPC Endpoints', () => {
serverlessStepFunctions.serverless.service.provider.vpcEndpointIds = ['vpc-11abcdefgh'];
serverlessStepFunctions.serverless.service.provider.endpointType = 'PRIVATE';
return serverlessStepFunctions.compileRestApi().then(() => {
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources).to.deep.equal(
serviceResourcesAwsResourcesPrivateObjectMock.Resources,
);
});
});

it('throw error if endpointType property is not a string', () => {
serverlessStepFunctions.serverless.service.provider.endpointType = ['EDGE'];
expect(() => serverlessStepFunctions.compileRestApi()).to.throw(Error);
Expand All @@ -150,14 +169,8 @@ describe('#compileRestApi()', () => {
expect(() => serverlessStepFunctions.compileRestApi()).to.not.throw(Error);
});

it('should not compile if endpointType property is PRIVATE and no vpcEndpointIds', () => {
serverlessStepFunctions.serverless.service.provider.endpointType = 'PRIVATE';
expect(() => serverlessStepFunctions.compileRestApi()).to.throw(Error);
});

it('should compile if endpointType property is PRIVATE and vpcEndpointIds', () => {
it('should compile if endpointType property is PRIVATE', () => {
serverlessStepFunctions.serverless.service.provider.endpointType = 'PRIVATE';
serverlessStepFunctions.serverless.service.provider.vpcEndpointIds = ["vpc-0a60eb65b4foo", "vpc-0a60eb65b4bar"];
expect(() => serverlessStepFunctions.compileRestApi()).to.not.throw(Error);
});

Expand Down

0 comments on commit 61d4528

Please sign in to comment.