Fix issue where the tester would not respect the strict yes/no setting.

This commit is contained in:
James Cole 2018-08-31 17:48:54 +02:00
parent 6377459e2f
commit 0cfe991482
4 changed files with 66 additions and 21 deletions

View File

@ -152,11 +152,13 @@ class SelectController extends Controller
$limit = (int)config('firefly.test-triggers.limit');
$range = (int)config('firefly.test-triggers.range');
$matchingTransactions = new Collection;
$strict = $request->get('strict') === '1';
/** @var TransactionMatcher $matcher */
$matcher = app(TransactionMatcher::class);
$matcher->setLimit($limit);
$matcher->setRange($range);
$matcher->setTriggers($triggers);
$matcher->setStrict($strict);
try {
$matchingTransactions = $matcher->findTransactionsByTriggers();
// @codeCoverageIgnoreStart

View File

@ -62,6 +62,22 @@ class Processor
$this->actions = new Collection;
}
/**
* @return bool
*/
public function isStrict(): bool
{
return $this->strict;
}
/**
* @param bool $strict
*/
public function setStrict(bool $strict): void
{
$this->strict = $strict;
}
/**
* Return found triggers
*

View File

@ -52,6 +52,30 @@ class TransactionMatcher
private $transactionTypes = [TransactionType::DEPOSIT, TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
/** @var array List of triggers to match */
private $triggers = [];
/** @var bool */
private $strict;
public function __construct()
{
$this->strict = false;
}
/**
* @return bool
*/
public function isStrict(): bool
{
return $this->strict;
}
/**
* @param bool $strict
*/
public function setStrict(bool $strict): void
{
$this->strict = $strict;
}
/**
* This method will search the user's transaction journal (with an upper limit of $range) for
@ -96,6 +120,7 @@ class TransactionMatcher
/** @var Processor $processor */
$processor = app(Processor::class);
$processor->makeFromStringArray($this->triggers);
$processor->setStrict($this->strict);
$result = $this->runProcessor($processor);
// If the list of matchingTransactions is larger than the maximum number of results

View File

@ -366,8 +366,10 @@ function testRuleTriggers() {
button.attr('disabled', 'disabled');
// Serialize all trigger data
var triggerData = $(".rule-trigger-tbody").find("input[type=text], input[type=checkbox], select").serializeArray();
console.log('Found the following trigger data: ' + triggerData);
var triggerData = $('.content').find("#ffInput_strict, .rule-trigger-tbody input[type=text], .rule-trigger-tbody input[type=checkbox], .rule-trigger-tbody select").serializeArray();
console.log('Found the following trigger data: ');
console.log(triggerData);
// Find a list of existing transactions that match these triggers
$.get('rules/test', triggerData).done(function (data) {