Skip to content

Commit a5507dc

Browse files
committed
fix: test codes and coverage. fixed check logic for coverage
1 parent 8a6629f commit a5507dc

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

lib/deploy/events/apiGateway/iamRole.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ module.exports = {
1919

2020
// generate IAM Role action by http.action parameter.
2121
this.pluginhttpValidated.events.forEach((event) => {
22-
if (!_.has(event, 'http')) return;
23-
24-
if (_.has(event.http, 'action')) {
22+
if (_.has(event, 'http.action')) {
2523
const actionName = `states:${event.http.action}`;
2624

2725
if (iamRoleApiGatewayToStepFunctionsAction.indexOf(actionName) === -1) {

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,56 @@ describe('#compileHttpIamRole()', () => {
120120
expect(resources).to.not.haveOwnProperty('ApigatewayToStepFunctionsRole');
121121
});
122122
});
123+
124+
it('Should add DescribeExecution action when it is assigned in config', () => {
125+
serverlessStepFunctions.pluginhttpValidated = {
126+
events: [
127+
{
128+
stateMachineName: 'first',
129+
http: {
130+
path: 'foo/bar1',
131+
method: 'post',
132+
},
133+
},
134+
{
135+
stateMachineName: 'first',
136+
http: {
137+
path: 'foo/bar2',
138+
method: 'post',
139+
action: 'DescribeExecution',
140+
},
141+
},
142+
],
143+
};
144+
145+
serverlessStepFunctions
146+
.compileHttpIamRole().then(() => {
147+
const properties = serverlessStepFunctions.serverless.service.provider
148+
.compiledCloudFormationTemplate.Resources.ApigatewayToStepFunctionsRole.Properties;
149+
expect(properties.Policies[0].PolicyDocument.Statement[0].Action)
150+
.to.deep.equal(['states:StartExecution', 'states:DescribeExecution']);
151+
});
152+
});
153+
154+
it('Should not add DescribeExecution action when it is not assigned in config', () => {
155+
serverlessStepFunctions.pluginhttpValidated = {
156+
events: [
157+
{
158+
stateMachineName: 'first',
159+
http: {
160+
path: 'foo/bar1',
161+
method: 'post',
162+
},
163+
},
164+
],
165+
};
166+
167+
serverlessStepFunctions
168+
.compileHttpIamRole().then(() => {
169+
const properties = serverlessStepFunctions.serverless.service.provider
170+
.compiledCloudFormationTemplate.Resources.ApigatewayToStepFunctionsRole.Properties;
171+
expect(properties.Policies[0].PolicyDocument.Statement[0].Action)
172+
.to.deep.equal(['states:StartExecution']);
173+
});
174+
});
123175
});

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ describe('#methods()', () => {
131131
.ResponseParameters['method.response.header.Access-Control-Allow-Origin'])
132132
.to.equal('\'*\'');
133133
});
134+
135+
it('should change passthroughBehavior and action when action is set',
136+
() => {
137+
expect(serverlessStepFunctions.getMethodIntegration('stateMachine', 'custom', {
138+
action: 'DescribeExecution',
139+
}).Properties.Integration.PassthroughBehavior)
140+
.to.equal('WHEN_NO_TEMPLATES');
141+
142+
expect(serverlessStepFunctions.getMethodIntegration('stateMachine', 'custom', {
143+
action: 'DescribeExecution',
144+
}).Properties.Integration.Uri['Fn::Join'][1][2])
145+
.to.equal(':states:action/DescribeExecution');
146+
});
134147
});
135148

136149
describe('#getIntegrationRequestTemplates()', () => {

0 commit comments

Comments
 (0)