Skip to content

Commit 31e5d07

Browse files
committed
replacing task arn
1 parent ab882fb commit 31e5d07

File tree

4 files changed

+101
-7
lines changed

4 files changed

+101
-7
lines changed

lib/dataProcessing.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,21 @@ module.exports = {
7272

7373
this.serverless.service.stepFunctions.stateMachines[this.options.name] =
7474
JSON.stringify(this.serverless.service.stepFunctions.stateMachines[this.options.name]);
75-
_.forEach(this.functionArns, (value, key) => {
76-
const regExp = new RegExp(`"Resource":"${key}"`, 'g');
75+
_.forEach(this.functionArns, (functionArn, functionName) => {
76+
const regExp = new RegExp(`"Resource":"${functionName}"`, 'g');
7777
this.serverless.service.stepFunctions.stateMachines[this.options.name] =
7878
this.serverless.service.stepFunctions.stateMachines[this.options.name]
79-
.replace(regExp, `"Resource":"${value}"`);
79+
.replace(regExp, `"Resource":"${functionArn}"`);
80+
});
81+
82+
_.forEach(this.activityArns, (activityArn, activityName) => {
83+
const regExp = new RegExp(`"Resource":"${activityName}"`, 'g');
84+
_.forEach(this.serverless.service.stepFunctions.stateMachines,
85+
(stepFunctionObj, stepFunctionKey) => {
86+
this.serverless.service.stepFunctions.stateMachines[stepFunctionKey] =
87+
this.serverless.service.stepFunctions.stateMachines[stepFunctionKey]
88+
.replace(regExp, `"Resource":"${activityArn}"`);
89+
});
8090
});
8191
return BbPromise.resolve();
8292
},
@@ -95,13 +105,23 @@ module.exports = {
95105
= JSON.stringify(stepFunctionObj);
96106
});
97107

98-
_.forEach(this.functionArns, (functionObj, functionKey) => {
99-
const regExp = new RegExp(`"Resource":"${functionKey}"`, 'g');
108+
_.forEach(this.functionArns, (functionArn, functionName) => {
109+
const regExp = new RegExp(`"Resource":"${functionName}"`, 'g');
110+
_.forEach(this.serverless.service.stepFunctions.stateMachines,
111+
(stepFunctionObj, stepFunctionKey) => {
112+
this.serverless.service.stepFunctions.stateMachines[stepFunctionKey] =
113+
this.serverless.service.stepFunctions.stateMachines[stepFunctionKey]
114+
.replace(regExp, `"Resource":"${functionArn}"`);
115+
});
116+
});
117+
118+
_.forEach(this.activityArns, (activityArn, activityName) => {
119+
const regExp = new RegExp(`"Resource":"${activityName}"`, 'g');
100120
_.forEach(this.serverless.service.stepFunctions.stateMachines,
101121
(stepFunctionObj, stepFunctionKey) => {
102122
this.serverless.service.stepFunctions.stateMachines[stepFunctionKey] =
103123
this.serverless.service.stepFunctions.stateMachines[stepFunctionKey]
104-
.replace(regExp, `"Resource":"${functionObj}"`);
124+
.replace(regExp, `"Resource":"${activityArn}"`);
105125
});
106126
});
107127
return BbPromise.resolve();

lib/dataProcessing.test.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,49 @@ describe('dataProsessing', () => {
142142
.to.be.equal(a);
143143
});
144144
});
145+
146+
it('should comple with replacing activityArn', () => {
147+
serverless.service.stepFunctions.stateMachines = {
148+
hellofunc: {
149+
States: {
150+
HelloWorld: {
151+
Resource: 'someActivity',
152+
},
153+
},
154+
},
155+
};
156+
serverlessStepFunctions.activityArns.someActivity = 'activityArn';
157+
serverlessStepFunctions.compile().then(() => {
158+
expect(serverlessStepFunctions.serverless.service.stepFunctions.stateMachines.hellofunc)
159+
.to.be.equal('{"States":{"HelloWorld":{"Resource":"activityArn"}}}');
160+
});
161+
});
162+
163+
it('should comple with correct params when nested Resource with replacing activityArn', () => {
164+
serverlessStepFunctions.serverless.service.stepFunctions.stateMachines = {
165+
hellofunc: {
166+
States: {
167+
HelloWorld: {
168+
Resource: 'someActivity',
169+
HelloWorld: {
170+
Resource: 'someActivity',
171+
HelloWorld: {
172+
Resource: 'someActivity',
173+
},
174+
},
175+
},
176+
},
177+
},
178+
};
179+
180+
let a = '{"States":{"HelloWorld":{"Resource":"activityArn","HelloWorld"';
181+
a += ':{"Resource":"activityArn","HelloWorld":{"Resource":"activityArn"}}}}}';
182+
serverlessStepFunctions.activityArns.someActivity = 'activityArn';
183+
serverlessStepFunctions.compile().then(() => {
184+
expect(serverlessStepFunctions.serverless.service.stepFunctions.stateMachines.hellofunc)
185+
.to.be.equal(a);
186+
});
187+
});
145188
});
146189

