@@ -25,15 +25,19 @@ describe('Engine: event', () => {
25
25
*/
26
26
function simpleSetup ( ) {
27
27
const conditions = {
28
- any : [ {
29
- fact : 'age' ,
30
- operator : 'greaterThanInclusive' ,
31
- value : 21
32
- } , {
33
- fact : 'qualified' ,
34
- operator : 'equal' ,
35
- value : true
36
- } ]
28
+ any : [
29
+ {
30
+ name : 'over 21' ,
31
+ fact : 'age' ,
32
+ operator : 'greaterThanInclusive' ,
33
+ value : 21
34
+ } ,
35
+ {
36
+ fact : 'qualified' ,
37
+ operator : 'equal' ,
38
+ value : true
39
+ }
40
+ ]
37
41
}
38
42
engine = engineFactory ( )
39
43
const ruleOptions = { conditions, event, priority : 100 }
@@ -50,25 +54,32 @@ describe('Engine: event', () => {
50
54
*/
51
55
function advancedSetup ( ) {
52
56
const conditions = {
53
- any : [ {
54
- fact : 'age' ,
55
- operator : 'greaterThanInclusive' ,
56
- value : 21
57
- } , {
58
- fact : 'qualified' ,
59
- operator : 'equal' ,
60
- value : true
61
- } , {
62
- all : [ {
63
- fact : 'zipCode' ,
64
- operator : 'in' ,
65
- value : [ 80211 , 80403 ]
66
- } , {
67
- fact : 'gender' ,
68
- operator : 'notEqual' ,
69
- value : 'female'
70
- } ]
71
- } ]
57
+ any : [
58
+ {
59
+ fact : 'age' ,
60
+ operator : 'greaterThanInclusive' ,
61
+ value : 21
62
+ } ,
63
+ {
64
+ fact : 'qualified' ,
65
+ operator : 'equal' ,
66
+ value : true
67
+ } ,
68
+ {
69
+ all : [
70
+ {
71
+ fact : 'zipCode' ,
72
+ operator : 'in' ,
73
+ value : [ 80211 , 80403 ]
74
+ } ,
75
+ {
76
+ fact : 'gender' ,
77
+ operator : 'notEqual' ,
78
+ value : 'female'
79
+ }
80
+ ]
81
+ }
82
+ ]
72
83
}
73
84
engine = engineFactory ( )
74
85
const ruleOptions = { conditions, event, priority : 100 }
@@ -91,6 +102,7 @@ describe('Engine: event', () => {
91
102
expect ( ruleResult . result ) . to . be . true ( )
92
103
expect ( ruleResult . conditions . any [ 0 ] . result ) . to . be . true ( )
93
104
expect ( ruleResult . conditions . any [ 0 ] . factResult ) . to . equal ( 21 )
105
+ expect ( ruleResult . conditions . any [ 0 ] . name ) . to . equal ( 'over 21' )
94
106
expect ( ruleResult . conditions . any [ 1 ] . result ) . to . be . false ( )
95
107
expect ( ruleResult . conditions . any [ 1 ] . factResult ) . to . equal ( false )
96
108
}
@@ -177,11 +189,13 @@ describe('Engine: event', () => {
177
189
params : drinkOrderParams
178
190
}
179
191
const drinkOrderConditions = {
180
- any : [ {
181
- fact : 'canOrderDrinks' ,
182
- operator : 'equal' ,
183
- value : true
184
- } ]
192
+ any : [
193
+ {
194
+ fact : 'canOrderDrinks' ,
195
+ operator : 'equal' ,
196
+ value : true
197
+ }
198
+ ]
185
199
}
186
200
const drinkOrderRule = factories . rule ( {
187
201
conditions : drinkOrderConditions ,
@@ -193,7 +207,10 @@ describe('Engine: event', () => {
193
207
engine . on ( 'success' , function ( event , almanac , ruleResult ) {
194
208
switch ( event . type ) {
195
209
case 'setDrinkingFlag' :
196
- almanac . addRuntimeFact ( 'canOrderDrinks' , event . params . canOrderDrinks )
210
+ almanac . addRuntimeFact (
211
+ 'canOrderDrinks' ,
212
+ event . params . canOrderDrinks
213
+ )
197
214
break
198
215
case 'offerDrink' :
199
216
expect ( event . params ) . to . eql ( drinkOrderParams )
@@ -257,7 +274,9 @@ describe('Engine: event', () => {
257
274
expect ( ruleResult . conditions . any [ 1 ] . factResult ) . to . equal ( false )
258
275
expect ( ruleResult . conditions . any [ 2 ] . result ) . to . be . false ( )
259
276
expect ( ruleResult . conditions . any [ 2 ] . all [ 0 ] . result ) . to . be . false ( )
260
- expect ( ruleResult . conditions . any [ 2 ] . all [ 0 ] . factResult ) . to . equal ( ZIP_CODE )
277
+ expect ( ruleResult . conditions . any [ 2 ] . all [ 0 ] . factResult ) . to . equal (
278
+ ZIP_CODE
279
+ )
261
280
expect ( ruleResult . conditions . any [ 2 ] . all [ 1 ] . result ) . to . be . false ( )
262
281
expect ( ruleResult . conditions . any [ 2 ] . all [ 1 ] . factResult ) . to . equal ( GENDER )
263
282
}
@@ -375,7 +394,8 @@ describe('Engine: event', () => {
375
394
rule . on ( 'success' , successSpy )
376
395
await engine . run ( )
377
396
const ruleResult = successSpy . getCall ( 0 ) . args [ 2 ]
378
- const expected = '{"conditions":{"priority":1,"any":[{"operator":"greaterThanInclusive","value":21,"fact":"age","factResult":21,"result":true},{"operator":"equal","value":true,"fact":"qualified","factResult":false,"result":false}]},"event":{"type":"setDrinkingFlag","params":{"canOrderDrinks":true}},"priority":100,"result":true}'
397
+ const expected =
398
+ '{"conditions":{"priority":1,"any":[{"name":"over 21","operator":"greaterThanInclusive","value":21,"fact":"age","factResult":21,"result":true},{"operator":"equal","value":true,"fact":"qualified","factResult":false,"result":false}]},"event":{"type":"setDrinkingFlag","params":{"canOrderDrinks":true}},"priority":100,"result":true}'
379
399
expect ( JSON . stringify ( ruleResult ) ) . to . equal ( expected )
380
400
} )
381
401
} )
0 commit comments