-
Notifications
You must be signed in to change notification settings - Fork 215
/
Copy pathyamlParser.test.js
206 lines (178 loc) · 7.01 KB
/
yamlParser.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
'use strict';
const expect = require('chai').expect;
const Serverless = require('serverless/lib/Serverless');
const AwsProvider = require('serverless/lib/plugins/aws/provider');
const ServerlessStepFunctions = require('./index');
describe('#yamlParse', () => {
let serverless;
let serverlessStepFunctions;
beforeEach(() => {
serverless = new Serverless({
configuration: {
service: 'test',
provider: 'aws',
},
serviceDir: __dirname,
configurationFilename: 'serverless.yml',
isConfigurationResolved: true,
hasResovledCommandsExternally: true,
isTelemetryReportedExternally: true,
commands: ['info'],
options: {},
});
serverless.servicePath = true;
serverless.service.service = 'step-functions';
serverless.configSchemaHandler = {
// eslint-disable-next-line no-unused-vars
defineTopLevelProperty: (propertyName, propertySchema) => {},
};
serverless.setProvider('aws', new AwsProvider(serverless));
serverlessStepFunctions = new ServerlessStepFunctions(serverless);
});
describe('#yamlParse()', () => {
it('should default to dev when stage and provider are not defined', () => {
serverlessStepFunctions.serverless.pluginManager.cliOptions.stage = null;
serverlessStepFunctions.serverless.service.provider = null;
serverlessStepFunctions.yamlParse();
expect(serverless.pluginManager.cliOptions.stage).to.be.equal('dev');
});
it('should default to us-east-1 when region and provider are not defined', () => {
serverlessStepFunctions.serverless.pluginManager.cliOptions.region = null;
serverlessStepFunctions.serverless.service.provider = null;
serverlessStepFunctions.yamlParse();
expect(serverless.pluginManager.cliOptions.region).to.be.equal('us-east-1');
});
it('should not default to dev when stage is defined', () => {
serverlessStepFunctions.serverless.pluginManager.cliOptions.stage = 'my-stage';
serverlessStepFunctions.yamlParse();
expect(serverless.pluginManager.cliOptions.stage).to.be.equal('my-stage');
});
it('should not default to us-east-1 when region is defined', () => {
serverlessStepFunctions.serverless.pluginManager.cliOptions.region = 'my-region';
serverlessStepFunctions.yamlParse();
expect(serverless.pluginManager.cliOptions.region).to.be.equal('my-region');
});
it('should create empty object when stepfunctions param are not given', () => {
serverlessStepFunctions.yamlParse();
expect(serverless.service.stepFunctions.stateMachines).to.be.deep.equal({});
expect(serverless.service.stepFunctions.activities).to.be.deep.equal([]);
});
});
describe('#getAllStateMachines()', () => {
it('should throw error if atateMachines are not object', () => {
serverless.service.stepFunctions = {
stateMachines: 'aaa',
};
expect(() => serverlessStepFunctions.getAllStateMachines()).to.throw(Error);
serverless.service.stepFunctions = {
stateMachines: ['aaa', 'bbb'],
};
expect(() => serverlessStepFunctions.getAllStateMachines()).to.throw(Error);
});
it('should return statemachine names as array', () => {
serverless.service.stepFunctions = {
stateMachines: {
aaa: {},
bbb: {},
},
};
expect(serverlessStepFunctions.getAllStateMachines()[0]).to.be.equal('aaa');
expect(serverlessStepFunctions.getAllStateMachines()[1]).to.be.equal('bbb');
});
});
describe('#getStateMachine()', () => {
beforeEach(() => {
serverless.service.stepFunctions = {
stateMachines: {
aaa: {
definition: 'definition1',
},
},
};
});
it('should return statemachine object', () => {
expect(serverlessStepFunctions.getStateMachine('aaa').definition).to.be.equal('definition1');
});
it('should throw error if the statemachine does not exists', () => {
expect(() => serverlessStepFunctions.getStateMachine('bbb').definition).to.throw(Error);
});
});
describe('#isStateMachines()', () => {
it('should return true if the statemachines exists', () => {
serverless.service.stepFunctions = {
stateMachines: {
aaa: {
definition: 'definition1',
},
},
};
expect(serverlessStepFunctions.isStateMachines()).to.be.equal(true);
});
it('should return false if the stepfunctions does not exists', () => {
expect(serverlessStepFunctions.isStateMachines()).to.be.equal(false);
});
it('should return false if the stameMachines does not exists', () => {
serverless.service.stepFunctions = {};
expect(serverlessStepFunctions.isStateMachines()).to.be.equal(false);
});
it('should return false if the stameMachines is empty object', () => {
serverless.service.stepFunctions = {
stateMachines: {},
};
expect(serverlessStepFunctions.isStateMachines()).to.be.equal(false);
});
});
describe('#getAllActivities()', () => {
it('should throw error if activities are not array', () => {
serverless.service.stepFunctions = {
activities: 'aaa',
};
expect(() => serverlessStepFunctions.getAllActivities()).to.throw(Error);
serverless.service.stepFunctions = {
activities: { aaa: 'aaa' },
};
expect(() => serverlessStepFunctions.getAllActivities()).to.throw(Error);
});
it('should return activity names as array', () => {
serverless.service.stepFunctions = {
activities: ['aaa', 'bbb'],
};
expect(serverlessStepFunctions.getAllActivities()[0]).to.be.equal('aaa');
expect(serverlessStepFunctions.getAllActivities()[1]).to.be.equal('bbb');
});
});
describe('#getActivity()', () => {
beforeEach(() => {
serverless.service.stepFunctions = {
activities: ['aaa'],
};
});
it('should return activity name', () => {
expect(serverlessStepFunctions.getActivity('aaa')).to.be.equal('aaa');
});
it('should throw error if the activity does not exists', () => {
expect(() => serverlessStepFunctions.getActivity('bbb').definition).to.throw(Error);
});
});
describe('#isActivities()', () => {
it('should return true if the activities exists', () => {
serverless.service.stepFunctions = {
activities: ['aaa'],
};
expect(serverlessStepFunctions.isActivities()).to.be.equal(true);
});
it('should return false if the stepfunctions does not exists', () => {
expect(serverlessStepFunctions.isActivities()).to.be.equal(false);
});
it('should return false if the activities does not exists', () => {
serverless.service.stepFunctions = {};
expect(serverlessStepFunctions.isActivities()).to.be.equal(false);
});
it('should return false if the activities is empty array', () => {
serverless.service.stepFunctions = {
activities: [],
};
expect(serverlessStepFunctions.isActivities()).to.be.equal(false);
});
});
});