Fix tests for transaction storage.

This commit is contained in:
James Cole
2021-03-14 16:08:49 +01:00
parent 288052905e
commit beece4dcbb
14 changed files with 1067 additions and 167 deletions

View File

@@ -43,7 +43,6 @@ class StoreRequest extends FormRequest
use ConvertsDataTypes, RecurrenceValidation, TransactionValidation, CurrencyValidation, GetRecurrenceData, ChecksLogin;
/**
* Get all data from the request.
*
@@ -51,26 +50,21 @@ class StoreRequest extends FormRequest
*/
public function getAll(): array
{
$active = true;
$applyRules = true;
if (null !== $this->get('active')) {
$active = $this->boolean('active');
}
if (null !== $this->get('apply_rules')) {
$applyRules = $this->boolean('apply_rules');
}
$fields = [
'type' => ['type', 'string'],
'title' => ['title', 'string'],
'description' => ['description', 'string'],
'first_date' => ['first_date', 'date'],
'repeat_until' => ['repeat_until', 'date'],
'nr_of_repetitions' => ['nr_of_repetitions', 'integer'],
'apply_rules' => ['apply_rules', 'boolean'],
'active' => ['active', 'boolean'],
'notes' => ['notes', 'nlString'],
];
$recurrence = $this->getAllData($fields);
return [
'recurrence' => [
'type' => $this->string('type'),
'title' => $this->string('title'),
'description' => $this->string('description'),
'first_date' => $this->date('first_date'),
'repeat_until' => $this->date('repeat_until'),
'repetitions' => $this->integer('nr_of_repetitions'),
'apply_rules' => $applyRules,
'active' => $active,
],
'recurrence' => $recurrence,
'transactions' => $this->getTransactionData(),
'repetitions' => $this->getRepetitionData(),
];
@@ -93,7 +87,7 @@ class StoreRequest extends FormRequest
}
/** @var array $transaction */
foreach ($transactions as $transaction) {
$return[] = $this->getSingleRecurrenceData($transaction);
$return[] = $this->getSingleTransactionData($transaction);
}
return $return;
@@ -115,12 +109,21 @@ class StoreRequest extends FormRequest
}
/** @var array $repetition */
foreach ($repetitions as $repetition) {
$return[] = [
'type' => $repetition['type'],
'moment' => $repetition['moment'],
'skip' => (int) $repetition['skip'],
'weekend' => (int) $repetition['weekend'],
];
$current = [];
if (array_key_exists('type', $repetition)) {
$current['type'] = $repetition['type'];
}
if (array_key_exists('moment', $repetition)) {
$current['moment'] = $repetition['moment'];
}
if (array_key_exists('skip', $repetition)) {
$current['skip'] = (int)$repetition['skip'];
}
if (array_key_exists('weekend', $repetition)) {
$current['weekend'] = (int)$repetition['weekend'];
}
$return[] = $current;
}
return $return;
@@ -142,12 +145,12 @@ class StoreRequest extends FormRequest
'first_date' => 'required|date',
'apply_rules' => [new IsBoolean],
'active' => [new IsBoolean],
'repeat_until' => sprintf('date|after:%s', $today->format('Y-m-d')),
'repeat_until' => 'date',
'nr_of_repetitions' => 'numeric|between:1,31',
'repetitions.*.type' => 'required|in:daily,weekly,ndom,monthly,yearly',
'repetitions.*.moment' => 'between:0,10',
'repetitions.*.skip' => 'required|numeric|between:0,31',
'repetitions.*.weekend' => 'required|numeric|min:1|max:4',
'repetitions.*.skip' => 'numeric|between:0,31',
'repetitions.*.weekend' => 'numeric|min:1|max:4',
'transactions.*.description' => 'required|between:1,255',
'transactions.*.amount' => 'required|numeric|gt:0',
'transactions.*.foreign_amount' => 'numeric|gt:0',
@@ -184,6 +187,7 @@ class StoreRequest extends FormRequest
{
$validator->after(
function (Validator $validator) {
$this->validateRecurringConfig($validator);
$this->validateOneRecurrenceTransaction($validator);
$this->validateOneRepetition($validator);
$this->validateRecurrenceRepetition($validator);

View File

@@ -40,7 +40,6 @@ class StoreRequest extends FormRequest
use ConvertsDataTypes, GetRuleConfiguration, ChecksLogin;
/**
* Get all data from the request.
*
@@ -48,31 +47,23 @@ class StoreRequest extends FormRequest
*/
public function getAll(): array
{
$strict = true;
$active = true;
$stopProcessing = false;
if (null !== $this->get('active')) {
$active = $this->boolean('active');
}
if (null !== $this->get('strict')) {
$strict = $this->boolean('strict');
}
if (null !== $this->get('stop_processing')) {
$stopProcessing = $this->boolean('stop_processing');
}
return [
'title' => $this->string('title'),
'description' => $this->string('description'),
'rule_group_id' => $this->integer('rule_group_id'),
'rule_group_title' => $this->string('rule_group_title'),
'trigger' => $this->string('trigger'),
'strict' => $strict,
'stop_processing' => $stopProcessing,
'active' => $active,
'triggers' => $this->getRuleTriggers(),
'actions' => $this->getRuleActions(),
$fields = [
'title' => ['title', 'string'],
'description' => ['description', 'string'],
'rule_group_id' => ['rule_group_id', 'integer'],
'order' => ['order', 'integer'],
'rule_group_title' => ['rule_group_title', 'string'],
'trigger' => ['trigger', 'string'],
'strict' => ['strict', 'boolean'],
'stop_processing' => ['stop_processing', 'boolean'],
'active' => ['active', 'boolean'],
];
$data = $this->getAllData($fields);
$data['triggers'] = $this->getRuleTriggers();
$data['actions'] = $this->getRuleActions();
return $data;
}
/**
@@ -87,8 +78,8 @@ class StoreRequest extends FormRequest
$return[] = [
'type' => $trigger['type'],
'value' => $trigger['value'],
'active' => $this->convertBoolean((string) ($trigger['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string) ($trigger['stop_processing'] ?? 'false')),
'active' => $this->convertBoolean((string)($trigger['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string)($trigger['stop_processing'] ?? 'false')),
];
}
}
@@ -108,8 +99,8 @@ class StoreRequest extends FormRequest
$return[] = [
'type' => $action['type'],
'value' => $action['value'],
'active' => $this->convertBoolean((string) ($action['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string) ($action['stop_processing'] ?? 'false')),
'active' => $this->convertBoolean((string)($action['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string)($action['stop_processing'] ?? 'false')),
];
}
}
@@ -134,7 +125,7 @@ class StoreRequest extends FormRequest
return [
'title' => 'required|between:1,100|uniqueObjectForUser:rules,title',
'description' => 'between:1,5000|nullable',
'rule_group_id' => 'required|belongsToUser:rule_groups|required_without:rule_group_title',
'rule_group_id' => 'belongsToUser:rule_groups|required_without:rule_group_title',
'rule_group_title' => 'nullable|between:1,255|required_without:rule_group_id|belongsToUser:rule_groups,title',
'trigger' => 'required|in:store-journal,update-journal',
'triggers.*.type' => 'required|in:' . implode(',', $validTriggers),
@@ -179,7 +170,7 @@ class StoreRequest extends FormRequest
$triggers = $data['triggers'] ?? [];
// need at least one trigger
if (!is_countable($triggers) || 0 === count($triggers)) {
$validator->errors()->add('title', (string) trans('validation.at_least_one_trigger'));
$validator->errors()->add('title', (string)trans('validation.at_least_one_trigger'));
}
}
@@ -194,7 +185,7 @@ class StoreRequest extends FormRequest
$actions = $data['actions'] ?? [];
// need at least one trigger
if (!is_countable($actions) || 0 === count($actions)) {
$validator->errors()->add('title', (string) trans('validation.at_least_one_action'));
$validator->errors()->add('title', (string)trans('validation.at_least_one_action'));
}
}
}