Skip to content

Commit 00bc4cf

Browse files
committed
test: add test for jsonata
1 parent 313355a commit 00bc4cf

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

lib/deploy/stepFunctions/compileStateMachines.test.js

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('#compileStateMachines', () => {
1616
serverless.cli = new CLI(serverless);
1717
serverless.configSchemaHandler = {
1818
// eslint-disable-next-line no-unused-vars
19-
defineTopLevelProperty: (propertyName, propertySchema) => {},
19+
defineTopLevelProperty: (propertyName, propertySchema) => { },
2020
};
2121
serverless.servicePath = true;
2222
serverless.service.service = 'step-functions';
@@ -1728,4 +1728,59 @@ describe('#compileStateMachines', () => {
17281728
const stateMachineObj = JSON.parse(stateMachine.Properties.DefinitionString);
17291729
expect(stateMachineObj.States).to.haveOwnProperty('One');
17301730
});
1731+
1732+
it('should compile with the new JSONata fields', () => {
1733+
serverless.service.stepFunctions = {
1734+
stateMachines: {
1735+
myStateMachine1: {
1736+
id: 'Test',
1737+
name: 'Test',
1738+
definition: {
1739+
Comment: 'Test JSONata features',
1740+
QueryLanguage: 'JSONata',
1741+
StartAt: 'Store inputs',
1742+
States: {
1743+
'Store inputs': {
1744+
Type: 'Pass',
1745+
Next: 'Output transformation',
1746+
Assign: {
1747+
desiredPrice: '{% $states.input.desired_price %}',
1748+
maximumWait: '{% $states.input.max_days %}',
1749+
},
1750+
},
1751+
'Output transformation': {
1752+
Type: 'Succeed',
1753+
Output: {
1754+
lastName:
1755+
"{% 'Last=>' & $states.input.customer.lastName %}",
1756+
orderValue: '{% $states.input.order.total %}',
1757+
},
1758+
},
1759+
},
1760+
},
1761+
},
1762+
},
1763+
};
1764+
1765+
serverlessStepFunctions.compileStateMachines();
1766+
1767+
const stateMachine = serverlessStepFunctions.serverless.service
1768+
.provider.compiledCloudFormationTemplate.Resources
1769+
.Test;
1770+
1771+
expect(stateMachine.Properties.DefinitionString).not.to.haveOwnProperty('Fn::Sub');
1772+
const stateMachineObj = JSON.parse(stateMachine.Properties.DefinitionString);
1773+
expect(stateMachineObj.States).to.haveOwnProperty('Store inputs');
1774+
expect(stateMachineObj.States).to.haveOwnProperty('Output transformation');
1775+
1776+
expect(stateMachineObj.QueryLanguage).to.equal('JSONata');
1777+
expect(stateMachineObj.States['Store inputs'].Assign).to.deep.equal({
1778+
desiredPrice: '{% $states.input.desired_price %}',
1779+
maximumWait: '{% $states.input.max_days %}',
1780+
});
1781+
expect(stateMachineObj.States['Output transformation'].Output).to.deep.equal({
1782+
lastName: "{% 'Last=>' & $states.input.customer.lastName %}",
1783+
orderValue: '{% $states.input.order.total %}',
1784+
});
1785+
});
17311786
});

0 commit comments

Comments
 (0)