mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
Fix tests
This commit is contained in:
@@ -25,6 +25,7 @@ namespace FireflyIII\Http\Requests;
|
|||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use Illuminate\Validation\Validator;
|
use Illuminate\Validation\Validator;
|
||||||
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class JournalFormRequest.
|
* Class JournalFormRequest.
|
||||||
@@ -237,12 +238,19 @@ class JournalFormRequest extends Request
|
|||||||
{
|
{
|
||||||
$data = $validator->getData();
|
$data = $validator->getData();
|
||||||
$type = $data['what'] ?? 'invalid';
|
$type = $data['what'] ?? 'invalid';
|
||||||
|
Log::debug(sprintf('Type is %s', $type));
|
||||||
if ($type === 'withdrawal') {
|
if ($type === 'withdrawal') {
|
||||||
|
|
||||||
$selectedCurrency = (int)($data['amount_currency_id_amount'] ?? 0);
|
$selectedCurrency = (int)($data['amount_currency_id_amount'] ?? 0);
|
||||||
$accountCurrency = (int)($data['source_account_currency'] ?? 0);
|
$accountCurrency = (int)($data['source_account_currency'] ?? 0);
|
||||||
$nativeAmount = (string)$data['native_amount'];
|
Log::debug(sprintf('Selected currency is %d, account currency is %d', $selectedCurrency, $accountCurrency));
|
||||||
if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount) {
|
$nativeAmount = (string)($data['native_amount'] ?? '');
|
||||||
$validator->errors()->add('native_amount', trans('validation.numeric', ['attribute' => 'native_amount']));
|
if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount
|
||||||
|
&& $selectedCurrency !== 0
|
||||||
|
&& $accountCurrency !== 0
|
||||||
|
) {
|
||||||
|
Log::debug('ADD validation error on native_amount');
|
||||||
|
$validator->errors()->add('native_amount', trans('validation.numeric_native'));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -252,9 +260,12 @@ class JournalFormRequest extends Request
|
|||||||
if ($type === 'deposit') {
|
if ($type === 'deposit') {
|
||||||
$selectedCurrency = (int)($data['amount_currency_id_amount'] ?? 0);
|
$selectedCurrency = (int)($data['amount_currency_id_amount'] ?? 0);
|
||||||
$accountCurrency = (int)($data['destination_account_currency'] ?? 0);
|
$accountCurrency = (int)($data['destination_account_currency'] ?? 0);
|
||||||
$nativeAmount = (string)$data['native_amount'];
|
$nativeAmount = (string)($data['native_amount'] ?? '');
|
||||||
if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount) {
|
if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount
|
||||||
$validator->errors()->add('native_amount', trans('validation.numeric', ['attribute' => 'native_amount']));
|
&& $selectedCurrency !== 0
|
||||||
|
&& $accountCurrency !== 0
|
||||||
|
) {
|
||||||
|
$validator->errors()->add('native_amount', trans('validation.numeric_native'));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -262,17 +273,29 @@ class JournalFormRequest extends Request
|
|||||||
|
|
||||||
// and for transfers
|
// and for transfers
|
||||||
if ($type === 'transfer') {
|
if ($type === 'transfer') {
|
||||||
|
|
||||||
$sourceCurrency = (int)($data['source_account_currency'] ?? 0);
|
$sourceCurrency = (int)($data['source_account_currency'] ?? 0);
|
||||||
$destinationCurrency = (int)($data['destination_account_currency'] ?? 0);
|
$destinationCurrency = (int)($data['destination_account_currency'] ?? 0);
|
||||||
$sourceAmount = (string)$data['source_amount'];
|
$sourceAmount = (string)($data['source_amount'] ?? '');
|
||||||
$destinationAmount = (string)$data['destination_amount'];
|
$destinationAmount = (string)($data['destination_amount'] ?? '');
|
||||||
if ($sourceCurrency !== $destinationCurrency && '' === $sourceAmount) {
|
|
||||||
$validator->errors()->add('source_amount', trans('validation.numeric', ['attribute' => 'source_amount']));
|
Log::debug(sprintf('Source currency is %d, destination currency is %d', $sourceCurrency, $destinationCurrency));
|
||||||
|
|
||||||
|
if ($sourceCurrency !== $destinationCurrency && '' === $sourceAmount
|
||||||
|
&& $sourceCurrency !== 0
|
||||||
|
&& $destinationCurrency !== 0
|
||||||
|
) {
|
||||||
|
$validator->errors()->add('source_amount', trans('validation.numeric_source'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sourceCurrency !== $destinationCurrency && '' === $destinationAmount) {
|
if ($sourceCurrency !== $destinationCurrency && '' === $destinationAmount
|
||||||
|
&& $sourceCurrency !== 0
|
||||||
|
&& $destinationCurrency !== 0
|
||||||
|
) {
|
||||||
|
$validator->errors()->add('destination_amount', trans('validation.numeric_destination'));
|
||||||
$validator->errors()->add('destination_amount', trans('validation.numeric', ['attribute' => 'destination_amount']));
|
$validator->errors()->add('destination_amount', trans('validation.numeric', ['attribute' => 'destination_amount']));
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -91,6 +91,9 @@ return [
|
|||||||
'min.array' => 'The :attribute must have at least :min items.',
|
'min.array' => 'The :attribute must have at least :min items.',
|
||||||
'not_in' => 'The selected :attribute is invalid.',
|
'not_in' => 'The selected :attribute is invalid.',
|
||||||
'numeric' => 'The :attribute must be a number.',
|
'numeric' => 'The :attribute must be a number.',
|
||||||
|
'numeric_native' => 'The native amount must be a number.',
|
||||||
|
'numeric_destination' => 'The destination amount must be a number.',
|
||||||
|
'numeric_source' => 'The source amount must be a number.',
|
||||||
'regex' => 'The :attribute format is invalid.',
|
'regex' => 'The :attribute format is invalid.',
|
||||||
'required' => 'The :attribute field is required.',
|
'required' => 'The :attribute field is required.',
|
||||||
'required_if' => 'The :attribute field is required when :other is :value.',
|
'required_if' => 'The :attribute field is required when :other is :value.',
|
||||||
|
@@ -810,6 +810,8 @@ class SingleControllerTest extends TestCase
|
|||||||
$data = [
|
$data = [
|
||||||
'what' => 'transfer',
|
'what' => 'transfer',
|
||||||
'amount' => '10',
|
'amount' => '10',
|
||||||
|
'source_amount' => '10',
|
||||||
|
'destination_amount' => '10',
|
||||||
'amount_currency_id_amount' => 1,
|
'amount_currency_id_amount' => 1,
|
||||||
'source_account_currency' => 1,
|
'source_account_currency' => 1,
|
||||||
'destination_account_currency' => 2,
|
'destination_account_currency' => 2,
|
||||||
|
Reference in New Issue
Block a user