support for nested Input objects

This commit is contained in:
Kostas Bariotis 2016-10-30 10:57:01 +02:00
parent 60b4fd5c27
commit e3750e6400
3 changed files with 42 additions and 5 deletions

View File

@ -36,9 +36,13 @@ functions:
- schedule:
rate: rate(10 minutes)
enabled: false
input: '{"key": "value"}'
input:
key1: value1
key2: value2
stageParams:
stage: dev
- schedule:
rate: cron(0 12 * * ? *)
enabled: false
inputPath: ''
inputPath: '$.stageVariables'
```

View File

@ -42,6 +42,12 @@ class AwsCompileScheduledEvents {
State = event.schedule.enabled ? 'ENABLED' : 'DISABLED';
Input = event.schedule.input || '';
InputPath = event.schedule.inputPath || '';
if (Input && typeof Input === 'object') {
Input = JSON.stringify(Input);
}
// escape quotes to favor JSON.parse
Input = Input.replace(/\"/g,'\\"'); // eslint-disable-line
} else if (typeof event.schedule === 'string') {
ScheduleExpression = event.schedule;
State = 'ENABLED';

View File

@ -109,7 +109,8 @@ describe('AwsCompileScheduledEvents', () => {
schedule: {
rate: 'rate(10 minutes)',
enabled: false,
input: '{}',
input: '{"key":"value"}',
inputPath: '$.stageVariables',
},
},
],
@ -121,11 +122,37 @@ describe('AwsCompileScheduledEvents', () => {
expect(awsCompileScheduledEvents.serverless.service
.provider.compiledCloudFormationTemplate.Resources.FirstEventsRuleSchedule1
.Properties.Targets[0].Input
).to.equal('{}');
).to.equal('{"key":"value"}');
expect(awsCompileScheduledEvents.serverless.service
.provider.compiledCloudFormationTemplate.Resources.FirstEventsRuleSchedule1
.Properties.Targets[0].InputPath
).to.equal('');
).to.equal('$.stageVariables');
});
it('should respect input variable as an object', () => {
awsCompileScheduledEvents.serverless.service.functions = {
first: {
events: [
{
schedule: {
rate: 'rate(10 minutes)',
enabled: false,
input: {
key: 'value',
},
inputPath: '$.stageVariables',
},
},
],
},
};
awsCompileScheduledEvents.compileScheduledEvents();
expect(awsCompileScheduledEvents.serverless.service
.provider.compiledCloudFormationTemplate.Resources.FirstEventsRuleSchedule1
.Properties.Targets[0].Input
).to.equal('{"key":"value"}');
});
it('should not create corresponding resources when scheduled events are not given', () => {