1- import engineFactory from '../src/index '
2- import { ruleFactory } from './support/rule-factory'
3- import Engine from '../src/engine'
1+ import { engineFactory } from '../src/truegin '
2+ import { ruleFactory } from './support/rule-factory'
3+ import { Engine } from '../src/engine'
44import { ConditionConstructorOptions } from '../src/condition'
55
66const CHILD = 14
@@ -25,14 +25,14 @@ async function eligibilityData (params: any) {
2525 zip : '80403' ,
2626 'dot.property' : 'dot-property-value' ,
2727 occupantHistory : [
28- { name : 'Joe' , year : 2011 } ,
29- { name : 'Jane' , year : 2013 } ,
28+ { name : 'Joe' , year : 2011 } ,
29+ { name : 'Jane' , year : 2013 } ,
3030 ] ,
3131 }
3232 if ( params . eligibilityId === 1 ) {
33- return { age : CHILD , address }
33+ return { age : CHILD , address}
3434 }
35- return { age : ADULT , address }
35+ return { age : ADULT , address}
3636}
3737
3838describe ( 'Engine: fact evaluation' , ( ) => {
@@ -43,6 +43,7 @@ describe('Engine: fact evaluation', () => {
4343 demographic : 'under50' ,
4444 } ,
4545 }
46+
4647 function baseConditions ( ) : any {
4748 return {
4849 any : [ {
@@ -56,6 +57,7 @@ describe('Engine: fact evaluation', () => {
5657 } ] ,
5758 }
5859 }
60+
5961 let successSpy = jest . fn ( )
6062 let failureSpy = jest . fn ( )
6163 beforeEach ( ( ) => {
@@ -65,7 +67,7 @@ describe('Engine: fact evaluation', () => {
6567
6668 function setup ( conditions = baseConditions ( ) , engineOptions = { } ) {
6769 engine = engineFactory ( [ ] , engineOptions )
68- let rule = ruleFactory ( { conditions, event } )
70+ let rule = ruleFactory ( { conditions, event} )
6971 engine . addRule ( rule )
7072 engine . addFact ( 'eligibilityField' , eligibilityField )
7173 engine . addFact ( 'eligibilityData' , eligibilityData )
@@ -87,36 +89,36 @@ describe('Engine: fact evaluation', () => {
8789 } )
8890
8991 describe (
90- 'treats undefined facts as falsey when allowUndefinedFacts is set' ,
91- ( ) => {
92- test ( 'emits "success" when the condition succeeds' , async ( ) => {
93- let conditions = Object . assign ( { } , baseConditions ( ) )
94- conditions . any . push ( {
95- fact : 'undefined-fact' ,
96- operator : 'equal' ,
97- value : true ,
98- } )
99- setup ( conditions , { allowUndefinedFacts : true } )
100- await engine . run ( )
101- expect ( successSpy . mock . calls . length )
102- expect ( ! successSpy . mock . calls . length )
103- } )
92+ 'treats undefined facts as falsey when allowUndefinedFacts is set' ,
93+ ( ) => {
94+ test ( 'emits "success" when the condition succeeds' , async ( ) => {
95+ let conditions = Object . assign ( { } , baseConditions ( ) )
96+ conditions . any . push ( {
97+ fact : 'undefined-fact' ,
98+ operator : 'equal' ,
99+ value : true ,
100+ } )
101+ setup ( conditions , { allowUndefinedFacts : true } )
102+ await engine . run ( )
103+ expect ( successSpy . mock . calls . length )
104+ expect ( ! successSpy . mock . calls . length )
105+ } )
104106
105- test ( 'emits "failure" when the condition fails' , async ( ) => {
106- let conditions = Object . assign ( { } , baseConditions ( ) )
107- conditions . any . push ( {
108- fact : 'undefined-fact' ,
109- operator : 'equal' ,
110- value : true ,
111- } )
112- conditions . any [ 0 ] . params . eligibilityId = 2
113- setup ( conditions , { allowUndefinedFacts : true } )
114- await engine . run ( )
115- expect ( ! successSpy . mock . calls . length )
116- expect ( failureSpy . mock . calls . length )
117- } )
118- } ,
119- )
107+ test ( 'emits "failure" when the condition fails' , async ( ) => {
108+ let conditions = Object . assign ( { } , baseConditions ( ) )
109+ conditions . any . push ( {
110+ fact : 'undefined-fact' ,
111+ operator : 'equal' ,
112+ value : true ,
113+ } )
114+ conditions . any [ 0 ] . params . eligibilityId = 2
115+ setup ( conditions , { allowUndefinedFacts : true } )
116+ await engine . run ( )
117+ expect ( ! successSpy . mock . calls . length )
118+ expect ( failureSpy . mock . calls . length )
119+ } )
120+ } ,
121+ )
120122 } )
121123 } )
122124
@@ -150,6 +152,7 @@ describe('Engine: fact evaluation', () => {
150152 } ] ,
151153 }
152154 }
155+
153156 test ( 'emits when the condition is met' , async ( ) => {
154157 setup ( conditions ( ) )
155158 await engine . run ( )
@@ -166,17 +169,17 @@ describe('Engine: fact evaluation', () => {
166169
167170 describe ( 'complex paths' , ( ) => {
168171 test (
169- 'correctly interprets "path" when dynamic facts return objects' ,
170- async ( ) => {
171- let complexCondition = conditions ( )
172- ; ( complexCondition as any ) . any [ 0 ] . path = '.address.occupantHistory[0].year'
173- ; ( complexCondition as any ) . any [ 0 ] . value = 2011
174- ; ( complexCondition as any ) . any [ 0 ] . operator = 'equal'
175- setup ( complexCondition )
176- await engine . run ( )
177- expect ( successSpy . mock . calls [ 0 ] [ 0 ] ) . toEqual ( event )
178- } ,
179- )
172+ 'correctly interprets "path" when dynamic facts return objects' ,
173+ async ( ) => {
174+ let complexCondition = conditions ( )
175+ ; ( complexCondition as any ) . any [ 0 ] . path = '.address.occupantHistory[0].year'
176+ ; ( complexCondition as any ) . any [ 0 ] . value = 2011
177+ ; ( complexCondition as any ) . any [ 0 ] . operator = 'equal'
178+ setup ( complexCondition )
179+ await engine . run ( )
180+ expect ( successSpy . mock . calls [ 0 ] [ 0 ] ) . toEqual ( event )
181+ } ,
182+ )
180183
181184 test (
182185 'correctly interprets "path" when target object properties have dots' ,
@@ -192,7 +195,7 @@ describe('Engine: fact evaluation', () => {
192195 )
193196
194197 test ( 'correctly interprets "path" with runtime fact objects' , async ( ) => {
195- let fact = { x : { y : 1 } , a : 2 }
198+ let fact = { x : { y : 1 } , a : 2 }
196199 let conditions = {
197200 all : [ {
198201 fact : 'x' ,
@@ -206,7 +209,7 @@ describe('Engine: fact evaluation', () => {
206209 }
207210
208211 engine = engineFactory ( [ ] )
209- let rule = ruleFactory ( { conditions, event } )
212+ let rule = ruleFactory ( { conditions, event} )
210213 engine . addRule ( rule )
211214 engine . on ( 'success' , successSpy )
212215 engine . on ( 'failure' , failureSpy )
0 commit comments