1
1
'use strict' ;
2
2
3
+ const itParam = require ( 'mocha-param' ) ;
3
4
const expect = require ( 'chai' ) . expect ;
4
5
const Serverless = require ( 'serverless/lib/Serverless' ) ;
5
6
const AwsProvider = require ( 'serverless/lib/plugins/aws/provider/awsProvider' ) ;
@@ -21,13 +22,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
21
22
} ) ;
22
23
23
24
describe ( '#compileCloudWatchEventEvents()' , ( ) => {
24
- it ( 'should throw an error if cloudwatch event type is not an object' , ( ) => {
25
+ itParam ( 'should throw an error if event type is not an object' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
25
26
serverlessStepFunctions . serverless . service . stepFunctions = {
26
27
stateMachines : {
27
28
first : {
28
29
events : [
29
30
{
30
- cloudwatchEvent : 42 ,
31
+ [ source ] : 42 ,
31
32
} ,
32
33
] ,
33
34
} ,
@@ -37,13 +38,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
37
38
expect ( ( ) => serverlessStepFunctions . compileCloudWatchEventEvents ( ) ) . to . throw ( Error ) ;
38
39
} ) ;
39
40
40
- it ( 'should throw an error if the "event" property is not given' , ( ) => {
41
+ itParam ( 'should throw an error if the "event" property is not given' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
41
42
serverlessStepFunctions . serverless . service . stepFunctions = {
42
43
stateMachines : {
43
44
first : {
44
45
events : [
45
46
{
46
- cloudwatchEvent : {
47
+ [ source ] : {
47
48
event : null ,
48
49
} ,
49
50
} ,
@@ -55,13 +56,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
55
56
expect ( ( ) => serverlessStepFunctions . compileCloudWatchEventEvents ( ) ) . to . throw ( Error ) ;
56
57
} ) ;
57
58
58
- it ( 'should create corresponding resources when cloudwatch events are given' , ( ) => {
59
+ itParam ( 'should create corresponding resources when events are given' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
59
60
serverlessStepFunctions . serverless . service . stepFunctions = {
60
61
stateMachines : {
61
62
first : {
62
63
events : [
63
64
{
64
- cloudwatchEvent : {
65
+ [ source ] : {
65
66
event : {
66
67
source : [ 'aws.ec2' ] ,
67
68
'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -71,7 +72,7 @@ describe('awsCompileCloudWatchEventEvents', () => {
71
72
} ,
72
73
} ,
73
74
{
74
- cloudwatchEvent : {
75
+ [ source ] : {
75
76
event : {
76
77
source : [ 'aws.ec2' ] ,
77
78
'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -96,13 +97,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
96
97
. FirstEventToStepFunctionsRole . Type ) . to . equal ( 'AWS::IAM::Role' ) ;
97
98
} ) ;
98
99
99
- it ( 'should respect enabled variable, defaulting to true' , ( ) => {
100
+ itParam ( 'should respect enabled variable, defaulting to true' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
100
101
serverlessStepFunctions . serverless . service . stepFunctions = {
101
102
stateMachines : {
102
103
first : {
103
104
events : [
104
105
{
105
- cloudwatchEvent : {
106
+ [ source ] : {
106
107
event : {
107
108
source : [ 'aws.ec2' ] ,
108
109
'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -112,7 +113,7 @@ describe('awsCompileCloudWatchEventEvents', () => {
112
113
} ,
113
114
} ,
114
115
{
115
- cloudwatchEvent : {
116
+ [ source ] : {
116
117
event : {
117
118
source : [ 'aws.ec2' ] ,
118
119
'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -122,7 +123,7 @@ describe('awsCompileCloudWatchEventEvents', () => {
122
123
} ,
123
124
} ,
124
125
{
125
- cloudwatchEvent : {
126
+ [ source ] : {
126
127
event : {
127
128
source : [ 'aws.ec2' ] ,
128
129
'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -148,13 +149,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
148
149
. Properties . State ) . to . equal ( 'ENABLED' ) ;
149
150
} ) ;
150
151
151
- it ( 'should respect inputPath variable' , ( ) => {
152
+ itParam ( 'should respect inputPath variable' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
152
153
serverlessStepFunctions . serverless . service . stepFunctions = {
153
154
stateMachines : {
154
155
first : {
155
156
events : [
156
157
{
157
- cloudwatchEvent : {
158
+ [ source ] : {
158
159
event : {
159
160
source : [ 'aws.ec2' ] ,
160
161
'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -176,13 +177,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
176
177
. Properties . Targets [ 0 ] . InputPath ) . to . equal ( '$.stageVariables' ) ;
177
178
} ) ;
178
179
179
- it ( 'should respect input variable' , ( ) => {
180
+ itParam ( 'should respect input variable' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
180
181
serverlessStepFunctions . serverless . service . stepFunctions = {
181
182
stateMachines : {
182
183
first : {
183
184
events : [
184
185
{
185
- cloudwatchEvent : {
186
+ [ source ] : {
186
187
event : {
187
188
source : [ 'aws.ec2' ] ,
188
189
'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -204,13 +205,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
204
205
. Properties . Targets [ 0 ] . Input ) . to . equal ( '{"key":"value"}' ) ;
205
206
} ) ;
206
207
207
- it ( 'should respect description variable' , ( ) => {
208
+ itParam ( 'should respect description variable' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
208
209
serverlessStepFunctions . serverless . service . stepFunctions = {
209
210
stateMachines : {
210
211
first : {
211
212
events : [
212
213
{
213
- cloudwatchEvent : {
214
+ [ source ] : {
214
215
event : {
215
216
source : [ 'aws.ec2' ] ,
216
217
'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -233,13 +234,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
233
234
. Properties . Description ) . to . equal ( 'test description' ) ;
234
235
} ) ;
235
236
236
- it ( 'should respect name variable' , ( ) => {
237
+ itParam ( 'should respect name variable' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
237
238
serverlessStepFunctions . serverless . service . stepFunctions = {
238
239
stateMachines : {
239
240
first : {
240
241
events : [
241
242
{
242
- cloudwatchEvent : {
243
+ [ source ] : {
243
244
event : {
244
245
source : [ 'aws.ec2' ] ,
245
246
'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -262,13 +263,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
262
263
. Properties . Name ) . to . equal ( 'test-event-name' ) ;
263
264
} ) ;
264
265
265
- it ( 'should respect eventBusName variable' , ( ) => {
266
+ itParam ( 'should respect eventBusName variable' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
266
267
serverlessStepFunctions . serverless . service . stepFunctions = {
267
268
stateMachines : {
268
269
first : {
269
270
events : [
270
271
{
271
- cloudwatchEvent : {
272
+ [ source ] : {
272
273
event : {
273
274
source : [ 'aws.ec2' ] ,
274
275
'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -292,13 +293,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
292
293
. Properties . EventBusName ) . to . equal ( 'custom-event-bus' ) ;
293
294
} ) ;
294
295
295
- it ( 'should respect input variable as an object' , ( ) => {
296
+ itParam ( 'should respect input variable as an object' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
296
297
serverlessStepFunctions . serverless . service . stepFunctions = {
297
298
stateMachines : {
298
299
first : {
299
300
events : [
300
301
{
301
- cloudwatchEvent : {
302
+ [ source ] : {
302
303
event : {
303
304
source : [ 'aws.ec2' ] ,
304
305
'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -322,13 +323,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
322
323
. Properties . Targets [ 0 ] . Input ) . to . equal ( '{"key":"value"}' ) ;
323
324
} ) ;
324
325
325
- it ( 'should throw an error when both Input and InputPath are set' , ( ) => {
326
+ itParam ( 'should throw an error when both Input and InputPath are set' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
326
327
serverlessStepFunctions . serverless . service . stepFunctions = {
327
328
stateMachines : {
328
329
first : {
329
330
events : [
330
331
{
331
- cloudwatchEvent : {
332
+ [ source ] : {
332
333
event : {
333
334
source : [ 'aws.ec2' ] ,
334
335
'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -349,13 +350,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
349
350
expect ( ( ) => serverlessStepFunctions . compileCloudWatchEventEvents ( ) ) . to . throw ( Error ) ;
350
351
} ) ;
351
352
352
- it ( 'should respect variables if multi-line variables is given' , ( ) => {
353
+ itParam ( 'should respect variables if multi-line variables is given' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
353
354
serverlessStepFunctions . serverless . service . stepFunctions = {
354
355
stateMachines : {
355
356
first : {
356
357
events : [
357
358
{
358
- cloudwatchEvent : {
359
+ [ source ] : {
359
360
event : {
360
361
source : [ 'aws.ec2' ] ,
361
362
'detail-type' : [ 'EC2 Instance State-change Notification \n with newline' ] ,
@@ -381,7 +382,7 @@ describe('awsCompileCloudWatchEventEvents', () => {
381
382
. FirstEventsRuleCloudWatchEvent1 . Properties . Targets [ 0 ] . Input ) . to . equal ( '{"key":"value"}' ) ;
382
383
} ) ;
383
384
384
- it ( 'should not create corresponding resources when cloudwatch events are not given' , ( ) => {
385
+ it ( 'should not create corresponding resources when events are not given' , ( ) => {
385
386
serverlessStepFunctions . serverless . service . stepFunctions = {
386
387
stateMachines : {
387
388
first : {
0 commit comments