Skip to content

Commit 3b44457

Browse files
committed
update test code
1 parent f1b5796 commit 3b44457

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,9 @@ class ServerlessStepFunctions {
449449
this.options.region)
450450
.then((result) => {
451451
this.stateMachineArns[stateMachine] =
452-
`arn:aws:states:${this.region}:${result.Account}:
453-
stateMachine:${this.getStateMachineName(stateMachine)}`;
452+
`arn:aws:states:${this.region}:${result.Account}:`;
453+
this.stateMachineArns[stateMachine] +=
454+
`stateMachine:${this.getStateMachineName(stateMachine)}`;
454455
return BbPromise.resolve();
455456
});
456457
}
@@ -464,8 +465,9 @@ class ServerlessStepFunctions {
464465
.then((result) => {
465466
_.forEach(this.serverless.service.stepFunctions, (value, key) => {
466467
this.stateMachineArns[key] =
467-
`arn:aws:states:${this.region}:${result.Account}:
468-
stateMachine:${this.getStateMachineName(key)}`;
468+
`arn:aws:states:${this.region}:${result.Account}:`;
469+
this.stateMachineArns[key] +=
470+
`stateMachine:${this.getStateMachineName(key)}`;
469471
});
470472
return BbPromise.resolve();
471473
});
@@ -645,7 +647,6 @@ class ServerlessStepFunctions {
645647

646648
this.serverless.service.stepFunctions[this.options.state] =
647649
JSON.stringify(this.serverless.service.stepFunctions[this.options.state]);
648-
649650
_.forEach(this.functionArns, (value, key) => {
650651
const regExp = new RegExp(`"Resource":"${key}"`, 'g');
651652
this.serverless.service.stepFunctions[this.options.state] =

index.test.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ describe('ServerlessStepFunctions', () => {
2222
name: 'first',
2323
},
2424
};
25+
2526
const options = {
2627
stage: 'dev',
2728
region: 'us-east-1',
2829
function: 'first',
2930
functionObj: {
3031
name: 'first',
3132
},
32-
state: 'stateMachine',
33+
state: 'hellofunc',
3334
data: 'inputData',
3435
};
3536

@@ -190,15 +191,15 @@ describe('ServerlessStepFunctions', () => {
190191

191192
describe('#getIamRoleName', () => {
192193
it('should return IamRoleName', () => {
193-
expect(serverlessStepFunctions.getIamRoleName())
194-
.to.be.equal('step-functions-us-east-1-dev-stateMachine-ssf-exerole');
194+
expect(serverlessStepFunctions.getIamRoleName('state'))
195+
.to.be.equal('step-functions-us-east-1-dev-state-ssf-exerole');
195196
});
196197
});
197198

198199
describe('#getIamPolicyName', () => {
199200
it('should return IamPolicyName', () => {
200-
expect(serverlessStepFunctions.getIamPolicyName())
201-
.to.be.equal('step-functions-us-east-1-dev-stateMachine-ssf-exepolicy');
201+
expect(serverlessStepFunctions.getIamPolicyName('state'))
202+
.to.be.equal('step-functions-us-east-1-dev-state-ssf-exepolicy');
202203
});
203204
});
204205

@@ -209,19 +210,19 @@ describe('ServerlessStepFunctions', () => {
209210
.returns(BbPromise.resolve({ Role: { Arn: 'roleArn' } }));
210211
});
211212

212-
it('should getIamRole with correct params', () => serverlessStepFunctions.getIamRole()
213+
it('should getIamRole with correct params', () => serverlessStepFunctions.getIamRole('state')
213214
.then(() => {
214215
expect(getRoleStub.calledOnce).to.be.equal(true);
215216
expect(getRoleStub.calledWithExactly(
216217
'IAM',
217218
'getRole',
218219
{
219-
RoleName: 'step-functions-us-east-1-dev-stateMachine-ssf-exerole',
220+
RoleName: 'step-functions-us-east-1-dev-state-ssf-exerole',
220221
},
221222
serverlessStepFunctions.options.stage,
222223
serverlessStepFunctions.options.region
223224
)).to.be.equal(true);
224-
expect(serverlessStepFunctions.iamRoleArn).to.be.equal('roleArn');
225+
expect(serverlessStepFunctions.iamRoleArn.state).to.be.equal('roleArn');
225226
serverlessStepFunctions.provider.request.restore();
226227
})
227228
);
@@ -335,7 +336,7 @@ describe('ServerlessStepFunctions', () => {
335336
});
336337

337338
it('should getStateMachineStub with correct params'
338-
, () => serverlessStepFunctions.getStateMachineArn()
339+
, () => serverlessStepFunctions.getStateMachineArn('state')
339340
.then(() => {
340341
expect(getStateMachineStub.calledOnce).to.be.equal(true);
341342
expect(getStateMachineStub.calledWithExactly(
@@ -345,8 +346,8 @@ describe('ServerlessStepFunctions', () => {
345346
serverlessStepFunctions.options.stage,
346347
serverlessStepFunctions.options.region
347348
)).to.be.equal(true);
348-
expect(serverlessStepFunctions.stateMachineArn).to.be
349-
.equal('arn:aws:states:us-east-1:1234:stateMachine:step-functions-dev-stateMachine');
349+
expect(serverlessStepFunctions.stateMachineArns.state).to.be
350+
.equal('arn:aws:states:us-east-1:1234:stateMachine:step-functions-dev-state');
350351
serverlessStepFunctions.provider.request.restore();
351352
})
352353
);
@@ -382,22 +383,22 @@ describe('ServerlessStepFunctions', () => {
382383
beforeEach(() => {
383384
createStateMachineStub = sinon.stub(serverlessStepFunctions.provider, 'request')
384385
.returns(BbPromise.resolve());
386+
serverlessStepFunctions.serverless.service.stepFunctions = { state: 'state' };
385387
});
386388

387389
it('should createStateMachine with correct params'
388-
, () => serverlessStepFunctions.createStateMachine()
390+
, () => serverlessStepFunctions.createStateMachine('state')
389391
.then(() => {
390392
const stage = serverlessStepFunctions.options.stage;
391-
const state = serverlessStepFunctions.options.state;
392393
expect(createStateMachineStub.calledOnce).to.be.equal(true);
393394
expect(createStateMachineStub.calledWithExactly(
394395
'StepFunctions',
395396
'createStateMachine',
396397
{
397398
definition: serverlessStepFunctions
398-
.awsStateLanguage[serverlessStepFunctions.options.state],
399-
name: `${serverless.service.service}-${stage}-${state}`,
400-
roleArn: serverlessStepFunctions.iamRoleArn,
399+
.serverless.service.stepFunctions.state,
400+
name: `${serverless.service.service}-${stage}-state`,
401+
roleArn: serverlessStepFunctions.iamRoleArn.state,
401402
},
402403
serverlessStepFunctions.options.stage,
403404
serverlessStepFunctions.options.region
@@ -591,7 +592,7 @@ describe('ServerlessStepFunctions', () => {
591592

592593
it('should comple with correct params', () => {
593594
serverless.service.stepFunctions = {
594-
stateMachine: {
595+
hellofunc: {
595596
States: {
596597
HelloWorld: {
597598
Resource: 'first',
@@ -601,14 +602,14 @@ describe('ServerlessStepFunctions', () => {
601602
};
602603
serverlessStepFunctions.functionArns.first = 'lambdaArn';
603604
serverlessStepFunctions.compile().then(() => {
604-
expect(serverlessStepFunctions.awsStateLanguage.stateMachine)
605+
expect(serverlessStepFunctions.serverless.service.stepFunctions.hellofunc)
605606
.to.be.equal('{"States":{"HelloWorld":{"Resource":"lambdaArn"}}}');
606607
});
607608
});
608609

609610
it('should comple with correct params when nested Resource', () => {
610-
serverless.service.stepFunctions = {
611-
stateMachine: {
611+
serverlessStepFunctions.serverless.service.stepFunctions = {
612+
hellofunc: {
612613
States: {
613614
HelloWorld: {
614615
Resource: 'first',
@@ -627,7 +628,7 @@ describe('ServerlessStepFunctions', () => {
627628
a += ':{"Resource":"lambdaArn","HelloWorld":{"Resource":"lambdaArn"}}}}}';
628629
serverlessStepFunctions.functionArns.first = 'lambdaArn';
629630
serverlessStepFunctions.compile().then(() => {
630-
expect(serverlessStepFunctions.awsStateLanguage.stateMachine).to.be.equal(a);
631+
expect(serverlessStepFunctions.serverless.service.stepFunctions.hellofunc).to.be.equal(a);
631632
});
632633
});
633634
});

0 commit comments

Comments
 (0)