@@ -406,6 +406,129 @@ public function ruleIn(ApiTester $I)
406406 }
407407 }
408408
409+ public function ruleEqual (ApiTester $ I )
410+ {
411+ $ I ->loginAdmin ();
412+ $ table_data = [
413+ 'title ' => 'Test ' ,
414+ 'description ' => 'Test ' ,
415+ 'default_decision ' => 'Decline ' ,
416+ 'fields ' => [
417+ [
418+ "key " => 'boolean ' ,
419+ "title " => 'Test ' ,
420+ "source " => "request " ,
421+ "type " => 'boolean '
422+ ]
423+ ],
424+ 'rules ' => [
425+ [
426+ 'than ' => 'Approve ' ,
427+ 'title ' => '' ,
428+ 'description ' => '' ,
429+ 'conditions ' => [
430+ [
431+ 'field_key ' => 'boolean ' ,
432+ 'condition ' => '$eq ' ,
433+ 'value ' => true ,
434+ ]
435+ ]
436+ ]
437+ ]
438+ ];
439+
440+ # boolean
441+ $ table = $ I ->createTable ($ table_data );
442+ foreach ([true , '1 ' , 1 ] as $ value ) {
443+ $ I ->checkDecision ($ table ->_id , ['boolean ' => $ value ]);
444+ $ I ->assertResponseDataFields (['final_decision ' => 'Approve ' ]);
445+ }
446+ foreach ([false , '0 ' , 0 ] as $ value ) {
447+ $ I ->checkDecision ($ table ->_id , ['boolean ' => $ value ]);
448+ $ I ->assertResponseDataFields (['final_decision ' => 'Decline ' ]);
449+ }
450+ foreach (['invalid ' , 100 , null ] as $ value ) {
451+ $ I ->sendPOST ("api/v1/tables/ $ table ->_id /decisions " , ['boolean ' => $ value ]);
452+ $ I ->seeResponseCodeIs (422 );
453+ }
454+
455+ # string
456+ $ table_data ['fields ' ][0 ]['type ' ] = 'string ' ;
457+ $ table_data ['rules ' ][0 ]['conditions ' ][0 ]['value ' ] = 'string ' ;
458+ $ table = $ I ->createTable ($ table_data );
459+ foreach ([true , null , 1 , '' ] as $ value ) {
460+ $ I ->sendPOST ("api/v1/tables/ $ table ->_id /decisions " , ['boolean ' => $ value ]);
461+ $ I ->seeResponseCodeIs (422 );
462+ }
463+ foreach (['invalid ' , '123321 ' ] as $ value ) {
464+ $ I ->checkDecision ($ table ->_id , ['boolean ' => $ value ]);
465+ $ I ->assertResponseDataFields (['final_decision ' => 'Decline ' ]);
466+ }
467+ $ I ->checkDecision ($ table ->_id , ['boolean ' => 'string ' ]);
468+ $ I ->assertResponseDataFields (['final_decision ' => 'Approve ' ]);
469+
470+ # numeric
471+ $ table_data ['fields ' ][0 ]['type ' ] = 'numeric ' ;
472+ $ table_data ['rules ' ][0 ]['conditions ' ][0 ]['value ' ] = 100.15 ;
473+ $ table = $ I ->createTable ($ table_data );
474+ foreach ([true , null , 'invalid ' , '100.15i ' ] as $ value ) {
475+ $ I ->sendPOST ("api/v1/tables/ $ table ->_id /decisions " , ['boolean ' => $ value ]);
476+ $ I ->seeResponseCodeIs (422 );
477+ }
478+ foreach ([100 , "100 " ] as $ value ) {
479+ $ I ->checkDecision ($ table ->_id , ['boolean ' => $ value ]);
480+ $ I ->assertResponseDataFields (['final_decision ' => 'Decline ' ]);
481+ }
482+ foreach ([100.15 , "100.15 " ] as $ value ) {
483+ $ I ->checkDecision ($ table ->_id , ['boolean ' => $ value ]);
484+ $ I ->assertResponseDataFields (['final_decision ' => 'Approve ' ]);
485+ }
486+ }
487+
488+ public function ruleNotEqual (ApiTester $ I )
489+ {
490+ $ I ->loginAdmin ();
491+ $ table = $ I ->createTable ([
492+ 'title ' => 'Test ' ,
493+ 'description ' => 'Test ' ,
494+ 'default_decision ' => 'Decline ' ,
495+ 'fields ' => [
496+ [
497+ "key " => 'boolean ' ,
498+ "title " => 'Test ' ,
499+ "source " => "request " ,
500+ "type " => 'numeric '
501+ ]
502+ ],
503+ 'rules ' => [
504+ [
505+ 'than ' => 'Approve ' ,
506+ 'title ' => '' ,
507+ 'description ' => '' ,
508+ 'conditions ' => [
509+ [
510+ 'field_key ' => 'boolean ' ,
511+ 'condition ' => '$ne ' ,
512+ 'value ' => 100 ,
513+ ]
514+ ]
515+ ]
516+ ]
517+ ]);
518+ foreach ([true , null , 'invalid ' , '100.15i ' ] as $ value ) {
519+ $ I ->sendPOST ("api/v1/tables/ $ table ->_id /decisions " , ['boolean ' => $ value ]);
520+ $ I ->seeResponseCodeIs (422 );
521+ }
522+ foreach ([100 , "100 " ] as $ value ) {
523+ $ I ->checkDecision ($ table ->_id , ['boolean ' => $ value ]);
524+ $ I ->assertResponseDataFields (['final_decision ' => 'Decline ' ]);
525+ }
526+ foreach ([100.15 , "100.15 " ] as $ value ) {
527+ $ I ->checkDecision ($ table ->_id , ['boolean ' => $ value ]);
528+ $ I ->assertResponseDataFields (['final_decision ' => 'Approve ' ]);
529+ }
530+ }
531+
409532 public function all (ApiTester $ I )
410533 {
411534 $ I ->loginAdmin ();
0 commit comments