147190
describe('#parseInputdate()', () => {
@@ -242,5 +285,31 @@ describe('dataProsessing', () => {
242285
.to.be.equal(a);
243286
});
244287
});
288+
289+
it('should comple with correct params when nested Resource with replacing activityArn', () => {
290+
serverlessStepFunctions.serverless.service.stepFunctions.stateMachines = {
291+
hellofunc: {
292+
States: {
293+
HelloWorld: {
294+
Resource: 'someActivity',
295+
HelloWorld: {
296+
Resource: 'someActivity',
297+
HelloWorld: {
298+
Resource: 'someActivity',
299+
},
300+
},
301+
},
302+
},
303+
},
304+
};
305+
306+
let a = '{"States":{"HelloWorld":{"Resource":"activityArn","HelloWorld"';
307+
a += ':{"Resource":"activityArn","HelloWorld":{"Resource":"activityArn"}}}}}';
308+
serverlessStepFunctions.activityArns.someActivity = 'activityArn';
309+
serverlessStepFunctions.compileAll().then(() => {
310+
expect(serverlessStepFunctions.serverless.service.stepFunctions.stateMachines.hellofunc)
311+
.to.be.equal(a);
312+
});
313+
});
245314
});
246315
});

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ class ServerlessStepFunctions {
354354
.then(this.yamlParse)
355355
.then(this.getStateMachineArn)
356356
.then(this.getFunctionArns)
357+
.then(this.getActivityArns)
357358
.then(this.compile)
358359
.then(this.getIamRole)
359360
.then(this.deleteStateMachine)

lib/index.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ describe('ServerlessStepFunctions', () => {
252252
.stub(serverlessStepFunctions, 'getStateMachineArn').returns(BbPromise.resolve());
253253
const getFunctionArnsStub = sinon
254254
.stub(serverlessStepFunctions, 'getFunctionArns').returns(BbPromise.resolve());
255+
const getActivityArnsStub = sinon
256+
.stub(serverlessStepFunctions, 'getActivityArns').returns(BbPromise.resolve());
255257
const compileStub = sinon
256258
.stub(serverlessStepFunctions, 'compile').returns(BbPromise.resolve());
257259
const getIamRoleStub = sinon
@@ -266,14 +268,16 @@ describe('ServerlessStepFunctions', () => {
266268
expect(yamlParseStub.calledOnce).to.be.equal(true);
267269
expect(getStateMachineArnStub.calledAfter(yamlParseStub)).to.be.equal(true);
268270
expect(getFunctionArnsStub.calledAfter(getStateMachineArnStub)).to.be.equal(true);
269-
expect(compileStub.calledAfter(getFunctionArnsStub)).to.be.equal(true);
271+
expect(getActivityArnsStub.calledAfter(getFunctionArnsStub)).to.be.equal(true);
272+
expect(compileStub.calledAfter(getActivityArnsStub)).to.be.equal(true);
270273
expect(getIamRoleStub.calledAfter(compileStub)).to.be.equal(true);
271274
expect(deleteStateMachineStub.calledAfter(getIamRoleStub)).to.be.equal(true);
272275
expect(createStateMachineStub.calledAfter(deleteStateMachineStub)).to.be.equal(true);
273276

274277
serverlessStepFunctions.yamlParse.restore();
275278
serverlessStepFunctions.getStateMachineArn.restore();
276279
serverlessStepFunctions.getFunctionArns.restore();
280+
serverlessStepFunctions.getActivityArns.restore();
277281
serverlessStepFunctions.compile.restore();
278282
serverlessStepFunctions.getIamRole.restore();
279283
serverlessStepFunctions.deleteStateMachine.restore();

0 commit comments

Comments
 (0)