Finish budget tests.

This commit is contained in:
James Cole
2021-03-13 19:03:08 +01:00
parent fdcd6befb6
commit 1f50f65bb7
7 changed files with 436 additions and 88 deletions

View File

@@ -68,6 +68,7 @@ class StoreController extends Controller
public function store(StoreRequest $request): JsonResponse
{
$budget = $this->repository->store($request->getAll());
$budget->refresh();
$manager = $this->getManager();
/** @var BudgetTransformer $transformer */

View File

@@ -46,23 +46,20 @@ class StoreRequest extends FormRequest
*/
public function getAll(): array
{
$active = true;
if (null !== $this->get('active')) {
$active = $this->boolean('active');
}
$fields = [
'name' => ['name', 'string'],
'active' => ['active', 'boolean'],
'order' => ['active', 'integer'],
return [
'name' => $this->string('name'),
'active' => $active,
'order' => 0,
'transaction_currency_id' => $this->integer('auto_budget_currency_id'),
'transaction_currency_code' => $this->string('auto_budget_currency_code'),
// auto budget info
'auto_budget_type' => $this->string('auto_budget_type'),
'auto_budget_amount' => $this->string('auto_budget_amount'),
'auto_budget_period' => $this->string('auto_budget_period'),
// auto budget currency:
'currency_id' => ['auto_budget_currency_id', 'integer'],
'currency_code' => ['auto_budget_currency_code', 'string'],
'auto_budget_type' => ['auto_budget_type', 'string'],
'auto_budget_amount' => ['auto_budget_amount', 'string'],
'auto_budget_period' => ['auto_budget_period', 'string'],
];
return $this->getAllData($fields);
}
/**
@@ -73,14 +70,14 @@ class StoreRequest extends FormRequest
public function rules(): array
{
return [
'name' => 'required|between:1,100|uniqueObjectForUser:budgets,name',
'active' => [new IsBoolean],
'auto_budget_currency_id' => 'exists:transaction_currencies,id',
'auto_budget_currency_code' => 'exists:transaction_currencies,code',
'name' => 'required|between:1,100|uniqueObjectForUser:budgets,name',
'active' => [new IsBoolean],
'currency_id' => 'exists:transaction_currencies,id',
'currency_code' => 'exists:transaction_currencies,code',
// auto budget info
'auto_budget_type' => 'in:reset,rollover,none',
'auto_budget_amount' => 'min:0|max:1000000000',
'auto_budget_period' => 'in:daily,weekly,monthly,quarterly,half_year,yearly',
'auto_budget_type' => 'in:reset,rollover,none',
'auto_budget_amount' => 'min:0|max:1000000000',
'auto_budget_period' => 'in:daily,weekly,monthly,quarterly,half_year,yearly',
];
}

View File

@@ -46,21 +46,19 @@ class UpdateRequest extends FormRequest
*/
public function getAll(): array
{
$active = true;
if (null !== $this->get('active')) {
$active = $this->boolean('active');
}
return [
'name' => $this->string('name'),
'active' => $active,
'order' => 0,
'auto_budget_type' => $this->string('auto_budget_type'),
'transaction_currency_id' => $this->integer('auto_budget_currency_id'),
'transaction_currency_code' => $this->string('auto_budget_currency_code'),
'auto_budget_amount' => $this->string('auto_budget_amount'),
'auto_budget_period' => $this->string('auto_budget_period'),
// this is the way:
$fields = [
'name' => ['name', 'string'],
'active' => ['active', 'boolean'],
'order' => ['order', 'integer'],
'currency_id' => ['auto_budget_currency_id', 'integer'],
'currency_code' => ['auto_budget_currency_code', 'string'],
'auto_budget_type' => ['auto_budget_type', 'string'],
'auto_budget_amount' => ['auto_budget_amount', 'string'],
'auto_budget_period' => ['auto_budget_period', 'string'],
];
return $this->getAllData($fields);
}
/**
@@ -73,7 +71,7 @@ class UpdateRequest extends FormRequest
$budget = $this->route()->parameter('budget');
return [
'name' => sprintf('required|between:1,100|uniqueObjectForUser:budgets,name,%d', $budget->id),
'name' => sprintf('between:1,100|uniqueObjectForUser:budgets,name,%d', $budget->id),
'active' => [new IsBoolean],
'auto_budget_type' => 'in:reset,rollover,none',
'auto_budget_currency_id' => 'exists:transaction_currencies,id',