Skip to content

Commit 786d382

Browse files
committed
add test
1 parent 97469c8 commit 786d382

File tree

4 files changed

+117
-6
lines changed

4 files changed

+117
-6
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict';
2+
3+
const expect = require('chai').expect;
4+
const Serverless = require('serverless/lib/Serverless');
5+
const AwsProvider = require('serverless/lib/plugins/aws/provider/awsProvider');
6+
const ServerlessStepFunctions = require('./../../../index');
7+
8+
describe('#compileDeployment()', () => {
9+
let serverless;
10+
let serverlessStepFunctions;
11+
12+
beforeEach(() => {
13+
serverless = new Serverless();
14+
serverless.setProvider('aws', new AwsProvider(serverless));
15+
serverless.service.provider.compiledCloudFormationTemplate = {
16+
Resources: {},
17+
Outputs: {},
18+
};
19+
const options = {
20+
stage: 'dev',
21+
region: 'us-east-1',
22+
};
23+
serverlessStepFunctions = new ServerlessStepFunctions(serverless, options);
24+
serverlessStepFunctions.apiGatewayRestApiLogicalId = 'ApiGatewayRestApi';
25+
serverlessStepFunctions.apiGatewayMethodLogicalIds
26+
= ['method-dependency1', 'method-dependency2'];
27+
});
28+
29+
it('should create a deployment resource', () => serverlessStepFunctions
30+
.compileDeployment().then(() => {
31+
const apiGatewayDeploymentLogicalId = Object
32+
.keys(serverlessStepFunctions.serverless.service.provider
33+
.compiledCloudFormationTemplate.Resources)[0];
34+
35+
expect(
36+
serverlessStepFunctions.serverless.service.provider.compiledCloudFormationTemplate
37+
.Resources[apiGatewayDeploymentLogicalId]
38+
).to.deep.equal({
39+
Type: 'AWS::ApiGateway::Deployment',
40+
DependsOn: ['method-dependency1', 'method-dependency2'],
41+
Properties: {
42+
RestApiId: { Ref: serverlessStepFunctions.apiGatewayRestApiLogicalId },
43+
StageName: 'dev',
44+
},
45+
});
46+
})
47+
);
48+
49+
it('should add service endpoint output', () =>
50+
serverlessStepFunctions.compileDeployment().then(() => {
51+
expect(
52+
serverlessStepFunctions.serverless.service.provider.compiledCloudFormationTemplate
53+
.Outputs.ServiceEndpoint
54+
).to.deep.equal({
55+
Description: 'URL of the service endpoint',
56+
Value: {
57+
'Fn::Join': [
58+
'',
59+
[
60+
'https://',
61+
{ Ref: serverlessStepFunctions.apiGatewayRestApiLogicalId },
62+
'.execute-api.us-east-1.amazonaws.com/dev',
63+
],
64+
],
65+
},
66+
});
67+
})
68+
);
69+
});

lib/deploy/events/apiGateway/methods.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ module.exports = {
2323
},
2424
};
2525

26-
if (event.http.private) {
27-
template.Properties.ApiKeyRequired = true;
28-
}
29-
3026
_.merge(template,
3127
this.getMethodIntegration(event.stateMachineName),
3228
this.getMethodResponses()
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
3+
const expect = require('chai').expect;
4+
const Serverless = require('serverless/lib/Serverless');
5+
const AwsProvider = require('serverless/lib/plugins/aws/provider/awsProvider');
6+
const ServerlessStepFunctions = require('./../../../index');
7+
8+
describe('#compileMethods()', () => {
9+
let serverless;
10+
let serverlessStepFunctions;
11+
12+
beforeEach(() => {
13+
serverless = new Serverless();
14+
serverless.setProvider('aws', new AwsProvider(serverless));
15+
serverless.service.provider.compiledCloudFormationTemplate = {
16+
Resources: {},
17+
};
18+
19+
const options = {
20+
stage: 'dev',
21+
region: 'us-east-1',
22+
};
23+
serverlessStepFunctions = new ServerlessStepFunctions(serverless, options);
24+
serverlessStepFunctions.apiGatewayResourceLogicalIds
25+
= { 'foo/bar': 'apiGatewayResourceLogicalId' };
26+
serverlessStepFunctions.apiGatewayResourceNames
27+
= { 'foo/bar': 'apiGatewayResourceNames' };
28+
serverlessStepFunctions.pluginhttpValidated = {
29+
events: [
30+
{
31+
stateMachineName: 'first',
32+
http: {
33+
path: 'foo/bar',
34+
method: 'post',
35+
},
36+
},
37+
],
38+
};
39+
});
40+
41+
it('should create a method resource', () => serverlessStepFunctions
42+
.compileMethods().then(() => {
43+
expect(serverlessStepFunctions.serverless.service.provider.compiledCloudFormationTemplate
44+
.Resources)
45+
.to.have.property('ApiGatewayMethodapiGatewayResourceNamesPost');
46+
})
47+
);
48+
});

lib/deploy/events/apiGateway/validate.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const _ = require('lodash');
55
module.exports = {
66
httpValidate() {
77
const events = [];
8-
const corsPreflight = {};
98

109
_.forEach(this.getAllStateMachines(), (stateMachineName) => {
1110
const stateMachineObj = this.getStateMachine(stateMachineName);
@@ -25,7 +24,6 @@ module.exports = {
2524

2625
return {
2726
events,
28-
corsPreflight,
2927
};
3028
},
3129

0 commit comments

Comments
 (0)