mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix budget limit tests
This commit is contained in:
@@ -104,7 +104,7 @@ class ShowController extends Controller
|
||||
*/
|
||||
public function show(Request $request, Budget $budget, BudgetLimit $budgetLimit): JsonResponse
|
||||
{
|
||||
if ($budget->id !== $budgetLimit->budget_id) {
|
||||
if ((int)$budget->id !== (int)$budgetLimit->budget_id) {
|
||||
throw new FireflyException('20028: The budget limit does not belong to the budget.');
|
||||
}
|
||||
// continue!
|
||||
|
||||
@@ -74,7 +74,7 @@ class UpdateController extends Controller
|
||||
public function update(UpdateRequest $request, Budget $budget, BudgetLimit $budgetLimit): JsonResponse
|
||||
{
|
||||
|
||||
if ($budget->id !== $budgetLimit->budget_id) {
|
||||
if ((int)$budget->id !== (int)$budgetLimit->budget_id) {
|
||||
throw new FireflyException('20028: The budget limit does not belong to the budget.');
|
||||
}
|
||||
$data = $request->getAll();
|
||||
|
||||
@@ -23,9 +23,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Requests\Models\BudgetLimit;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Support\Request\ChecksLogin;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
/**
|
||||
* Class UpdateRequest
|
||||
@@ -43,13 +45,15 @@ class UpdateRequest extends FormRequest
|
||||
*/
|
||||
public function getAll(): array
|
||||
{
|
||||
return [
|
||||
'start' => $this->date('start'),
|
||||
'end' => $this->date('end'),
|
||||
'amount' => $this->string('amount'),
|
||||
'currency_id' => $this->integer('currency_id'),
|
||||
'currency_code' => $this->string('currency_code'),
|
||||
$fields = [
|
||||
'start' => ['start', 'date'],
|
||||
'end' => ['end', 'date'],
|
||||
'amount' => ['amount', 'string'],
|
||||
'currency_id' => ['currency_id', 'integer'],
|
||||
'currency_code' => ['currency_code', 'string'],
|
||||
];
|
||||
|
||||
return $this->getAllData($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,12 +64,37 @@ return [
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'start' => 'before:end|date',
|
||||
'end' => 'after:start|date',
|
||||
'start' => 'date',
|
||||
'end' => 'date',
|
||||
'amount' => 'gt:0',
|
||||
'currency_id' => 'numeric|exists:transaction_currencies,id',
|
||||
'currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the validator instance with special rules for after the basic validation rules.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* TODO duplicate code.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(
|
||||
function (Validator $validator) {
|
||||
// validate start before end only if both are there.
|
||||
$data = $validator->getData();
|
||||
if (array_key_exists('start', $data) && array_key_exists('end', $data)) {
|
||||
$start = new Carbon($data['start']);
|
||||
$end = new Carbon($data['end']);
|
||||
if ($end->isBefore($start)) {
|
||||
$validator->errors()->add('end', (string)trans('validation.date_after'));
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -359,8 +359,8 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
{
|
||||
$budgetLimit->amount = array_key_exists('amount', $data) ? $data['amount'] : $budgetLimit->amount;
|
||||
$budgetLimit->budget_id = array_key_exists('budget_id', $data) ? $data['budget_id'] : $budgetLimit->budget_id;
|
||||
$budgetLimit->start_date = array_key_exists('start_date', $data) ? $data['start_date']->format('Y-m-d 00:00:00') : $budgetLimit->start_date;
|
||||
$budgetLimit->end_date = array_key_exists('end_date', $data) ? $data['end_date']->format('Y-m-d 23:59:59') : $budgetLimit->end_date;
|
||||
$budgetLimit->start_date = array_key_exists('start', $data) ? $data['start']->format('Y-m-d 00:00:00') : $budgetLimit->start_date;
|
||||
$budgetLimit->end_date = array_key_exists('end', $data) ? $data['end']->format('Y-m-d 23:59:59') : $budgetLimit->end_date;
|
||||
|
||||
// if no currency has been provided, use the user's default currency:
|
||||
$currency = null;
|
||||
@@ -381,8 +381,6 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
$budgetLimit->transaction_currency_id = $currency->id;
|
||||
$budgetLimit->save();
|
||||
|
||||
Log::debug(sprintf('Updated budget limit with ID #%d and amount %s', $budgetLimit->id, $data['amount']));
|
||||
|
||||
return $budgetLimit;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,16 +33,6 @@ use Log;
|
||||
*/
|
||||
class BillDestroyService
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
*/
|
||||
|
||||
@@ -34,16 +34,6 @@ use Log;
|
||||
*/
|
||||
class BudgetDestroyService
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
*/
|
||||
|
||||
@@ -34,16 +34,6 @@ use Log;
|
||||
*/
|
||||
class CategoryDestroyService
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*/
|
||||
|
||||
@@ -67,10 +67,6 @@ class AccountValidator
|
||||
|
||||
/** @var AccountRepositoryInterface accountRepository */
|
||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user