Expand test cases.

This commit is contained in:
James Cole
2021-03-14 06:20:23 +01:00
parent d82fe2ab4c
commit 40a463d62a
33 changed files with 890 additions and 308 deletions

View File

@@ -82,7 +82,7 @@ class ShowController extends Controller
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of accounts. Count it and split it.
$this->repository->sortAccounts();
$this->repository->resetAccountOrder();
$collection = $this->repository->getAccountsByType($types);
$count = $collection->count();
$accounts = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
@@ -111,7 +111,7 @@ class ShowController extends Controller
public function show(Account $account): JsonResponse
{
// get list of accounts. Count it and split it.
$this->repository->sortAccounts();
$this->repository->resetAccountOrder();
$account->refresh();
$manager = $this->getManager();

View File

@@ -78,7 +78,7 @@ class ShowController extends Controller
// types to get, page size:
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of accounts. Count it and split it.
$this->repository->resetOrder();
$collection = $this->repository->get();
$count = $collection->count();
$objectGroups = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
@@ -108,6 +108,8 @@ class ShowController extends Controller
public function show(ObjectGroup $objectGroup): JsonResponse
{
$manager = $this->getManager();
$this->repository->resetOrder();
$objectGroup->refresh();
/** @var ObjectGroupTransformer $transformer */
$transformer = app(ObjectGroupTransformer::class);

View File

@@ -70,7 +70,7 @@ class UpdateController extends Controller
{
$data = $request->getUpdateData();
$this->repository->update($objectGroup, $data);
$this->repository->sort();
$this->repository->resetOrder();
$manager = $this->getManager();
/** @var ObjectGroupTransformer $transformer */

View File

@@ -43,16 +43,11 @@ class UpdateRequest extends FormRequest
*/
public function getAll(): array
{
$notes = null;
$all = $this->all();
if (array_key_exists('notes', $all)) {
$notes = $this->nlString('notes');
}
return [
'name' => $this->string('name'),
'notes' => $notes,
$fields = [
'name' => ['name', 'string'],
'notes' => ['notes', 'nlString']
];
return $this->getAllData($fields);
}
/**
@@ -65,7 +60,7 @@ class UpdateRequest extends FormRequest
$category = $this->route()->parameter('category');
return [
'name' => sprintf('required|between:1,100|uniqueObjectForUser:categories,name,%d', $category->id),
'name' => sprintf('between:1,100|uniqueObjectForUser:categories,name,%d', $category->id),
];
}
}

View File

@@ -42,10 +42,11 @@ class UpdateRequest extends FormRequest
*/
public function getUpdateData(): array
{
return [
'title' => $this->string('title'),
'order' => $this->integer('order'),
$fields = [
'title' => ['title', 'string'],
'order' =>['order', 'integer']
];
return $this->getAllData($fields);
}
/**

View File

@@ -43,17 +43,24 @@ class StoreRequest extends FormRequest
*/
public function getAll(): array
{
return [
'name' => $this->string('name'),
'account_id' => $this->integer('account_id'),
'targetamount' => $this->string('target_amount'),
'current_amount' => $this->string('current_amount'),
'startdate' => $this->date('start_date'),
'targetdate' => $this->date('target_date'),
'notes' => $this->nlString('notes'),
'object_group_id' => $this->integer('object_group_id'),
'object_group_title' => $this->string('object_group_title'),
$fields = [
'order' => ['order', 'integer'],
];
$data = $this->getAllData($fields);
$data['name'] = $this->string('name');
$data['account_id'] = $this->integer('account_id');
$data['targetamount'] = $this->string('target_amount');
$data['current_amount'] = $this->string('current_amount');
$data['startdate'] = $this->date('start_date');
$data['targetdate'] = $this->date('target_date');
$data['notes'] = $this->nlString('notes');
$data['object_group_id'] = $this->integer('object_group_id');
$data['object_group_title'] = $this->string('object_group_title');
return $data;
}
/**

View File

@@ -45,24 +45,19 @@ class UpdateRequest extends FormRequest
*/
public function getAll(): array
{
// if the value isn't present, dont return it at all.
// TODO this should be the way to collect fields for all API things.
// TODO make sure piggy bank uses 'start_date' etc. until right up to DB update.
// TODO can we configure this and return it from config?
// TODO this is the way.
$fields = [
'name' => ['name', 'string'],
'account_id' => ['account_id', 'integer'],
'targetamount' => ['target_amount', 'string'],
'current_amount' => ['current_amount', 'string'],
'startdate' => ['start_date', 'date'],
'targetdate' => ['target_date', 'string'],
'notes' => ['notes', 'nlString'],
'order' => ['order', 'integer'],
'object_group' => ['object_group', 'string'],
'object_group_id' => ['object_group_id', 'integer'],
'name' => ['name', 'string'],
'account_id' => ['account_id', 'integer'],
'targetamount' => ['target_amount', 'string'],
'current_amount' => ['current_amount', 'string'],
'startdate' => ['start_date', 'date'],
'targetdate' => ['target_date', 'string'],
'notes' => ['notes', 'nlString'],
'order' => ['order', 'integer'],
'object_group_title' => ['object_group_title', 'string'],
'object_group_id' => ['object_group_id', 'integer'],
];
return $this->getAllData($fields);
}