@@ -498,14 +498,30 @@ test('cannot create transitions that transit to duprecated target state', () =>
498
498
} ) ;
499
499
500
500
describe ( 'Expression' , ( ) => {
501
- test ( 'currentInput' , ( ) => {
501
+ const E = iotevents . Expression ;
502
+ test . each ( [
503
+ [ 'currentInput' , ( testInput : iotevents . IInput ) => E . currentInput ( testInput ) , 'currentInput("test-input")' ] ,
504
+ [ 'inputAttribute' , ( testInput : iotevents . IInput ) => E . inputAttribute ( testInput , 'json.path' ) , '$input.test-input.json.path' ] ,
505
+ [ 'eq' , ( ) => E . eq ( E . fromString ( '"aaa"' ) , E . fromString ( '"bbb"' ) ) , '"aaa" == "bbb"' ] ,
506
+ [ 'neq' , ( ) => E . neq ( E . fromString ( '"aaa"' ) , E . fromString ( '"bbb"' ) ) , '"aaa" != "bbb"' ] ,
507
+ [ 'lt' , ( ) => E . lt ( E . fromString ( '5' ) , E . fromString ( '2' ) ) , '5 < 2' ] ,
508
+ [ 'lte' , ( ) => E . lte ( E . fromString ( '5' ) , E . fromString ( '2' ) ) , '5 <= 2' ] ,
509
+ [ 'gt' , ( ) => E . gt ( E . fromString ( '5' ) , E . fromString ( '2' ) ) , '5 > 2' ] ,
510
+ [ 'gte' , ( ) => E . gte ( E . fromString ( '5' ) , E . fromString ( '2' ) ) , '5 >= 2' ] ,
511
+ [ 'and' , ( ) => E . and ( E . fromString ( 'true' ) , E . fromString ( 'false' ) ) , 'true && false' ] ,
512
+ [ 'or' , ( ) => E . or ( E . fromString ( 'true' ) , E . fromString ( 'false' ) ) , 'true || false' ] ,
513
+ [ 'operator priority' , ( ) => E . and (
514
+ E . and ( E . fromString ( 'false' ) , E . fromString ( 'false' ) ) ,
515
+ E . or ( E . fromString ( 'true' ) , E . fromString ( 'true' ) ) ,
516
+ ) , 'false && false && (true || true)' ] ,
517
+ ] ) ( '%s' , ( _ , getExpression , expectedCondition ) => {
502
518
// WHEN
503
519
new iotevents . DetectorModel ( stack , 'MyDetectorModel' , {
504
520
initialState : new iotevents . State ( {
505
521
stateName : 'test-state' ,
506
522
onEnter : [ {
507
523
eventName : 'test-eventName' ,
508
- condition : iotevents . Expression . currentInput ( input ) ,
524
+ condition : getExpression ( input ) ,
509
525
} ] ,
510
526
} ) ,
511
527
} ) ;
@@ -517,97 +533,7 @@ describe('Expression', () => {
517
533
Match . objectLike ( {
518
534
OnEnter : {
519
535
Events : [ Match . objectLike ( {
520
- Condition : 'currentInput("test-input")' ,
521
- } ) ] ,
522
- } ,
523
- } ) ,
524
- ] ,
525
- } ,
526
- } ) ;
527
- } ) ;
528
-
529
- test ( 'inputAttribute' , ( ) => {
530
- // WHEN
531
- new iotevents . DetectorModel ( stack , 'MyDetectorModel' , {
532
- initialState : new iotevents . State ( {
533
- stateName : 'test-state' ,
534
- onEnter : [ {
535
- eventName : 'test-eventName' ,
536
- condition : iotevents . Expression . inputAttribute ( input , 'json.path' ) ,
537
- } ] ,
538
- } ) ,
539
- } ) ;
540
-
541
- // THEN
542
- Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::IoTEvents::DetectorModel' , {
543
- DetectorModelDefinition : {
544
- States : [
545
- Match . objectLike ( {
546
- OnEnter : {
547
- Events : [ Match . objectLike ( {
548
- Condition : '$input.test-input.json.path' ,
549
- } ) ] ,
550
- } ,
551
- } ) ,
552
- ] ,
553
- } ,
554
- } ) ;
555
- } ) ;
556
-
557
- test ( 'eq' , ( ) => {
558
- // WHEN
559
- new iotevents . DetectorModel ( stack , 'MyDetectorModel' , {
560
- initialState : new iotevents . State ( {
561
- stateName : 'test-state' ,
562
- onEnter : [ {
563
- eventName : 'test-eventName' ,
564
- condition : iotevents . Expression . eq (
565
- iotevents . Expression . fromString ( '"aaa"' ) ,
566
- iotevents . Expression . fromString ( '"bbb"' ) ,
567
- ) ,
568
- } ] ,
569
- } ) ,
570
- } ) ;
571
-
572
- // THEN
573
- Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::IoTEvents::DetectorModel' , {
574
- DetectorModelDefinition : {
575
- States : [
576
- Match . objectLike ( {
577
- OnEnter : {
578
- Events : [ Match . objectLike ( {
579
- Condition : '"aaa" == "bbb"' ,
580
- } ) ] ,
581
- } ,
582
- } ) ,
583
- ] ,
584
- } ,
585
- } ) ;
586
- } ) ;
587
-
588
- test ( 'eq' , ( ) => {
589
- // WHEN
590
- new iotevents . DetectorModel ( stack , 'MyDetectorModel' , {
591
- initialState : new iotevents . State ( {
592
- stateName : 'test-state' ,
593
- onEnter : [ {
594
- eventName : 'test-eventName' ,
595
- condition : iotevents . Expression . and (
596
- iotevents . Expression . fromString ( 'true' ) ,
597
- iotevents . Expression . fromString ( 'false' ) ,
598
- ) ,
599
- } ] ,
600
- } ) ,
601
- } ) ;
602
-
603
- // THEN
604
- Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::IoTEvents::DetectorModel' , {
605
- DetectorModelDefinition : {
606
- States : [
607
- Match . objectLike ( {
608
- OnEnter : {
609
- Events : [ Match . objectLike ( {
610
- Condition : 'true && false' ,
536
+ Condition : expectedCondition ,
611
537
} ) ] ,
612
538
} ,
613
539
} ) ,
0 commit comments