Skip to content

Commit acaf689

Browse files
committed
add conditions for empty of activities
1 parent 6c422c4 commit acaf689

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

lib/yamlParser.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
const BbPromise = require('bluebird');
33
const path = require('path');
4+
const _ = require('lodash');
45

56
module.exports = {
67
yamlParse() {
@@ -21,7 +22,7 @@ module.exports = {
2122
this.serverless.service.stepFunctions.activities
2223
= serverlessFileParam.stepFunctions
2324
&& serverlessFileParam.stepFunctions.activities
24-
? serverlessFileParam.stepFunctions.activities : {};
25+
? serverlessFileParam.stepFunctions.activities : [];
2526
this.serverless.variables.populateService(this.serverless.pluginManager.cliOptions);
2627
return BbPromise.resolve();
2728
});
@@ -49,8 +50,9 @@ module.exports = {
4950
},
5051

5152
isStateMachines() {
52-
if (this.serverless.service.stepFunctions
53-
&& this.serverless.service.stepFunctions.stateMachines) {
53+
if (this.serverless.service.stepFunctions != null
54+
&& this.serverless.service.stepFunctions.stateMachines != null
55+
&& !_.isEmpty(this.serverless.service.stepFunctions.stateMachines)) {
5456
return true;
5557
}
5658
return false;
@@ -78,8 +80,9 @@ module.exports = {
7880
},
7981

8082
isActivities() {
81-
if (this.serverless.service.stepFunctions
82-
&& this.serverless.service.stepFunctions.activities) {
83+
if (this.serverless.service.stepFunctions != null
84+
&& this.serverless.service.stepFunctions.activities != null
85+
&& !_.isEmpty(this.serverless.service.stepFunctions.activities)) {
8386
return true;
8487
}
8588
return false;

lib/yamlParser.test.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('#yamlParse', () => {
7070
expect(yamlParserStub.calledOnce).to.be.equal(true);
7171
expect(populateServiceStub.calledOnce).to.be.equal(true);
7272
expect(serverless.service.stepFunctions.stateMachines).to.be.deep.equal({});
73-
expect(serverless.service.stepFunctions.activities).to.be.deep.equal({});
73+
expect(serverless.service.stepFunctions.activities).to.be.deep.equal([]);
7474
serverlessStepFunctions.serverless.yamlParser.parse.restore();
7575
serverlessStepFunctions.serverless.variables.populateService.restore();
7676
});
@@ -142,6 +142,13 @@ describe('#yamlParse', () => {
142142
serverless.service.stepFunctions = {};
143143
expect(serverlessStepFunctions.isStateMachines()).to.be.equal(false);
144144
});
145+
146+
it('should return false if the stameMachines is empty object', () => {
147+
serverless.service.stepFunctions = {
148+
stateMachines: {},
149+
};
150+
expect(serverlessStepFunctions.isStateMachines()).to.be.equal(false);
151+
});
145152
});
146153

147154
describe('#getAllActivities()', () => {
@@ -198,5 +205,12 @@ describe('#yamlParse', () => {
198205
serverless.service.stepFunctions = {};
199206
expect(serverlessStepFunctions.isActivities()).to.be.equal(false);
200207
});
208+
209+
it('should return false if the activities is empty array', () => {
210+
serverless.service.stepFunctions = {
211+
activities: [],
212+
};
213+
expect(serverlessStepFunctions.isActivities()).to.be.equal(false);
214+
});
201215
});
202216
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-step-functions",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "The module is AWS Step Functions plugin for Serverless Framework",
55
"main": "lib/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)