Skip to content

Commit 61d4528

Browse files
fix: vpc endpoints -> endpoint configuration
1 parent c843043 commit 61d4528

File tree

1 file changed

+37
-24
lines changed

1 file changed

+37
-24
lines changed

lib/deploy/events/apiGateway/restApi.test.js

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,31 @@ describe('#compileRestApi()', () => {
99
let serverless;
1010
let serverlessStepFunctions;
1111

12-
const serviceresourcesawsresourcesprivateobjectmock = {
13-
resources: {
14-
apigatewayrestapi: {
15-
type: 'aws::apigateway::restapi',
16-
properties: {
17-
name: 'dev-new-service',
18-
endpointconfiguration: {
19-
vpcEndpointIds: ["vpc-0a60eb65b4foo", "vpc-0a60eb65b4bar"],
20-
types: ['private'],
12+
const serviceResourcesAwsResourcesPrivateObjectMock = {
13+
Resources: {
14+
ApiGatewayRestApi: {
15+
Type: 'AWS::ApiGateway::RestApi',
16+
Properties: {
17+
Name: 'dev-new-service',
18+
EndpointConfiguration: {
19+
Types: ['PRIVATE'],
20+
VpcEndpointIds: [
21+
'vpc-11abcdefgh',
22+
],
2123
},
2224
},
2325
},
2426
},
2527
};
2628

27-
const serviceresourcesawsresourcesobjectmock = {
28-
resources: {
29-
apigatewayrestapi: {
30-
type: 'aws::apigateway::restapi',
31-
properties: {
32-
name: 'dev-new-service',
33-
endpointconfiguration: {
34-
types: ['edge'],
29+
const serviceResourcesAwsResourcesObjectMock = {
30+
Resources: {
31+
ApiGatewayRestApi: {
32+
Type: 'AWS::ApiGateway::RestApi',
33+
Properties: {
34+
Name: 'dev-new-service',
35+
EndpointConfiguration: {
36+
Types: ['EDGE'],
3537
},
3638
},
3739
},
@@ -140,6 +142,23 @@ describe('#compileRestApi()', () => {
140142
});
141143
});
142144

145+
it('throw error if vpcEndpointIds and endpointType is not PRIVATE', () => {
146+
serverlessStepFunctions.serverless.service.provider.vpcEndpointIds = ['vpc-11abcdefgh'];
147+
serverlessStepFunctions.serverless.service.provider.endpointType = 'EDGE';
148+
expect(() => serverlessStepFunctions.compileRestApi()).to.throw(Error);
149+
});
150+
151+
it('should create a Private REST API Resource with VPC Endpoints', () => {
152+
serverlessStepFunctions.serverless.service.provider.vpcEndpointIds = ['vpc-11abcdefgh'];
153+
serverlessStepFunctions.serverless.service.provider.endpointType = 'PRIVATE';
154+
return serverlessStepFunctions.compileRestApi().then(() => {
155+
expect(serverlessStepFunctions.serverless.service
156+
.provider.compiledCloudFormationTemplate.Resources).to.deep.equal(
157+
serviceResourcesAwsResourcesPrivateObjectMock.Resources,
158+
);
159+
});
160+
});
161+
143162
it('throw error if endpointType property is not a string', () => {
144163
serverlessStepFunctions.serverless.service.provider.endpointType = ['EDGE'];
145164
expect(() => serverlessStepFunctions.compileRestApi()).to.throw(Error);
@@ -150,14 +169,8 @@ describe('#compileRestApi()', () => {
150169
expect(() => serverlessStepFunctions.compileRestApi()).to.not.throw(Error);
151170
});
152171

153-
it('should not compile if endpointType property is PRIVATE and no vpcEndpointIds', () => {
154-
serverlessStepFunctions.serverless.service.provider.endpointType = 'PRIVATE';
155-
expect(() => serverlessStepFunctions.compileRestApi()).to.throw(Error);
156-
});
157-
158-
it('should compile if endpointType property is PRIVATE and vpcEndpointIds', () => {
172+
it('should compile if endpointType property is PRIVATE', () => {
159173
serverlessStepFunctions.serverless.service.provider.endpointType = 'PRIVATE';
160-
serverlessStepFunctions.serverless.service.provider.vpcEndpointIds = ["vpc-0a60eb65b4foo", "vpc-0a60eb65b4bar"];
161174
expect(() => serverlessStepFunctions.compileRestApi()).to.not.throw(Error);
162175
});
163176

0 commit comments

Comments
 (0)