Skip to content

Commit 0d5a0a7

Browse files
test: added failing test for new feature
1 parent 6f33c81 commit 0d5a0a7

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

lib/deploy/stepFunctions/compileStateMachines.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,4 +731,50 @@ describe('#compileStateMachines', () => {
731731
expect(stateMachineObj.States).to.haveOwnProperty('RefreshLead');
732732
expect(stateMachineObj.States).to.haveOwnProperty('EndState');
733733
});
734+
735+
it('should support local function names', () => {
736+
serverless.service.functions = {
737+
'hello-world': {
738+
handler: 'hello-world.handler',
739+
},
740+
};
741+
serverless.service.stepFunctions = {
742+
stateMachines: {
743+
myStateMachine1: {
744+
id: 'Test',
745+
definition: {
746+
StartAt: 'Lambda',
747+
States: {
748+
Lambda: {
749+
Type: 'Task',
750+
Resource: {
751+
'Fn::GetAtt': ['hello-world', 'Arn'],
752+
},
753+
End: true,
754+
},
755+
},
756+
},
757+
},
758+
},
759+
};
760+
761+
serverlessStepFunctions.compileStateMachines();
762+
const stateMachine = serverlessStepFunctions.serverless.service
763+
.provider.compiledCloudFormationTemplate.Resources
764+
.Test;
765+
766+
expect(stateMachine.Properties.DefinitionString).to.haveOwnProperty('Fn::Sub');
767+
expect(stateMachine.Properties.DefinitionString['Fn::Sub']).to.have.lengthOf(2);
768+
769+
const [json, params] = stateMachine.Properties.DefinitionString['Fn::Sub'];
770+
const modifiedDefinition = JSON.parse(json);
771+
772+
const lambda = modifiedDefinition.States.Lambda;
773+
expect(lambda.Resource.startsWith('${')).to.eq(true);
774+
const functionParam = lambda.Resource.replace(/[${}]/g, '');
775+
expect(params).to.haveOwnProperty(functionParam);
776+
777+
const refParam = params[functionParam];
778+
expect(refParam).to.eql({ 'Fn::GetAtt': ['HelloDashWorldLambdaFunction', 'Arn'] });
779+
});
734780
});

0 commit comments

Comments
 (0)