@@ -116,6 +116,26 @@ describe('Engine: event', () => {
116116 engine . addFact ( 'age' , 21 )
117117 }
118118
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+
119139 context ( 'engine events: simple' , ( ) => {
120140 beforeEach ( ( ) => simpleSetup ( ) )
121141
@@ -635,4 +655,15 @@ describe('Engine: event', () => {
635655 expect ( JSON . stringify ( ruleResult ) ) . to . equal ( expected )
636656 } )
637657 } )
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+ } )
638669} )
0 commit comments