@@ -483,4 +483,128 @@ describe('#compileStateMachines', () => {
483
483
} ;
484
484
expect ( ( ) => serverlessStepFunctions . compileStateMachines ( ) ) . to . throw ( Error ) ;
485
485
} ) ;
486
+
487
+ it ( 'should add tags' , ( ) => {
488
+ serverless . service . stepFunctions = {
489
+ stateMachines : {
490
+ myStateMachine1 : {
491
+ definition : 'definition1' ,
492
+ name : 'stateMachineBeta1' ,
493
+ tags : {
494
+ team : 'core' ,
495
+ score : 42 ,
496
+ } ,
497
+ } ,
498
+ myStateMachine2 : {
499
+ definition : 'definition2' ,
500
+ name : 'stateMachineBeta2' ,
501
+ tags : {
502
+ team : 'core' ,
503
+ score : 42 ,
504
+ } ,
505
+ } ,
506
+ } ,
507
+ } ;
508
+
509
+ serverlessStepFunctions . compileStateMachines ( ) ;
510
+ const stateMachineBeta1 = serverlessStepFunctions . serverless . service
511
+ . provider . compiledCloudFormationTemplate . Resources
512
+ . StateMachineBeta1 ;
513
+ const stateMachineBeta2 = serverlessStepFunctions . serverless . service
514
+ . provider . compiledCloudFormationTemplate . Resources
515
+ . StateMachineBeta2 ;
516
+ expect ( stateMachineBeta1 . Properties . Tags ) . to . have . lengthOf ( 2 ) ;
517
+ expect ( stateMachineBeta2 . Properties . Tags ) . to . have . lengthOf ( 2 ) ;
518
+ expect ( stateMachineBeta1 . Properties . Tags )
519
+ . to . deep . eq ( [ { Key : 'team' , Value : 'core' } , { Key : 'score' , Value : '42' } ] ) ;
520
+ expect ( stateMachineBeta2 . Properties . Tags )
521
+ . to . deep . eq ( [ { Key : 'team' , Value : 'core' } , { Key : 'score' , Value : '42' } ] ) ;
522
+ } ) ;
523
+
524
+ it ( 'should add global tags' , ( ) => {
525
+ serverless . service . provider . tags = {
526
+ team : 'core' ,
527
+ score : 42 ,
528
+ } ;
529
+
530
+ serverless . service . stepFunctions = {
531
+ stateMachines : {
532
+ myStateMachine1 : {
533
+ definition : 'definition1' ,
534
+ name : 'stateMachineBeta1' ,
535
+ } ,
536
+ myStateMachine2 : {
537
+ definition : 'definition2' ,
538
+ name : 'stateMachineBeta2' ,
539
+ } ,
540
+ } ,
541
+ } ;
542
+
543
+ serverlessStepFunctions . compileStateMachines ( ) ;
544
+ const stateMachineBeta1 = serverlessStepFunctions . serverless . service
545
+ . provider . compiledCloudFormationTemplate . Resources
546
+ . StateMachineBeta1 ;
547
+ const stateMachineBeta2 = serverlessStepFunctions . serverless . service
548
+ . provider . compiledCloudFormationTemplate . Resources
549
+ . StateMachineBeta2 ;
550
+ expect ( stateMachineBeta1 . Properties . Tags ) . to . have . lengthOf ( 2 ) ;
551
+ expect ( stateMachineBeta2 . Properties . Tags ) . to . have . lengthOf ( 2 ) ;
552
+ expect ( stateMachineBeta1 . Properties . Tags )
553
+ . to . deep . eq ( [ { Key : 'team' , Value : 'core' } , { Key : 'score' , Value : '42' } ] ) ;
554
+ expect ( stateMachineBeta2 . Properties . Tags )
555
+ . to . deep . eq ( [ { Key : 'team' , Value : 'core' } , { Key : 'score' , Value : '42' } ] ) ;
556
+ } ) ;
557
+
558
+ it ( 'should merge global and state machine tags' , ( ) => {
559
+ serverless . service . provider . tags = {
560
+ team : 'core' ,
561
+ } ;
562
+
563
+ serverless . service . stepFunctions = {
564
+ stateMachines : {
565
+ myStateMachine1 : {
566
+ definition : 'definition1' ,
567
+ name : 'stateMachineBeta1' ,
568
+ tags : {
569
+ score : 42 ,
570
+ } ,
571
+ } ,
572
+ myStateMachine2 : {
573
+ definition : 'definition2' ,
574
+ name : 'stateMachineBeta2' ,
575
+ tags : {
576
+ score : 42 ,
577
+ } ,
578
+ } ,
579
+ } ,
580
+ } ;
581
+
582
+ serverlessStepFunctions . compileStateMachines ( ) ;
583
+ const stateMachineBeta1 = serverlessStepFunctions . serverless . service
584
+ . provider . compiledCloudFormationTemplate . Resources
585
+ . StateMachineBeta1 ;
586
+ const stateMachineBeta2 = serverlessStepFunctions . serverless . service
587
+ . provider . compiledCloudFormationTemplate . Resources
588
+ . StateMachineBeta2 ;
589
+ expect ( stateMachineBeta1 . Properties . Tags ) . to . have . lengthOf ( 2 ) ;
590
+ expect ( stateMachineBeta2 . Properties . Tags ) . to . have . lengthOf ( 2 ) ;
591
+ expect ( stateMachineBeta1 . Properties . Tags )
592
+ . to . deep . eq ( [ { Key : 'team' , Value : 'core' } , { Key : 'score' , Value : '42' } ] ) ;
593
+ expect ( stateMachineBeta2 . Properties . Tags )
594
+ . to . deep . eq ( [ { Key : 'team' , Value : 'core' } , { Key : 'score' , Value : '42' } ] ) ;
595
+ } ) ;
596
+
597
+ it ( 'should throw error when tags property contains malformed tags' , ( ) => {
598
+ serverless . service . stepFunctions = {
599
+ stateMachines : {
600
+ myStateMachine1 : {
601
+ definition : 'definition1' ,
602
+ name : 'stateMachineBeta1' ,
603
+ tags : [ 'team:core' ] ,
604
+ } ,
605
+ } ,
606
+ } ;
607
+
608
+ expect ( ( ) => serverlessStepFunctions . compileStateMachines ( ) ) . to . throw ( Error ) ;
609
+ } ) ;
486
610
} ) ;
0 commit comments