Skip to content

Commit f843de0

Browse files
committed
Merge pull request #4 from Nebo15/GDF-113
GDF-113 - non strict $eq and $ne rules
2 parents 567a046 + 6c201b1 commit f843de0

File tree

3 files changed

+127
-4
lines changed

3 files changed

+127
-4
lines changed

app/Services/ConditionsTypes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public function __construct()
2323
'$eq' => [
2424
'input_type' => '',
2525
'function' => function ($condition_value, $field_value) {
26-
return $condition_value === $field_value;
26+
return $condition_value == $field_value;
2727
}
2828
],
2929
'$ne' => [
3030
'input_type' => '',
3131
'function' => function ($condition_value, $field_value) {
32-
return $condition_value !== $field_value;
32+
return $condition_value != $field_value;
3333
}
3434
],
3535
'$gt' => [

tests/_support/ApiTester.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function assertTable($jsonPath = '$.data', $code = 200)
7373
$this->seeResponseMatchesJsonType([
7474
'field_key' => 'string',
7575
'condition' => 'string',
76-
'value' => 'string|boolean',
76+
'value' => 'string|integer|float|boolean',
7777
], "$jsonPath.rules[*].conditions[*]");
7878

7979
$this->dontSeeResponseJsonMatchesJsonPath("$jsonPath.rules[*].conditions[*].matched");
@@ -117,7 +117,7 @@ public function assertTableDecisionsForAdmin($jsonPath = '$.data')
117117
$this->seeResponseMatchesJsonType([
118118
'field_key' => 'string',
119119
'condition' => 'string',
120-
'value' => 'string|boolean',
120+
'value' => 'string|integer|float|boolean',
121121
'matched' => 'boolean',
122122
], "$jsonPath.rules[*].conditions[*]");
123123

tests/api/TablesCest.php

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)