11var RuleEngine = require ( '../index' ) ;
2- var expect = require ( "chai" ) . expect ;
32describe ( "Rules" , function ( ) {
43 describe ( ".init()" , function ( ) {
54 it ( "should empty the existing rule array" , function ( ) {
@@ -13,7 +12,7 @@ describe("Rules", function() {
1312 } ] ;
1413 var R = new RuleEngine ( rules ) ;
1514 R . init ( ) ;
16- expect ( R . rules ) . to . eql ( [ ] ) ;
15+ expect ( R . rules ) . toEqual ( [ ] ) ;
1716 } ) ;
1817 } ) ;
1918 describe ( ".register()" , function ( ) {
@@ -27,7 +26,7 @@ describe("Rules", function() {
2726 }
2827 } ] ;
2928 var R = new RuleEngine ( rules ) ;
30- expect ( R . rules [ 0 ] . on ) . to . eql ( true ) ;
29+ expect ( R . rules [ 0 ] . on ) . toEqual ( true ) ;
3130 } ) ;
3231 it ( "Rule can be passed to register as both arrays and individual objects" , function ( ) {
3332 var rule = {
@@ -40,7 +39,7 @@ describe("Rules", function() {
4039 } ;
4140 var R1 = new RuleEngine ( rule ) ;
4241 var R2 = new RuleEngine ( [ rule ] ) ;
43- expect ( R1 . rules ) . to . eql ( R2 . rules ) ;
42+ expect ( R1 . rules ) . toEqual ( R2 . rules ) ;
4443 } ) ;
4544 it ( "Rules can be appended multiple times via register after creating rule engine instance" , function ( ) {
4645 var rules = [ {
@@ -62,9 +61,9 @@ describe("Rules", function() {
6261 var R2 = new RuleEngine ( rules [ 0 ] ) ;
6362 var R3 = new RuleEngine ( ) ;
6463 R2 . register ( rules [ 1 ] ) ;
65- expect ( R1 . rules ) . to . eql ( R2 . rules ) ;
64+ expect ( R1 . rules ) . toEqual ( R2 . rules ) ;
6665 R3 . register ( rules ) ;
67- expect ( R1 . rules ) . to . eql ( R3 . rules ) ;
66+ expect ( R1 . rules ) . toEqual ( R3 . rules ) ;
6867 } ) ;
6968 } ) ;
7069 describe ( ".sync()" , function ( ) {
@@ -90,7 +89,7 @@ describe("Rules", function() {
9089 } ] ;
9190 var R = new RuleEngine ( ) ;
9291 R . register ( rules ) ;
93- expect ( R . activeRules ) . not . to . eql ( R . rules ) ;
92+ expect ( R . activeRules ) . not . toEqual ( R . rules ) ;
9493 } ) ;
9594 it ( "should sort the rules accroding to priority, if priority is present" , function ( ) {
9695 var rules = [ {
@@ -123,7 +122,7 @@ describe("Rules", function() {
123122 } ] ;
124123 var R = new RuleEngine ( ) ;
125124 R . register ( rules ) ;
126- expect ( R . activeRules [ 2 ] . index ) . to . eql ( 2 ) ;
125+ expect ( R . activeRules [ 2 ] . index ) . toEqual ( 2 ) ;
127126 } ) ;
128127 } ) ;
129128 describe ( ".exec()" , function ( ) {
@@ -141,7 +140,7 @@ describe("Rules", function() {
141140 R . execute ( {
142141 "transactionTotal" : 200
143142 } , function ( result ) {
144- expect ( result . result ) . to . eql ( false ) ;
143+ expect ( result . result ) . toEqual ( false ) ;
145144 } ) ;
146145 } ) ;
147146 it ( "should chain rules and find result with next()" , function ( ) {
@@ -168,7 +167,7 @@ describe("Rules", function() {
168167 "transactionTotal" : 200 ,
169168 "card" : "VISA"
170169 } , function ( result ) {
171- expect ( result . result ) . to . eql ( "Custom Result" ) ;
170+ expect ( result . result ) . toEqual ( "Custom Result" ) ;
172171 } ) ;
173172 } ) ;
174173 it ( "should provide access to rule definition properties via rule()" , function ( ) {
@@ -189,8 +188,8 @@ describe("Rules", function() {
189188 R . execute ( {
190189 "input" : true
191190 } , function ( result ) {
192- expect ( result . ruleName ) . to . eql ( rule . name ) ;
193- expect ( result . ruleID ) . to . eql ( rule . id ) ;
191+ expect ( result . ruleName ) . toEqual ( rule . name ) ;
192+ expect ( result . ruleID ) . toEqual ( rule . id ) ;
194193 } ) ;
195194 } ) ;
196195 it ( "should include the matched rule path" , function ( ) {
@@ -246,7 +245,7 @@ describe("Rules", function() {
246245 "x" : true ,
247246 "y" : false
248247 } , function ( result ) {
249- expect ( result . matchPath ) . to . eql ( [ rules [ 0 ] . name , rules [ 2 ] . id , lastMatch ] ) ;
248+ expect ( result . matchPath ) . toEqual ( [ rules [ 0 ] . name , rules [ 2 ] . id , lastMatch ] ) ;
250249 } ) ;
251250 } ) ;
252251
@@ -264,7 +263,7 @@ describe("Rules", function() {
264263 R . execute ( {
265264 "transactionTotal" : 200
266265 } , function ( result ) {
267- expect ( result . result ) . to . eql ( false ) ;
266+ expect ( result . result ) . toEqual ( false ) ;
268267 } ) ;
269268 } ) ;
270269
@@ -284,7 +283,7 @@ describe("Rules", function() {
284283 R . execute ( {
285284 "transactionTotal" : 200
286285 } , function ( result ) {
287- expect ( result . result ) . to . eql ( false ) ;
286+ expect ( result . result ) . toEqual ( false ) ;
288287 } ) ;
289288 } ) ;
290289
@@ -311,21 +310,21 @@ describe("Rules", function() {
311310 it ( "find selector function for rules should exact number of matches" , function ( ) {
312311 expect ( R . findRules ( {
313312 "id" : "one"
314- } ) . length ) . to . eql ( 1 ) ;
313+ } ) . length ) . toEqual ( 1 ) ;
315314 } ) ;
316315 it ( "find selector function for rules should give the correct match as result" , function ( ) {
317316 expect ( R . findRules ( {
318317 "id" : "one"
319- } ) [ 0 ] . id ) . to . eql ( "one" ) ;
318+ } ) [ 0 ] . id ) . toEqual ( "one" ) ;
320319 } ) ;
321320 it ( "find selector function should filter off undefined entries in the query if any" , function ( ) {
322321 expect ( R . findRules ( {
323322 "id" : "one" ,
324323 "myMistake" : undefined
325- } ) [ 0 ] . id ) . to . eql ( "one" ) ;
324+ } ) [ 0 ] . id ) . toEqual ( "one" ) ;
326325 } ) ;
327326 it ( "find without condition works fine" , function ( ) {
328- expect ( R . findRules ( ) . length ) . to . eql ( 2 ) ;
327+ expect ( R . findRules ( ) . length ) . toEqual ( 2 ) ;
329328 } ) ;
330329 } ) ;
331330 describe ( ".turn()" , function ( ) {
@@ -354,15 +353,15 @@ describe("Rules", function() {
354353 } ) ;
355354 expect ( R . findRules ( {
356355 "id" : "one"
357- } ) [ 0 ] . on ) . to . eql ( false ) ;
356+ } ) [ 0 ] . on ) . toEqual ( false ) ;
358357 } ) ;
359358 it ( "checking whether turn on rules work as expected" , function ( ) {
360359 R . turn ( "ON" , {
361360 "id" : "two"
362361 } ) ;
363362 expect ( R . findRules ( {
364363 "id" : "two"
365- } ) [ 0 ] . on ) . to . eql ( true ) ;
364+ } ) [ 0 ] . on ) . toEqual ( true ) ;
366365 } ) ;
367366 } ) ;
368367 describe ( ".prioritize()" , function ( ) {
@@ -401,13 +400,13 @@ describe("Rules", function() {
401400 } ) ;
402401 expect ( R . findRules ( {
403402 "id" : "one"
404- } ) [ 0 ] . priority ) . to . eql ( 10 ) ;
403+ } ) [ 0 ] . priority ) . toEqual ( 10 ) ;
405404 } ) ;
406405 it ( "checking whether rules reorder after prioritize" , function ( ) {
407406 R . prioritize ( 10 , {
408407 "id" : "one"
409408 } ) ;
410- expect ( R . activeRules [ 0 ] . id ) . to . eql ( "one" ) ;
409+ expect ( R . activeRules [ 0 ] . id ) . toEqual ( "one" ) ;
411410 } ) ;
412411 } ) ;
413412 describe ( "ignoreFactChanges" , function ( ) {
@@ -432,7 +431,7 @@ describe("Rules", function() {
432431 var R = new RuleEngine ( rules , { ignoreFactChanges : true } ) ;
433432
434433 R . execute ( fact , function ( result ) {
435- expect ( result . errors ) . to . have . length ( 1 ) ;
434+ expect ( result . errors ) . toHaveLength ( 1 ) ;
436435 done ( ) ;
437436 } ) ;
438437 } ) ;
@@ -444,11 +443,9 @@ describe("Rules", function() {
444443 "priority" : 4 ,
445444 "on" : true ,
446445 "condition" : function ( R ) {
447- console . log ( `Executing rule 1 on ${ this . name } ` ) ;
448446 R . when ( this . userCredibility && this . userCredibility > 5 ) ;
449447 } ,
450448 "consequence" : function ( R ) {
451- console . log ( `Rule 1 matched for ${ this . name } user credibility is more, then avoid further check. Accepting payment.` ) ;
452449 this . result = true ;
453450 R . stop ( ) ;
454451 }
@@ -457,11 +454,9 @@ describe("Rules", function() {
457454 "name" : "block guest payment above 10000" ,
458455 "priority" : 3 ,
459456 "condition" : function ( R ) {
460- console . log ( `Executing rule 2 on ${ this . name } ` ) ;
461457 R . when ( this . customerType && this . transactionTotal > 10000 && this . customerType == "guest" ) ;
462458 } ,
463459 "consequence" : function ( R ) {
464- console . log ( `Rule 2 matched for ${ this . name } reject if above 10000 and customer type is guest. Rejecting payment.` ) ;
465460 this . result = false ;
466461 R . stop ( ) ;
467462 }
@@ -470,12 +465,9 @@ describe("Rules", function() {
470465 "name" : "is customer guest?" ,
471466 "priority" : 2 ,
472467 "condition" : function ( R ) {
473- console . log ( `Executing rule 3 on ${ this . name } ` ) ;
474468 R . when ( ! this . userLoggedIn ) ;
475469 } ,
476470 "consequence" : function ( R ) {
477- console . log ( `Rule 3 matched for ${ this . name } support rule written for blocking payment above 10000 from guests.` ) ;
478- console . log ( "Process left to chain with rule 2." ) ;
479471 this . customerType = "guest" ;
480472 // the fact has been altered above, so all rules will run again since ignoreFactChanges is not set.
481473 R . next ( ) ;
@@ -485,11 +477,9 @@ describe("Rules", function() {
485477 "name" : "block Cashcard Payment" ,
486478 "priority" : 1 ,
487479 "condition" : function ( R ) {
488- console . log ( `Executing rule 4 on ${ this . name } ` ) ;
489480 R . when ( this . cardType == "Cash Card" ) ;
490481 } ,
491482 "consequence" : function ( R ) {
492- console . log ( `Rule 4 matched for ${ this . name } reject the payment if cash card. Rejecting payment.` ) ;
493483 this . result = false ;
494484 R . stop ( ) ;
495485 }
@@ -518,7 +508,7 @@ describe("Rules", function() {
518508 var isStraightFactFast = false ;
519509
520510 R . execute ( chainedFact , function ( result ) {
521- expect ( isStraightFactFast ) . eql ( true ) ;
511+ expect ( isStraightFactFast ) . toBe ( true ) ;
522512 done ( ) ;
523513 } ) ;
524514
@@ -528,4 +518,4 @@ describe("Rules", function() {
528518
529519 } ) ;
530520 } ) ;
531- } ) ;
521+ } ) ;
0 commit comments