Expand API test to bill store.

This commit is contained in:
James Cole
2021-03-13 16:47:29 +01:00
parent bdb298740a
commit c9f7f877c0
15 changed files with 679 additions and 178 deletions

View File

@@ -57,6 +57,7 @@ class StoreController extends Controller
}
);
}
/**
* Store a newly created resource in storage.
*
@@ -70,14 +71,14 @@ class StoreController extends Controller
$data['start']->startOfDay();
$data['end']->endOfDay();
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
$currency = $factory->find($data['currency_id'], $data['currency_code']);
if (null === $currency) {
$currency = app('amount')->getDefaultCurrency();
// currency is not mandatory:
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
$factory = app(TransactionCurrencyFactory::class);
$currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null);
$data['currency_id'] = $currency->id;
unset($data['currency_code']);
}
$data['currency'] = $currency;
$availableBudget = $this->abRepository->store($data);
$manager = $this->getManager();

View File

@@ -72,20 +72,15 @@ class UpdateController extends Controller
{
$data = $request->getAll();
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
/** @var TransactionCurrency $currency */
$currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null);
if (null === $currency) {
// use default currency:
$currency = app('amount')->getDefaultCurrency();
// find and validate currency ID
if(array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
$factory = app(TransactionCurrencyFactory::class);
$currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null) ?? app('amount')->getDefaultCurrency();
$currency->enabled = true;
$currency->save();
unset($data['currency_code']);
$data['currency_id'] = $currency->id;
}
$currency->enabled = true;
$currency->save();
unset($data['currency_code']);
$data['currency_id'] = $currency->id;
$this->abRepository->updateAvailableBudget($availableBudget, $data);
$manager = $this->getManager();

View File

@@ -74,7 +74,8 @@ class StoreController extends Controller
*/
public function store(StoreRequest $request): JsonResponse
{
$bill = $this->repository->store($request->getAll());
$data = $request->getAll();
$bill = $this->repository->store($data);
$manager = $this->getManager();
/** @var BillTransformer $transformer */