11'use strict' ;
22
3+ const itParam = require ( 'mocha-param' ) ;
34const expect = require ( 'chai' ) . expect ;
45const Serverless = require ( 'serverless/lib/Serverless' ) ;
56const AwsProvider = require ( 'serverless/lib/plugins/aws/provider/awsProvider' ) ;
@@ -21,13 +22,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
2122 } ) ;
2223
2324 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 ) => {
2526 serverlessStepFunctions . serverless . service . stepFunctions = {
2627 stateMachines : {
2728 first : {
2829 events : [
2930 {
30- cloudwatchEvent : 42 ,
31+ [ source ] : 42 ,
3132 } ,
3233 ] ,
3334 } ,
@@ -37,13 +38,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
3738 expect ( ( ) => serverlessStepFunctions . compileCloudWatchEventEvents ( ) ) . to . throw ( Error ) ;
3839 } ) ;
3940
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 ) => {
4142 serverlessStepFunctions . serverless . service . stepFunctions = {
4243 stateMachines : {
4344 first : {
4445 events : [
4546 {
46- cloudwatchEvent : {
47+ [ source ] : {
4748 event : null ,
4849 } ,
4950 } ,
@@ -55,13 +56,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
5556 expect ( ( ) => serverlessStepFunctions . compileCloudWatchEventEvents ( ) ) . to . throw ( Error ) ;
5657 } ) ;
5758
58- it ( 'should create corresponding resources when cloudwatch events are given' , ( ) => {
59+ itParam ( 'should create corresponding resources when events are given' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
5960 serverlessStepFunctions . serverless . service . stepFunctions = {
6061 stateMachines : {
6162 first : {
6263 events : [
6364 {
64- cloudwatchEvent : {
65+ [ source ] : {
6566 event : {
6667 source : [ 'aws.ec2' ] ,
6768 'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -71,7 +72,7 @@ describe('awsCompileCloudWatchEventEvents', () => {
7172 } ,
7273 } ,
7374 {
74- cloudwatchEvent : {
75+ [ source ] : {
7576 event : {
7677 source : [ 'aws.ec2' ] ,
7778 'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -96,13 +97,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
9697 . FirstEventToStepFunctionsRole . Type ) . to . equal ( 'AWS::IAM::Role' ) ;
9798 } ) ;
9899
99- it ( 'should respect enabled variable, defaulting to true' , ( ) => {
100+ itParam ( 'should respect enabled variable, defaulting to true' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
100101 serverlessStepFunctions . serverless . service . stepFunctions = {
101102 stateMachines : {
102103 first : {
103104 events : [
104105 {
105- cloudwatchEvent : {
106+ [ source ] : {
106107 event : {
107108 source : [ 'aws.ec2' ] ,
108109 'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -112,7 +113,7 @@ describe('awsCompileCloudWatchEventEvents', () => {
112113 } ,
113114 } ,
114115 {
115- cloudwatchEvent : {
116+ [ source ] : {
116117 event : {
117118 source : [ 'aws.ec2' ] ,
118119 'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -122,7 +123,7 @@ describe('awsCompileCloudWatchEventEvents', () => {
122123 } ,
123124 } ,
124125 {
125- cloudwatchEvent : {
126+ [ source ] : {
126127 event : {
127128 source : [ 'aws.ec2' ] ,
128129 'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -148,13 +149,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
148149 . Properties . State ) . to . equal ( 'ENABLED' ) ;
149150 } ) ;
150151
151- it ( 'should respect inputPath variable' , ( ) => {
152+ itParam ( 'should respect inputPath variable' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
152153 serverlessStepFunctions . serverless . service . stepFunctions = {
153154 stateMachines : {
154155 first : {
155156 events : [
156157 {
157- cloudwatchEvent : {
158+ [ source ] : {
158159 event : {
159160 source : [ 'aws.ec2' ] ,
160161 'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -176,13 +177,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
176177 . Properties . Targets [ 0 ] . InputPath ) . to . equal ( '$.stageVariables' ) ;
177178 } ) ;
178179
179- it ( 'should respect input variable' , ( ) => {
180+ itParam ( 'should respect input variable' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
180181 serverlessStepFunctions . serverless . service . stepFunctions = {
181182 stateMachines : {
182183 first : {
183184 events : [
184185 {
185- cloudwatchEvent : {
186+ [ source ] : {
186187 event : {
187188 source : [ 'aws.ec2' ] ,
188189 'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -204,13 +205,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
204205 . Properties . Targets [ 0 ] . Input ) . to . equal ( '{"key":"value"}' ) ;
205206 } ) ;
206207
207- it ( 'should respect description variable' , ( ) => {
208+ itParam ( 'should respect description variable' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
208209 serverlessStepFunctions . serverless . service . stepFunctions = {
209210 stateMachines : {
210211 first : {
211212 events : [
212213 {
213- cloudwatchEvent : {
214+ [ source ] : {
214215 event : {
215216 source : [ 'aws.ec2' ] ,
216217 'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -233,13 +234,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
233234 . Properties . Description ) . to . equal ( 'test description' ) ;
234235 } ) ;
235236
236- it ( 'should respect name variable' , ( ) => {
237+ itParam ( 'should respect name variable' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
237238 serverlessStepFunctions . serverless . service . stepFunctions = {
238239 stateMachines : {
239240 first : {
240241 events : [
241242 {
242- cloudwatchEvent : {
243+ [ source ] : {
243244 event : {
244245 source : [ 'aws.ec2' ] ,
245246 'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -262,13 +263,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
262263 . Properties . Name ) . to . equal ( 'test-event-name' ) ;
263264 } ) ;
264265
265- it ( 'should respect eventBusName variable' , ( ) => {
266+ itParam ( 'should respect eventBusName variable' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
266267 serverlessStepFunctions . serverless . service . stepFunctions = {
267268 stateMachines : {
268269 first : {
269270 events : [
270271 {
271- cloudwatchEvent : {
272+ [ source ] : {
272273 event : {
273274 source : [ 'aws.ec2' ] ,
274275 'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -292,13 +293,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
292293 . Properties . EventBusName ) . to . equal ( 'custom-event-bus' ) ;
293294 } ) ;
294295
295- it ( 'should respect input variable as an object' , ( ) => {
296+ itParam ( 'should respect input variable as an object' , [ 'cloudwatchEvent' , 'eventBridge' ] , ( source ) => {
296297 serverlessStepFunctions . serverless . service . stepFunctions = {
297298 stateMachines : {
298299 first : {
299300 events : [
300301 {
301- cloudwatchEvent : {
302+ [ source ] : {
302303 event : {
303304 source : [ 'aws.ec2' ] ,
304305 'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -322,13 +323,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
322323 . Properties . Targets [ 0 ] . Input ) . to . equal ( '{"key":"value"}' ) ;
323324 } ) ;
324325
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 ) => {
326327 serverlessStepFunctions . serverless . service . stepFunctions = {
327328 stateMachines : {
328329 first : {
329330 events : [
330331 {
331- cloudwatchEvent : {
332+ [ source ] : {
332333 event : {
333334 source : [ 'aws.ec2' ] ,
334335 'detail-type' : [ 'EC2 Instance State-change Notification' ] ,
@@ -349,13 +350,13 @@ describe('awsCompileCloudWatchEventEvents', () => {
349350 expect ( ( ) => serverlessStepFunctions . compileCloudWatchEventEvents ( ) ) . to . throw ( Error ) ;
350351 } ) ;
351352
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 ) => {
353354 serverlessStepFunctions . serverless . service . stepFunctions = {
354355 stateMachines : {
355356 first : {
356357 events : [
357358 {
358- cloudwatchEvent : {
359+ [ source ] : {
359360 event : {
360361 source : [ 'aws.ec2' ] ,
361362 'detail-type' : [ 'EC2 Instance State-change Notification \n with newline' ] ,
@@ -381,7 +382,7 @@ describe('awsCompileCloudWatchEventEvents', () => {
381382 . FirstEventsRuleCloudWatchEvent1 . Properties . Targets [ 0 ] . Input ) . to . equal ( '{"key":"value"}' ) ;
382383 } ) ;
383384
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' , ( ) => {
385386 serverlessStepFunctions . serverless . service . stepFunctions = {
386387 stateMachines : {
387388 first : {
0 commit comments