@@ -116,6 +116,26 @@ describe('Engine: event', () => {
116
116
engine . addFact ( 'age' , 21 )
117
117
}
118
118
119
+ function setupWithUndefinedCondition ( ) {
120
+ const conditionName = 'conditionThatIsNotDefined'
121
+ const conditions = {
122
+ any : [
123
+ { condition : conditionName , name : 'nameOfTheUndefinedConditionReference' } ,
124
+ {
125
+ name : 'over 21' ,
126
+ fact : 'age' ,
127
+ operator : 'greaterThanInclusive' ,
128
+ value : 21
129
+ }
130
+ ]
131
+ }
132
+ engine = engineFactory ( [ ] , { allowUndefinedConditions : true } )
133
+ const ruleOptions = { conditions, event : awesomeEvent , priority : 100 }
134
+ const rule = factories . rule ( ruleOptions )
135
+ engine . addRule ( rule )
136
+ engine . addFact ( 'age' , 21 )
137
+ }
138
+
119
139
context ( 'engine events: simple' , ( ) => {
120
140
beforeEach ( ( ) => simpleSetup ( ) )
121
141
@@ -635,4 +655,15 @@ describe('Engine: event', () => {
635
655
expect ( JSON . stringify ( ruleResult ) ) . to . equal ( expected )
636
656
} )
637
657
} )
658
+
659
+ context ( 'rule events: json serializing with condition reference that is undefined' , ( ) => {
660
+ beforeEach ( ( ) => setupWithUndefinedCondition ( ) )
661
+ it ( 'serializes properties' , async ( ) => {
662
+ const { results : [ ruleResult ] } = await engine . run ( )
663
+ const { conditions : { any : [ conditionReference ] } } = ruleResult
664
+ expect ( conditionReference . result ) . to . equal ( false )
665
+ const expected = '{"conditions":{"priority":1,"any":[{"name":"nameOfTheUndefinedConditionReference","condition":"conditionThatIsNotDefined"},{"name":"over 21","operator":"greaterThanInclusive","value":21,"fact":"age","factResult":21,"result":true}]},"event":{"type":"awesome"},"priority":100,"result":true}'
666
+ expect ( JSON . stringify ( ruleResult ) ) . to . equal ( expected )
667
+ } )
668
+ } )
638
669
} )
0 commit comments