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\Models\TransactionType;
|
||||
use Illuminate\Validation\Validator;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class JournalFormRequest.
|
||||
@@ -237,12 +238,19 @@ class JournalFormRequest extends Request
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$type = $data['what'] ?? 'invalid';
|
||||
Log::debug(sprintf('Type is %s', $type));
|
||||
if ($type === 'withdrawal') {
|
||||
|
||||
$selectedCurrency = (int)($data['amount_currency_id_amount'] ?? 0);
|
||||
$accountCurrency = (int)($data['source_account_currency'] ?? 0);
|
||||
$nativeAmount = (string)$data['native_amount'];
|
||||
if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount) {
|
||||
$validator->errors()->add('native_amount', trans('validation.numeric', ['attribute' => 'native_amount']));
|
||||
Log::debug(sprintf('Selected currency is %d, account currency is %d', $selectedCurrency, $accountCurrency));
|
||||
$nativeAmount = (string)($data['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;
|
||||
}
|
||||
@@ -252,9 +260,12 @@ class JournalFormRequest extends Request
|
||||
if ($type === 'deposit') {
|
||||
$selectedCurrency = (int)($data['amount_currency_id_amount'] ?? 0);
|
||||
$accountCurrency = (int)($data['destination_account_currency'] ?? 0);
|
||||
$nativeAmount = (string)$data['native_amount'];
|
||||
if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount) {
|
||||
$validator->errors()->add('native_amount', trans('validation.numeric', ['attribute' => 'native_amount']));
|
||||
$nativeAmount = (string)($data['native_amount'] ?? '');
|
||||
if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount
|
||||
&& $selectedCurrency !== 0
|
||||
&& $accountCurrency !== 0
|
||||
) {
|
||||
$validator->errors()->add('native_amount', trans('validation.numeric_native'));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -262,17 +273,29 @@ class JournalFormRequest extends Request
|
||||
|
||||
// and for transfers
|
||||
if ($type === 'transfer') {
|
||||
|
||||
$sourceCurrency = (int)($data['source_account_currency'] ?? 0);
|
||||
$destinationCurrency = (int)($data['destination_account_currency'] ?? 0);
|
||||
$sourceAmount = (string)$data['source_amount'];
|
||||
$destinationAmount = (string)$data['destination_amount'];
|
||||
if ($sourceCurrency !== $destinationCurrency && '' === $sourceAmount) {
|
||||
$validator->errors()->add('source_amount', trans('validation.numeric', ['attribute' => 'source_amount']));
|
||||
$sourceAmount = (string)($data['source_amount'] ?? '');
|
||||
$destinationAmount = (string)($data['destination_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']));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -91,6 +91,9 @@ return [
|
||||
'min.array' => 'The :attribute must have at least :min items.',
|
||||
'not_in' => 'The selected :attribute is invalid.',
|
||||
'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.',
|
||||
'required' => 'The :attribute field is required.',
|
||||
'required_if' => 'The :attribute field is required when :other is :value.',
|
||||
|
@@ -810,6 +810,8 @@ class SingleControllerTest extends TestCase
|
||||
$data = [
|
||||
'what' => 'transfer',
|
||||
'amount' => '10',
|
||||
'source_amount' => '10',
|
||||
'destination_amount' => '10',
|
||||
'amount_currency_id_amount' => 1,
|
||||
'source_account_currency' => 1,
|
||||
'destination_account_currency' => 2,
|
||||
|
Reference in New Issue
Block a user