mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Clean up tests, test only the important things.
This commit is contained in:
parent
6f063a134f
commit
5ac39dbdef
@ -34,7 +34,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
|
||||
|
||||
/**
|
||||
* Returns basic information about this installation.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* Class AboutController.
|
||||
*/
|
||||
class AboutController extends Controller
|
||||
@ -69,7 +69,6 @@ class AboutController extends Controller
|
||||
* Returns information about the user.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function user(Request $request): JsonResponse
|
||||
|
@ -23,8 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Controllers;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Api\V1\Requests\AccountRequest;
|
||||
use FireflyIII\Api\V1\Requests\AccountStoreRequest;
|
||||
use FireflyIII\Api\V1\Requests\AccountUpdateRequest;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
@ -59,6 +57,8 @@ class AccountController extends Controller
|
||||
|
||||
/**
|
||||
* AccountController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -81,6 +81,7 @@ class AccountController extends Controller
|
||||
*
|
||||
* @param Account $account
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function delete(Account $account): JsonResponse
|
||||
@ -95,6 +96,7 @@ class AccountController extends Controller
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
@ -140,7 +142,9 @@ class AccountController extends Controller
|
||||
* @param Request $request
|
||||
* @param Account $account
|
||||
*
|
||||
* @return JsonResponse]
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function piggyBanks(Request $request, Account $account): JsonResponse
|
||||
{
|
||||
@ -180,6 +184,7 @@ class AccountController extends Controller
|
||||
* @param Request $request
|
||||
* @param Account $account
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function show(Request $request, Account $account): JsonResponse
|
||||
@ -202,7 +207,6 @@ class AccountController extends Controller
|
||||
* @param AccountStoreRequest $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function store(AccountStoreRequest $request): JsonResponse
|
||||
{
|
||||
@ -224,6 +228,8 @@ class AccountController extends Controller
|
||||
/**
|
||||
* Show all transaction groups related to the account.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Account $account
|
||||
*
|
||||
@ -293,7 +299,6 @@ class AccountController extends Controller
|
||||
* @param Account $account
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update(AccountUpdateRequest $request, Account $account): JsonResponse
|
||||
{
|
||||
|
@ -52,6 +52,7 @@ class AttachmentController extends Controller
|
||||
|
||||
/**
|
||||
* AccountController constructor.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -70,7 +71,7 @@ class AttachmentController extends Controller
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return JsonResponse
|
||||
@ -86,9 +87,9 @@ class AttachmentController extends Controller
|
||||
* Download an attachment.
|
||||
*
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return LaravelResponse
|
||||
* @throws FireflyException
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function download(Attachment $attachment): LaravelResponse
|
||||
{
|
||||
@ -121,7 +122,7 @@ class AttachmentController extends Controller
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
@ -160,7 +161,7 @@ class AttachmentController extends Controller
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function show(Request $request, Attachment $attachment): JsonResponse
|
||||
@ -230,7 +231,7 @@ class AttachmentController extends Controller
|
||||
|
||||
/**
|
||||
* Upload an attachment.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @param Request $request
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
|
@ -50,7 +50,9 @@ class AvailableBudgetController extends Controller
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* AccountController constructor.
|
||||
* AvailableBudgetController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -72,6 +74,8 @@ class AvailableBudgetController extends Controller
|
||||
*
|
||||
* @param AvailableBudget $availableBudget
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function delete(AvailableBudget $availableBudget): JsonResponse
|
||||
@ -87,6 +91,7 @@ class AvailableBudgetController extends Controller
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -135,10 +140,11 @@ class AvailableBudgetController extends Controller
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param AvailableBudget $availableBudget
|
||||
* @param Request $request
|
||||
* @param AvailableBudget $availableBudget
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, AvailableBudget $availableBudget): JsonResponse
|
||||
{
|
||||
|
@ -57,6 +57,8 @@ class BillController extends Controller
|
||||
|
||||
/**
|
||||
* BillController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -82,6 +84,7 @@ class BillController extends Controller
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function attachments(Request $request, Bill $bill): JsonResponse
|
||||
{
|
||||
@ -115,9 +118,10 @@ class BillController extends Controller
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function delete(Bill $bill): JsonResponse
|
||||
{
|
||||
@ -132,6 +136,7 @@ class BillController extends Controller
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -161,6 +166,7 @@ class BillController extends Controller
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function rules(Request $request, Bill $bill): JsonResponse
|
||||
{
|
||||
@ -202,6 +208,7 @@ class BillController extends Controller
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, Bill $bill): JsonResponse
|
||||
{
|
||||
@ -254,6 +261,7 @@ class BillController extends Controller
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function transactions(Request $request, Bill $bill): JsonResponse
|
||||
{
|
||||
|
@ -42,7 +42,7 @@ use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\Serializer\JsonApiSerializer;
|
||||
|
||||
use Exception;
|
||||
/**
|
||||
* Class BudgetController.
|
||||
*
|
||||
@ -56,6 +56,8 @@ class BudgetController extends Controller
|
||||
|
||||
/**
|
||||
* BudgetController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -77,10 +79,12 @@ class BudgetController extends Controller
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function budgetLimits(Request $request, Budget $budget): JsonResponse
|
||||
{
|
||||
@ -113,6 +117,7 @@ class BudgetController extends Controller
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function delete(Budget $budget): JsonResponse
|
||||
{
|
||||
@ -127,6 +132,7 @@ class BudgetController extends Controller
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -166,6 +172,7 @@ class BudgetController extends Controller
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, Budget $budget): JsonResponse
|
||||
{
|
||||
@ -189,6 +196,7 @@ class BudgetController extends Controller
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*
|
||||
*/
|
||||
public function store(BudgetRequest $request): JsonResponse
|
||||
{
|
||||
@ -214,7 +222,7 @@ class BudgetController extends Controller
|
||||
*
|
||||
* @param BudgetLimitRequest $request
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @throws Exception
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function storeBudgetLimit(BudgetLimitRequest $request, Budget $budget): JsonResponse
|
||||
@ -243,6 +251,7 @@ class BudgetController extends Controller
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function transactions(Request $request, Budget $budget): JsonResponse
|
||||
{
|
||||
|
@ -43,7 +43,6 @@ use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\Serializer\JsonApiSerializer;
|
||||
|
||||
|
||||
/**
|
||||
* Class BudgetLimitController.
|
||||
*
|
||||
@ -56,7 +55,9 @@ class BudgetLimitController extends Controller
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* AccountController constructor.
|
||||
* BudgetLimitController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -79,6 +80,7 @@ class BudgetLimitController extends Controller
|
||||
* @param BudgetLimit $budgetLimit
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function delete(BudgetLimit $budgetLimit): JsonResponse
|
||||
{
|
||||
@ -93,6 +95,7 @@ class BudgetLimitController extends Controller
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -135,6 +138,7 @@ class BudgetLimitController extends Controller
|
||||
* @param BudgetLimit $budgetLimit
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, BudgetLimit $budgetLimit): JsonResponse
|
||||
{
|
||||
@ -158,6 +162,7 @@ class BudgetLimitController extends Controller
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*
|
||||
*/
|
||||
public function store(BudgetLimitRequest $request): JsonResponse
|
||||
{
|
||||
@ -188,6 +193,7 @@ class BudgetLimitController extends Controller
|
||||
* @param BudgetLimit $budgetLimit
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function transactions(Request $request, BudgetLimit $budgetLimit): JsonResponse
|
||||
{
|
||||
|
@ -54,6 +54,8 @@ class CategoryController extends Controller
|
||||
|
||||
/**
|
||||
* CategoryController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -78,6 +80,7 @@ class CategoryController extends Controller
|
||||
* @param Category $category
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function delete(Category $category): JsonResponse
|
||||
{
|
||||
@ -92,6 +95,7 @@ class CategoryController extends Controller
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -133,6 +137,7 @@ class CategoryController extends Controller
|
||||
* @param Category $category
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, Category $category): JsonResponse
|
||||
{
|
||||
@ -184,6 +189,7 @@ class CategoryController extends Controller
|
||||
* @param Category $category
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function transactions(Request $request, Category $category): JsonResponse
|
||||
{
|
||||
|
@ -32,6 +32,7 @@ use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* Class ConfigurationController.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class ConfigurationController extends Controller
|
||||
{
|
||||
@ -41,7 +42,8 @@ class ConfigurationController extends Controller
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* BudgetController constructor.
|
||||
* ConfigurationController constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -80,6 +80,7 @@ class CurrencyController extends Controller
|
||||
|
||||
/**
|
||||
* CurrencyRepository constructor.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -106,6 +107,7 @@ class CurrencyController extends Controller
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function accounts(Request $request, TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
@ -164,6 +166,7 @@ class CurrencyController extends Controller
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function availableBudgets(Request $request, TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
@ -218,6 +221,7 @@ class CurrencyController extends Controller
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function bills(Request $request, TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
@ -266,6 +270,7 @@ class CurrencyController extends Controller
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function budgetLimits(Request $request, TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
@ -308,6 +313,7 @@ class CurrencyController extends Controller
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function cer(Request $request, TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
@ -343,6 +349,7 @@ class CurrencyController extends Controller
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function delete(TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
@ -368,6 +375,7 @@ class CurrencyController extends Controller
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function disable(Request $request, TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
@ -400,6 +408,7 @@ class CurrencyController extends Controller
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function enable(Request $request, TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
@ -427,6 +436,7 @@ class CurrencyController extends Controller
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -462,6 +472,7 @@ class CurrencyController extends Controller
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function makeDefault(Request $request, TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
@ -493,7 +504,8 @@ class CurrencyController extends Controller
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return JsonResponse]
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function recurrences(Request $request, TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
@ -551,7 +563,8 @@ class CurrencyController extends Controller
|
||||
* @param Request $request
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return JsonResponse]
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function rules(Request $request, TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
@ -605,6 +618,7 @@ class CurrencyController extends Controller
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
@ -666,6 +680,7 @@ class CurrencyController extends Controller
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function transactions(Request $request, TransactionCurrency $currency): JsonResponse
|
||||
{
|
||||
|
@ -37,6 +37,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
|
||||
|
||||
/**
|
||||
* Class CurrencyExchangeRateController
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class CurrencyExchangeRateController extends Controller
|
||||
{
|
||||
@ -45,6 +46,7 @@ class CurrencyExchangeRateController extends Controller
|
||||
|
||||
/**
|
||||
* CurrencyExchangeRateController constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -50,7 +50,8 @@ class ImportController extends Controller
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* LinkTypeController constructor.
|
||||
* ImportController constructor.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -71,6 +72,7 @@ class ImportController extends Controller
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function listAll(Request $request): JsonResponse
|
||||
{
|
||||
@ -106,6 +108,7 @@ class ImportController extends Controller
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, ImportJob $importJob): JsonResponse
|
||||
{
|
||||
@ -129,6 +132,7 @@ class ImportController extends Controller
|
||||
* @param ImportJob $importJob
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function transactions(Request $request, ImportJob $importJob): JsonResponse
|
||||
{
|
||||
|
@ -58,6 +58,8 @@ class LinkTypeController extends Controller
|
||||
|
||||
/**
|
||||
* LinkTypeController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -82,6 +84,7 @@ class LinkTypeController extends Controller
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function delete(LinkType $linkType): JsonResponse
|
||||
{
|
||||
@ -98,7 +101,8 @@ class LinkTypeController extends Controller
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse]
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -137,6 +141,7 @@ class LinkTypeController extends Controller
|
||||
* @param LinkType $linkType
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, LinkType $linkType): JsonResponse
|
||||
{
|
||||
@ -192,6 +197,7 @@ class LinkTypeController extends Controller
|
||||
* @param LinkType $linkType
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function transactions(Request $request, LinkType $linkType): JsonResponse
|
||||
{
|
||||
|
@ -52,6 +52,8 @@ class PiggyBankController extends Controller
|
||||
|
||||
/**
|
||||
* PiggyBankController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -76,6 +78,7 @@ class PiggyBankController extends Controller
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function delete(PiggyBank $piggyBank): JsonResponse
|
||||
{
|
||||
@ -89,7 +92,8 @@ class PiggyBankController extends Controller
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse]
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -130,6 +134,7 @@ class PiggyBankController extends Controller
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function piggyBankEvents(Request $request, PiggyBank $piggyBank): JsonResponse
|
||||
{
|
||||
@ -165,6 +170,7 @@ class PiggyBankController extends Controller
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, PiggyBank $piggyBank): JsonResponse
|
||||
{
|
||||
|
@ -45,6 +45,8 @@ class PreferenceController extends Controller
|
||||
{
|
||||
/**
|
||||
* LinkTypeController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -76,7 +78,8 @@ class PreferenceController extends Controller
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse]
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -111,7 +114,6 @@ class PreferenceController extends Controller
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,6 +124,7 @@ class PreferenceController extends Controller
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, Preference $preference): JsonResponse
|
||||
{
|
||||
|
@ -23,7 +23,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Controllers;
|
||||
|
||||
use FireflyIII\Api\V1\Requests\RecurrenceRequest;
|
||||
use FireflyIII\Api\V1\Requests\RecurrenceStoreRequest;
|
||||
use FireflyIII\Api\V1\Requests\RecurrenceUpdateRequest;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\Recurrence;
|
||||
@ -54,6 +55,8 @@ class RecurrenceController extends Controller
|
||||
|
||||
/**
|
||||
* RecurrenceController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -78,6 +81,7 @@ class RecurrenceController extends Controller
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function delete(Recurrence $recurrence): JsonResponse
|
||||
{
|
||||
@ -91,7 +95,8 @@ class RecurrenceController extends Controller
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse]
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -132,6 +137,7 @@ class RecurrenceController extends Controller
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, Recurrence $recurrence): JsonResponse
|
||||
{
|
||||
@ -153,11 +159,11 @@ class RecurrenceController extends Controller
|
||||
/**
|
||||
* Store new object.
|
||||
*
|
||||
* @param RecurrenceRequest $request
|
||||
* @param RecurrenceStoreRequest $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function store(RecurrenceRequest $request): JsonResponse
|
||||
public function store(RecurrenceStoreRequest $request): JsonResponse
|
||||
{
|
||||
$recurrence = $this->repository->store($request->getAll());
|
||||
$manager = new Manager();
|
||||
@ -180,6 +186,7 @@ class RecurrenceController extends Controller
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function transactions(Request $request, Recurrence $recurrence): JsonResponse
|
||||
{
|
||||
@ -234,6 +241,7 @@ class RecurrenceController extends Controller
|
||||
/**
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function trigger(): JsonResponse
|
||||
{
|
||||
@ -258,12 +266,12 @@ class RecurrenceController extends Controller
|
||||
/**
|
||||
* Update single recurrence.
|
||||
*
|
||||
* @param RecurrenceRequest $request
|
||||
* @param RecurrenceUpdateRequest $request
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(RecurrenceRequest $request, Recurrence $recurrence): JsonResponse
|
||||
public function update(RecurrenceUpdateRequest $request, Recurrence $recurrence): JsonResponse
|
||||
{
|
||||
$data = $request->getAll();
|
||||
$category = $this->repository->update($recurrence, $data);
|
||||
|
@ -45,7 +45,7 @@ use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\Serializer\JsonApiSerializer;
|
||||
use Log;
|
||||
|
||||
use Exception;
|
||||
/**
|
||||
* Class RuleController
|
||||
*/
|
||||
@ -58,6 +58,7 @@ class RuleController extends Controller
|
||||
|
||||
/**
|
||||
* RuleController constructor.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -84,6 +85,7 @@ class RuleController extends Controller
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function delete(Rule $rule): JsonResponse
|
||||
{
|
||||
@ -97,7 +99,8 @@ class RuleController extends Controller
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse]
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -138,6 +141,7 @@ class RuleController extends Controller
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, Rule $rule): JsonResponse
|
||||
{
|
||||
@ -252,6 +256,7 @@ class RuleController extends Controller
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function triggerRule(Request $request, Rule $rule): JsonResponse
|
||||
{
|
||||
|
@ -47,7 +47,7 @@ use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\Serializer\JsonApiSerializer;
|
||||
use Log;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Class RuleGroupController
|
||||
@ -61,6 +61,7 @@ class RuleGroupController extends Controller
|
||||
|
||||
/**
|
||||
* RuleGroupController constructor.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -87,6 +88,7 @@ class RuleGroupController extends Controller
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function delete(RuleGroup $ruleGroup): JsonResponse
|
||||
{
|
||||
@ -100,7 +102,8 @@ class RuleGroupController extends Controller
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse]
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -138,6 +141,7 @@ class RuleGroupController extends Controller
|
||||
* @param RuleGroup $group
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function rules(Request $request, RuleGroup $group): JsonResponse
|
||||
{
|
||||
@ -178,6 +182,7 @@ class RuleGroupController extends Controller
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, RuleGroup $ruleGroup): JsonResponse
|
||||
{
|
||||
@ -286,6 +291,7 @@ class RuleGroupController extends Controller
|
||||
* @param RuleGroup $group
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function triggerGroup(Request $request, RuleGroup $group): JsonResponse
|
||||
{
|
||||
|
@ -58,7 +58,8 @@ class SummaryController extends Controller
|
||||
private $currencyRepos;
|
||||
|
||||
/**
|
||||
* AccountController constructor.
|
||||
* SummaryController constructor.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -88,6 +89,7 @@ class SummaryController extends Controller
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function basic(Request $request): JsonResponse
|
||||
{
|
||||
|
@ -54,6 +54,8 @@ class TagController extends Controller
|
||||
|
||||
/**
|
||||
* RuleController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -126,6 +128,7 @@ class TagController extends Controller
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function delete(Tag $tag): JsonResponse
|
||||
{
|
||||
@ -139,7 +142,8 @@ class TagController extends Controller
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse]
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -179,6 +183,7 @@ class TagController extends Controller
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, Tag $tag): JsonResponse
|
||||
{
|
||||
@ -226,6 +231,7 @@ class TagController extends Controller
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function transactions(Request $request, Tag $tag): JsonResponse
|
||||
{
|
||||
|
@ -63,6 +63,8 @@ class TransactionController extends Controller
|
||||
|
||||
/**
|
||||
* TransactionController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -87,6 +89,7 @@ class TransactionController extends Controller
|
||||
* @param TransactionJournal $transactionJournal
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function attachments(Request $request, TransactionJournal $transactionJournal): JsonResponse
|
||||
{
|
||||
@ -112,6 +115,7 @@ class TransactionController extends Controller
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function delete(TransactionGroup $transactionGroup): JsonResponse
|
||||
{
|
||||
@ -125,6 +129,7 @@ class TransactionController extends Controller
|
||||
*
|
||||
* @param TransactionJournal $transactionJournal
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function deleteJournal(TransactionJournal $transactionJournal): JsonResponse
|
||||
@ -140,6 +145,7 @@ class TransactionController extends Controller
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -192,6 +198,7 @@ class TransactionController extends Controller
|
||||
* @param TransactionJournal $transactionJournal
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function piggyBankEvents(Request $request, TransactionJournal $transactionJournal): JsonResponse
|
||||
{
|
||||
@ -218,6 +225,7 @@ class TransactionController extends Controller
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, TransactionGroup $transactionGroup): JsonResponse
|
||||
{
|
||||
@ -252,7 +260,7 @@ class TransactionController extends Controller
|
||||
/**
|
||||
* Store a new transaction.
|
||||
*
|
||||
* @param TransactionStoreRequest $request
|
||||
* @param TransactionStoreRequest $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
|
@ -53,7 +53,8 @@ class TransactionLinkController extends Controller
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* JournalLinkController constructor.
|
||||
* TransactionLinkController constructor.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -80,6 +81,7 @@ class TransactionLinkController extends Controller
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function delete(TransactionJournalLink $link): JsonResponse
|
||||
{
|
||||
@ -93,7 +95,8 @@ class TransactionLinkController extends Controller
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse]
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -138,6 +141,7 @@ class TransactionLinkController extends Controller
|
||||
* @param TransactionJournalLink $journalLink
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, TransactionJournalLink $journalLink): JsonResponse
|
||||
{
|
||||
|
@ -52,6 +52,7 @@ class UserController extends Controller
|
||||
|
||||
/**
|
||||
* UserController constructor.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@ -73,6 +74,7 @@ class UserController extends Controller
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function delete(User $user): JsonResponse
|
||||
{
|
||||
@ -92,6 +94,7 @@ class UserController extends Controller
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@ -130,6 +133,7 @@ class UserController extends Controller
|
||||
* @param User $user
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function show(Request $request, User $user): JsonResponse
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ use FireflyIII\Rules\IsBoolean;
|
||||
|
||||
/**
|
||||
* Class AccountStoreRequest
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class AccountStoreRequest extends Request
|
||||
{
|
||||
@ -48,7 +49,6 @@ class AccountStoreRequest extends Request
|
||||
* Get all data from the request.
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAll(): array
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ use FireflyIII\Rules\IsBoolean;
|
||||
|
||||
/**
|
||||
* Class AccountUpdateRequest
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class AccountUpdateRequest extends Request
|
||||
{
|
||||
@ -48,7 +49,6 @@ class AccountUpdateRequest extends Request
|
||||
* Get all data from the request.
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAll(): array
|
||||
{
|
||||
|
@ -31,6 +31,7 @@ use FireflyIII\Rules\IsValidAttachmentModel;
|
||||
|
||||
/**
|
||||
* Class AttachmentRequest
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class AttachmentRequest extends Request
|
||||
{
|
||||
@ -73,7 +74,6 @@ class AttachmentRequest extends Request
|
||||
str_replace('FireflyIII\\Models\\', '', Bill::class),
|
||||
str_replace('FireflyIII\\Models\\', '', ImportJob::class),
|
||||
str_replace('FireflyIII\\Models\\', '', TransactionJournal::class),
|
||||
str_replace('FireflyIII\\Models\\', '', Transaction::class),
|
||||
]
|
||||
);
|
||||
$model = $this->string('model');
|
||||
|
@ -23,8 +23,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Requests;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Class AvailableBudgetRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class AvailableBudgetRequest extends Request
|
||||
{
|
||||
|
@ -29,6 +29,8 @@ use Illuminate\Validation\Validator;
|
||||
|
||||
/**
|
||||
* Class BillRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class BillRequest extends Request
|
||||
{
|
||||
@ -108,7 +110,7 @@ class BillRequest extends Request
|
||||
/**
|
||||
* Configure the validator instance.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@ -23,9 +23,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Requests;
|
||||
|
||||
|
||||
/**
|
||||
* Class BudgetLimitRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class BudgetLimitRequest extends Request
|
||||
{
|
||||
|
@ -28,6 +28,7 @@ use FireflyIII\Rules\IsBoolean;
|
||||
|
||||
/**
|
||||
* Class BudgetRequest
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class BudgetRequest extends Request
|
||||
{
|
||||
|
@ -27,6 +27,7 @@ use FireflyIII\Models\Category;
|
||||
|
||||
/**
|
||||
* Class CategoryRequest
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class CategoryRequest extends Request
|
||||
{
|
||||
|
@ -28,6 +28,7 @@ use FireflyIII\Rules\IsBoolean;
|
||||
|
||||
/**
|
||||
* Class ConfigurationRequest
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class ConfigurationRequest extends Request
|
||||
{
|
||||
|
@ -28,6 +28,7 @@ use FireflyIII\Rules\IsBoolean;
|
||||
|
||||
/**
|
||||
* Class CurrencyRequest
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class CurrencyRequest extends Request
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ use Illuminate\Validation\Rule;
|
||||
/**
|
||||
*
|
||||
* Class LinkTypeRequest
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class LinkTypeRequest extends Request
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ use FireflyIII\Rules\IsAssetAccountId;
|
||||
/**
|
||||
*
|
||||
* Class PiggyBankRequest
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class PiggyBankRequest extends Request
|
||||
{
|
||||
|
@ -26,6 +26,7 @@ namespace FireflyIII\Api\V1\Requests;
|
||||
/**
|
||||
*
|
||||
* Class PreferenceRequest
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class PreferenceRequest extends Request
|
||||
{
|
||||
|
214
app/Api/V1/Requests/RecurrenceStoreRequest.php
Normal file
214
app/Api/V1/Requests/RecurrenceStoreRequest.php
Normal file
@ -0,0 +1,214 @@
|
||||
<?php
|
||||
/**
|
||||
* RecurrenceStoreRequest.php
|
||||
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Requests;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Rules\BelongsUser;
|
||||
use FireflyIII\Rules\IsBoolean;
|
||||
use FireflyIII\Validation\RecurrenceValidation;
|
||||
use FireflyIII\Validation\TransactionValidation;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
/**
|
||||
* Class RecurrenceStoreRequest
|
||||
*/
|
||||
class RecurrenceStoreRequest extends Request
|
||||
{
|
||||
use RecurrenceValidation, TransactionValidation;
|
||||
|
||||
/**
|
||||
* Authorize logged in users.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
// Only allow authenticated users
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all data from the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll(): array
|
||||
{
|
||||
$active = true;
|
||||
$applyRules = true;
|
||||
if (null !== $this->get('active')) {
|
||||
$active = $this->boolean('active');
|
||||
}
|
||||
if (null !== $this->get('apply_rules')) {
|
||||
$applyRules = $this->boolean('apply_rules');
|
||||
}
|
||||
$return = [
|
||||
'recurrence' => [
|
||||
'type' => $this->string('type'),
|
||||
'title' => $this->string('title'),
|
||||
'description' => $this->string('description'),
|
||||
'first_date' => $this->date('first_date'),
|
||||
'repeat_until' => $this->date('repeat_until'),
|
||||
'repetitions' => $this->integer('nr_of_repetitions'),
|
||||
'apply_rules' => $applyRules,
|
||||
'active' => $active,
|
||||
],
|
||||
'meta' => [
|
||||
'piggy_bank_id' => $this->integer('piggy_bank_id'),
|
||||
'piggy_bank_name' => $this->string('piggy_bank_name'),
|
||||
'tags' => explode(',', $this->string('tags')),
|
||||
],
|
||||
'transactions' => $this->getTransactionData(),
|
||||
'repetitions' => $this->getRepetitionData(),
|
||||
];
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* The rules that the incoming request must be matched against.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$today = Carbon::now()->addDay();
|
||||
|
||||
return [
|
||||
'type' => 'required|in:withdrawal,transfer,deposit',
|
||||
'title' => 'required|between:1,255|uniqueObjectForUser:recurrences,title',
|
||||
'description' => 'between:1,65000',
|
||||
'first_date' => sprintf('required|date|after:%s', $today->format('Y-m-d')),
|
||||
'apply_rules' => [new IsBoolean],
|
||||
'active' => [new IsBoolean],
|
||||
'repeat_until' => sprintf('date|after:%s', $today->format('Y-m-d')),
|
||||
'nr_of_repetitions' => 'numeric|between:1,31',
|
||||
'tags' => 'between:1,64000',
|
||||
'piggy_bank_id' => 'numeric',
|
||||
'repetitions.*.type' => 'required|in:daily,weekly,ndom,monthly,yearly',
|
||||
'repetitions.*.moment' => 'between:0,10',
|
||||
'repetitions.*.skip' => 'required|numeric|between:0,31',
|
||||
'repetitions.*.weekend' => 'required|numeric|min:1|max:4',
|
||||
'transactions.*.description' => 'required|between:1,255',
|
||||
'transactions.*.amount' => 'required|numeric|more:0',
|
||||
'transactions.*.foreign_amount' => 'numeric|more:0',
|
||||
'transactions.*.currency_id' => 'numeric|exists:transaction_currencies,id',
|
||||
'transactions.*.currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
|
||||
'transactions.*.foreign_currency_id' => 'numeric|exists:transaction_currencies,id',
|
||||
'transactions.*.foreign_currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
|
||||
'transactions.*.budget_id' => ['mustExist:budgets,id', new BelongsUser],
|
||||
'transactions.*.category_name' => 'between:1,255|nullable',
|
||||
'transactions.*.source_id' => ['numeric', 'nullable', new BelongsUser],
|
||||
'transactions.*.source_name' => 'between:1,255|nullable',
|
||||
'transactions.*.destination_id' => ['numeric', 'nullable', new BelongsUser],
|
||||
'transactions.*.destination_name' => 'between:1,255|nullable',
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the validator instance.
|
||||
*
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(
|
||||
function (Validator $validator) {
|
||||
$this->validateOneTransaction($validator);
|
||||
$this->validateOneRepetition($validator);
|
||||
$this->validateRecurrenceRepetition($validator);
|
||||
$this->validateRepetitionMoment($validator);
|
||||
$this->validateForeignCurrencyInformation($validator);
|
||||
$this->validateAccountInformation($validator);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the repetition data as it is found in the submitted data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getRepetitionData(): array
|
||||
{
|
||||
$return = [];
|
||||
// repetition data:
|
||||
/** @var array $repetitions */
|
||||
$repetitions = $this->get('repetitions');
|
||||
/** @var array $repetition */
|
||||
foreach ($repetitions as $repetition) {
|
||||
$return[] = [
|
||||
'type' => $repetition['type'],
|
||||
'moment' => $repetition['moment'],
|
||||
'skip' => (int)$repetition['skip'],
|
||||
'weekend' => (int)$repetition['weekend'],
|
||||
];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
|
||||
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
|
||||
*
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
private function getTransactionData(): array
|
||||
{
|
||||
$return = [];
|
||||
// transaction data:
|
||||
/** @var array $transactions */
|
||||
$transactions = $this->get('transactions');
|
||||
/** @var array $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$return[] = [
|
||||
'amount' => $transaction['amount'],
|
||||
'currency_id' => isset($transaction['currency_id']) ? (int)$transaction['currency_id'] : null,
|
||||
'currency_code' => $transaction['currency_code'] ?? null,
|
||||
'foreign_amount' => $transaction['foreign_amount'] ?? null,
|
||||
'foreign_currency_id' => isset($transaction['foreign_currency_id']) ? (int)$transaction['foreign_currency_id'] : null,
|
||||
'foreign_currency_code' => $transaction['foreign_currency_code'] ?? null,
|
||||
'budget_id' => isset($transaction['budget_id']) ? (int)$transaction['budget_id'] : null,
|
||||
'budget_name' => $transaction['budget_name'] ?? null,
|
||||
'category_id' => isset($transaction['category_id']) ? (int)$transaction['category_id'] : null,
|
||||
'category_name' => $transaction['category_name'] ?? null,
|
||||
'source_id' => isset($transaction['source_id']) ? (int)$transaction['source_id'] : null,
|
||||
'source_name' => isset($transaction['source_name']) ? (string)$transaction['source_name'] : null,
|
||||
'destination_id' => isset($transaction['destination_id']) ? (int)$transaction['destination_id'] : null,
|
||||
'destination_name' => isset($transaction['destination_name']) ? (string)$transaction['destination_name'] : null,
|
||||
'description' => $transaction['description'],
|
||||
];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* RecurrenceRequest.php
|
||||
* RecurrenceUpdateRequest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
@ -31,9 +31,9 @@ use FireflyIII\Validation\TransactionValidation;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
/**
|
||||
* Class RecurrenceRequest
|
||||
* Class RecurrenceUpdateRequest
|
||||
*/
|
||||
class RecurrenceRequest extends Request
|
||||
class RecurrenceUpdateRequest extends Request
|
||||
{
|
||||
use RecurrenceValidation, TransactionValidation;
|
||||
|
@ -32,6 +32,7 @@ use FireflyIII\Http\Requests\Request as FireflyIIIRequest;
|
||||
* Technically speaking this class does not have to be extended like this but who knows what the future brings.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.NumberOfChildren)
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Request extends FireflyIIIRequest
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ use FireflyIII\Rules\IsBoolean;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* Class RuleGroupRequest
|
||||
*/
|
||||
class RuleGroupRequest extends Request
|
||||
|
@ -28,6 +28,10 @@ use FireflyIII\Models\Tag;
|
||||
|
||||
/**
|
||||
* Class TagRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* TODO split in store / update
|
||||
*/
|
||||
class TagRequest extends Request
|
||||
{
|
||||
|
@ -31,6 +31,7 @@ use FireflyIII\User;
|
||||
|
||||
/**
|
||||
* Class UserRequest
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class UserRequest extends Request
|
||||
{
|
||||
|
@ -215,11 +215,17 @@ class Request extends FormRequest
|
||||
* @param string $field
|
||||
*
|
||||
* @return Carbon|null
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function date(string $field): ?Carbon
|
||||
{
|
||||
return $this->get($field) ? new Carbon($this->get($field)) : null;
|
||||
$result = null;
|
||||
try {
|
||||
$result = $this->get($field) ? new Carbon($this->get($field)) : null;
|
||||
} catch (Exception $e) {
|
||||
Log::debug(sprintf('Exception when parsing date. Not interesting: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,92 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* AboutControllerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use FireflyIII\Transformers\UserTransformer;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class AboutControllerTest.
|
||||
*/
|
||||
class AboutControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Set up test
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Passport::actingAs($this->user());
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the about endpoint
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AboutController
|
||||
*/
|
||||
public function testAbout(): void
|
||||
{
|
||||
|
||||
$search = ['~', '#'];
|
||||
$replace = ['\~', '# '];
|
||||
$phpVersion = str_replace($search, $replace, PHP_VERSION);
|
||||
$phpOs = str_replace($search, $replace, PHP_OS);
|
||||
$response = $this->get(route('api.v1.about.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
['data' => [
|
||||
'version' => config('firefly.version'),
|
||||
'api_version' => config('firefly.api_version'),
|
||||
'php_version' => $phpVersion,
|
||||
'os' => $phpOs,
|
||||
'driver' => 'sqlite',
|
||||
]]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test user end point
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AboutController
|
||||
*/
|
||||
public function testUser(): void
|
||||
{
|
||||
$transformer = $this->mock(UserTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
$response = $this->get(route('api.v1.about.user'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -24,16 +24,9 @@ declare(strict_types=1);
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use FireflyIII\Transformers\AccountTransformer;
|
||||
use FireflyIII\Transformers\PiggyBankTransformer;
|
||||
use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
@ -53,145 +46,10 @@ class AccountControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy account over API.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('destroy')->atLeast()->once()->andReturn(true);
|
||||
|
||||
// get account:
|
||||
$account = $this->getRandomAsset();
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.accounts.delete', [$account->id]));
|
||||
$response->assertStatus(204);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the list of accounts.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// create stuff
|
||||
$accounts = factory(Account::class, 10)->create();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(AccountTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getAccountsByType')->withAnyArgs()->andReturn($accounts)->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/accounts');
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 10, 'count' => 10, 'per_page' => true, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(
|
||||
['links' => ['self' => true, 'first' => true, 'last' => true,],]
|
||||
);
|
||||
$response->assertSee('type=all'); // default returns this.
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the list of piggy banks.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
*/
|
||||
public function testPiggyBanks(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$transformer = $this->mock(PiggyBankTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// get piggies for this user.
|
||||
$piggies = factory(PiggyBank::class, 10)->create();
|
||||
$asset = $this->getRandomAsset();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
$repository->shouldReceive('getPiggyBanks')->andReturn($piggies)->atLeast()->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.accounts.piggy_banks', [$asset->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(
|
||||
['meta' => ['pagination' => ['total' => $piggies->count(), 'count' => $piggies->count(), 'per_page' => true, 'current_page' => 1,
|
||||
'total_pages' => 1]],]
|
||||
);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertSee('page=1'); // default returns this.
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an account.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
*/
|
||||
|
||||
public function testShow(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$account = $this->getRandomAsset();
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$transformer = $this->mock(AccountTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.accounts.show', [$account->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => ['type' => 'accounts', 'links' => true],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Opening balance without date.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreInvalidBalance(): void
|
||||
@ -230,7 +88,6 @@ class AccountControllerTest extends TestCase
|
||||
* Send correct data. Should call account repository store method.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreLiability(): void
|
||||
@ -277,7 +134,7 @@ class AccountControllerTest extends TestCase
|
||||
* CC type present when account is a credit card.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreNoCreditCardData(): void
|
||||
{
|
||||
@ -316,7 +173,6 @@ class AccountControllerTest extends TestCase
|
||||
* No currency information (is allowed).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreNoCurrencyInfo(): void
|
||||
@ -354,13 +210,11 @@ class AccountControllerTest extends TestCase
|
||||
* Name already in use.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
|
||||
*/
|
||||
public function testStoreNotUnique(): void
|
||||
{
|
||||
// mock repositories
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(AccountTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
@ -395,7 +249,6 @@ class AccountControllerTest extends TestCase
|
||||
* Send correct data. Should call account repository store method.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreValid(): void
|
||||
@ -434,7 +287,6 @@ class AccountControllerTest extends TestCase
|
||||
* Send correct data. Should call account repository store method.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreWithCurrencyCode(): void
|
||||
@ -471,138 +323,15 @@ class AccountControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show transactions.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
*/
|
||||
public function testTransactionsBasic(): void
|
||||
{
|
||||
// default mocks
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$transformer = $this->mock(TransactionGroupTransformer::class);
|
||||
|
||||
// objects
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
|
||||
// calls to account repos.
|
||||
$accountRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// mock collector:
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('withAPIInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->withArgs([50])->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn($paginator);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$asset = $this->getRandomAsset();
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.accounts.transactions', [$asset->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show transactions but submit a limit.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
*/
|
||||
public function testTransactionsLimit(): void
|
||||
{
|
||||
// default mocks
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$transformer = $this->mock(TransactionGroupTransformer::class);
|
||||
|
||||
// objects
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
|
||||
// calls to account repos.
|
||||
$accountRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// mock collector:
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('withAPIInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->withArgs([10])->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn($paginator);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$asset = $this->getRandomAsset();
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.accounts.transactions', [$asset->id]) . '?limit=10');
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
*/
|
||||
public function testTransactionsRange(): void
|
||||
{
|
||||
// default mocks
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$transformer = $this->mock(TransactionGroupTransformer::class);
|
||||
|
||||
// objects
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
|
||||
// calls to account repos.
|
||||
$accountRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// mock collector:
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('withAPIInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn($paginator);
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$asset = $this->getRandomAsset();
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.accounts.transactions', [$asset->id]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update first asset account we find. Name can be the same as it was.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountUpdateRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
// mock repositories
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$transformer = $this->mock(AccountTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
@ -639,7 +368,6 @@ class AccountControllerTest extends TestCase
|
||||
* Update first asset account we find. Name can be the same as it was.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountUpdateRequest
|
||||
*/
|
||||
public function testUpdateCurrencyCode(): void
|
||||
{
|
||||
@ -681,7 +409,6 @@ class AccountControllerTest extends TestCase
|
||||
* Update a liability
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountUpdateRequest
|
||||
*/
|
||||
public function testUpdateLiability(): void
|
||||
{
|
||||
|
@ -23,11 +23,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use Exception;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Transformers\AttachmentTransformer;
|
||||
use Laravel\Passport\Passport;
|
||||
@ -50,202 +48,11 @@ class AttachmentControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy account over API.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get attachment:
|
||||
$attachment = $this->user()->attachments()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.attachments.delete', [$attachment->id]));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download attachment
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
*/
|
||||
public function testDownload(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
$content = 'Attachment content ' . random_int(100, 1000);
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('exists')->andReturn(true)->once();
|
||||
$repository->shouldReceive('getContent')->andReturn($content)->once();
|
||||
|
||||
// get attachment:
|
||||
$attachment = $this->user()->attachments()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.attachments.download', [$attachment->id]));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee($content);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Download attachment but file doesn't exist.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
*/
|
||||
public function testDownloadNotExisting(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
$content = 'Attachment content ' . random_int(100, 1000);
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('exists')->andReturn(false)->once();
|
||||
|
||||
// get attachment:
|
||||
$attachment = $this->user()->attachments()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.attachments.download', [$attachment->id]));
|
||||
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Could not find the indicated attachment. The file is no longer there.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Download attachment but no file uploaded
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
*/
|
||||
public function testDownloadNotUploaded(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// create attachment
|
||||
$attachment = Attachment::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'attachable_id' => 1,
|
||||
'attachable_type' => TransactionJournal::class,
|
||||
'md5' => md5('Hello' . random_int(1, 10000)),
|
||||
'filename' => 'some name',
|
||||
'mime' => 'text/plain',
|
||||
'size' => 5,
|
||||
'uploaded' => false,
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.attachments.download', [$attachment->id]));
|
||||
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('No file has been uploaded for this attachment (yet).');
|
||||
}
|
||||
|
||||
/**
|
||||
* List all attachments.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// create stuff
|
||||
$attachments = factory(Attachment::class, 10)->create();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('get')->once()->andReturn($attachments);
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.attachments.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 10, 'count' => 10, 'per_page' => true, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* List one attachment.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
/** @var Attachment $attachment */
|
||||
$attachment = $this->user()->attachments()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.attachments.show', [$attachment->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => ['type' => 'attachments', 'links' => true],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store a new attachment.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AttachmentRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
@ -253,10 +60,9 @@ class AttachmentControllerTest extends TestCase
|
||||
$attachment = $this->user()->attachments()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
@ -295,14 +101,13 @@ class AttachmentControllerTest extends TestCase
|
||||
* Update an attachment.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AttachmentRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
// mock repositories
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
@ -333,31 +138,6 @@ class AttachmentControllerTest extends TestCase
|
||||
$response->assertJson(['data' => ['type' => 'attachments', 'links' => true],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload file for attachment.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
*
|
||||
*/
|
||||
public function testUpload(): void
|
||||
{
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
|
||||
/** @var Attachment $attachment */
|
||||
$attachment = $this->user()->attachments()->first();
|
||||
$content = 'Hello there';
|
||||
// mock helper:
|
||||
$helper = $this->mock(AttachmentHelperInterface::class);
|
||||
$helper->shouldReceive('saveAttachmentFromApi')->once();
|
||||
|
||||
$response = $this->call('POST', route('api.v1.attachments.upload', [$attachment->id]), [], [], [], [], $content);
|
||||
//$response = $this->post('/api/v1/attachments/' . $attachment->id . '/upload',$content, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
}
|
||||
|
@ -51,102 +51,14 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an available budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('destroyAvailableBudget')->once()->andReturn(true);
|
||||
|
||||
// get available budget:
|
||||
$availableBudget = $this->user()->availableBudgets()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.available_budgets.delete', [$availableBudget->id]));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all available budgets.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$availableBudgets = $this->user()->availableBudgets()->get();
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getAvailableBudgets')->once()->andReturn($availableBudgets);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.available_budgets.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee($availableBudgets->first()->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show one available budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$availableBudget = $this->user()->availableBudgets()->first();
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.available_budgets.show', [$availableBudget->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee($availableBudget->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store new available budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AvailableBudgetRequest
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$availableBudget = new AvailableBudget;
|
||||
@ -183,14 +95,12 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
* Store new available budget without a valid currency.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AvailableBudgetRequest
|
||||
*/
|
||||
public function testStoreNoCurrencyAtAll(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$availableBudget = new AvailableBudget;
|
||||
|
||||
@ -226,7 +136,6 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
* Store new available budget without a valid currency.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AvailableBudgetRequest
|
||||
*/
|
||||
public function testStoreNoCurrencyId(): void
|
||||
{
|
||||
@ -237,7 +146,6 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
@ -273,7 +181,6 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
* Update available budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AvailableBudgetRequest
|
||||
*
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
|
@ -24,18 +24,9 @@ declare(strict_types=1);
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
||||
use Exception;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Transformers\AttachmentTransformer;
|
||||
use FireflyIII\Transformers\BillTransformer;
|
||||
use FireflyIII\Transformers\RuleTransformer;
|
||||
use FireflyIII\Transformers\TransactionTransformer;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
@ -56,155 +47,17 @@ class BillControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* List all attachments.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
*/
|
||||
public function testAttachments(): void
|
||||
{
|
||||
// create stuff
|
||||
$bill = $this->user()->bills()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$billRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$billRepos->shouldReceive('getAttachments')->once()->andReturn(new Collection);
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.bills.attachments', [$bill->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => true, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send delete
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(BillTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get bill:
|
||||
$bill = $this->user()->bills()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.bills.delete', [$bill->id]));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all bills
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// create stuff
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50, 1);
|
||||
$repository = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(BillTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getPaginator')->withAnyArgs()->andReturn($paginator)->once();
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.bills.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(
|
||||
['links' => ['self' => true, 'first' => true, 'last' => true,],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
*/
|
||||
public function testRules(): void
|
||||
{
|
||||
$bill = $this->user()->bills()->first();
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$billRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$billRepos->shouldReceive('getRulesForBill')->atLeast()->once()->andReturn(new Collection);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.bills.rules', [$bill->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show one bill
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
// create stuff
|
||||
$bill = $this->user()->bills()->first();
|
||||
$repository = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(BillTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.bills.show', [$bill->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
['data' => [
|
||||
'type' => 'bills',
|
||||
],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store with minimum amount more than maximum amount
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BillRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreMinOverMax(): void
|
||||
{
|
||||
// create stuff
|
||||
$bill = $this->user()->bills()->first();
|
||||
$repository = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(BillTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
@ -243,7 +96,7 @@ class BillControllerTest extends TestCase
|
||||
* Store a valid bill
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BillRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreValid(): void
|
||||
{
|
||||
@ -285,110 +138,12 @@ class BillControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
*/
|
||||
public function testTransactionsBasic(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$bill = $this->user()->bills()->first();
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$billRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setBills')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
|
||||
// mock some calls:
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.bills.transactions', [$bill->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
*/
|
||||
public function testTransactionsRange(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$bill = $this->user()->bills()->first();
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$billRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setBills')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
|
||||
// mock some calls:
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.bills.transactions', [$bill->id]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a valid bill.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BillRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testUpdateValid(): void
|
||||
{
|
||||
|
@ -57,100 +57,10 @@ class BudgetControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all budgets
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
*/
|
||||
public function testBudgetLimits(): void
|
||||
{
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once()->atLeast()->once();
|
||||
$repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection());
|
||||
$transformer->shouldReceive('setParameters')->atLeast()->once();
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.budgets.budget_limits', [$budget->id]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get budget:
|
||||
$budget = $this->user()->budgets()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.budgets.delete', [$budget->id]));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all budgets
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getBudgets')->once()->andReturn(new Collection);
|
||||
$transformer->shouldReceive('setParameters')->atLeast()->once();
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.budgets.index'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a single budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.budgets.show', [$budget->id]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a new budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BudgetRequest
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
@ -188,7 +98,6 @@ class BudgetControllerTest extends TestCase
|
||||
* Store new budget limit.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BudgetLimitRequest
|
||||
*/
|
||||
public function testStoreBudgetLimit(): void
|
||||
{
|
||||
@ -225,109 +134,10 @@ class BudgetControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
*/
|
||||
public function testTransactionsBasic(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$billRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$budgetRepos->shouldReceive('setUser');
|
||||
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setBudget')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.budgets.transactions', [$budget->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
*/
|
||||
public function testTransactionsRange(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$billRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$budgetRepos->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setBudget')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.budgets.transactions', [$budget->id]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BudgetRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
|
@ -56,171 +56,10 @@ class BudgetLimitControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroyBudgetLimit')->once()->andReturn(true);
|
||||
|
||||
// Create a budget limit (just in case).
|
||||
/** @var Budget $budget */
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$budgetLimit = BudgetLimit::create(
|
||||
[
|
||||
'budget_id' => $budget->id,
|
||||
'start_date' => '2018-01-01',
|
||||
'end_date' => '2018-01-31',
|
||||
'amount' => 1,
|
||||
]
|
||||
);
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.budget_limits.delete', $budgetLimit->id));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show budget limits by budget, include no dates.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
/** @var Budget $budget */
|
||||
$budget = $this->user()->budgets()->first();
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findNull')->andReturn($budget);
|
||||
$repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection);
|
||||
|
||||
// call API
|
||||
$params = ['budget_id' => $budget->id,];
|
||||
$response = $this->get(route('api.v1.budget_limits.index') . '?' . http_build_query($params));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show budget limits by budget, include dates.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
*/
|
||||
public function testIndexNoBudget(): void
|
||||
{
|
||||
/** @var Budget $budget */
|
||||
$budget = $this->user()->budgets()->first();
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findNull')->andReturn(null);
|
||||
$repository->shouldReceive('getAllBudgetLimits')->once()->andReturn(new Collection);
|
||||
|
||||
// call API
|
||||
$params = [
|
||||
'start' => '2018-01-01',
|
||||
'end' => '2018-01-31',
|
||||
];
|
||||
$uri = route('api.v1.budget_limits.index') . '?' . http_build_query($params);
|
||||
$response = $this->get($uri);
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show budget limits by budget, include dates.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
*/
|
||||
public function testIndexWithDates(): void
|
||||
{
|
||||
/** @var Budget $budget */
|
||||
$budget = $this->user()->budgets()->first();
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findNull')->andReturn($budget);
|
||||
$repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection);
|
||||
|
||||
// call API
|
||||
$params = [
|
||||
'budget_id' => $budget->id,
|
||||
'start' => '2018-01-01',
|
||||
'end' => '2018-01-31',
|
||||
];
|
||||
$response = $this->get(route('api.v1.budget_limits.index') . '?' . http_build_query($params));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
// Create a budget limit (just in case).
|
||||
/** @var Budget $budget */
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$budgetLimit = BudgetLimit::create(
|
||||
[
|
||||
'budget_id' => $budget->id,
|
||||
'start_date' => '2018-01-01',
|
||||
'end_date' => '2018-01-31',
|
||||
'amount' => 1,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
$response = $this->get(route('api.v1.budget_limits.show', $budgetLimit->id));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store new budget limit.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BudgetLimitRequest
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
@ -267,7 +106,6 @@ class BudgetLimitControllerTest extends TestCase
|
||||
* Store new budget limit, but give error
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BudgetLimitRequest
|
||||
*/
|
||||
public function testStoreBadBudget(): void
|
||||
{
|
||||
@ -292,60 +130,10 @@ class BudgetLimitControllerTest extends TestCase
|
||||
$response->assertSee('Unknown budget.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
*/
|
||||
public function testTransactionsBasic(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$budgetLimit = BudgetLimit::first();
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$billRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$budgetRepos->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setBudget')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
// mock some calls:
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.budget_limits.transactions', [$budgetLimit->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update of budget limit.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BudgetLimitRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
|
@ -55,83 +55,10 @@ class CategoryControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a category.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CategoryController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get category:
|
||||
$category = $this->user()->categories()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.categories.delete', $category->id));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all categories
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CategoryController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$transformer = $this->mock(CategoryTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getCategories')->once()->andReturn(new Collection);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.categories.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a single category.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CategoryController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$category = $this->user()->categories()->first();
|
||||
// mock stuff:
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$transformer = $this->mock(CategoryTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.categories.show', [$category->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a new category.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CategoryController
|
||||
* @covers \FireflyIII\Api\V1\Requests\CategoryRequest
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
@ -166,109 +93,10 @@ class CategoryControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CategoryController
|
||||
*/
|
||||
public function testTransactionsBasic(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$category = $this->user()->categories()->first();
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
|
||||
$categoryRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$billRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setCategory')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.categories.transactions', [$category->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CategoryController
|
||||
*/
|
||||
public function testTransactionsRange(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$category = $this->user()->categories()->first();
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
|
||||
$categoryRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$billRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setCategory')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$response = $this->get(
|
||||
route('api.v1.categories.transactions', [$category->id]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31'])
|
||||
);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a category.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CategoryController
|
||||
* @covers \FireflyIII\Api\V1\Requests\CategoryRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
|
@ -1,251 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ConfigurationControllerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use FireflyConfig;
|
||||
use FireflyIII\Models\Configuration;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class ConfigurationControllerTest
|
||||
*/
|
||||
class ConfigurationControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Passport::actingAs($this->user());
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration variables.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ConfigurationController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$demoConfig = new Configuration;
|
||||
$demoConfig->name = 'is_demo_site';
|
||||
$demoConfig->data = false;
|
||||
|
||||
$permConfig = new Configuration;
|
||||
$permConfig->name = 'permission_update_check';
|
||||
$permConfig->data = -1;
|
||||
|
||||
$lastConfig = new Configuration;
|
||||
$lastConfig->name = 'last_update_check';
|
||||
$lastConfig->data = 123456789;
|
||||
|
||||
$singleConfig = new Configuration;
|
||||
$singleConfig->name = 'single_user_mode';
|
||||
$singleConfig->data = true;
|
||||
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site'])->andReturn($demoConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check'])->andReturn($permConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check'])->andReturn($lastConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['single_user_mode'])->andReturn($singleConfig)->once();
|
||||
|
||||
$expected = [
|
||||
'data' => [
|
||||
'is_demo_site' => false,
|
||||
'permission_update_check' => -1,
|
||||
'last_update_check' => 123456789,
|
||||
'single_user_mode' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->get(route('api.v1.configuration.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson($expected);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get configuration variables.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ConfigurationController
|
||||
*/
|
||||
public function testIndexNotOwner(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(false);
|
||||
|
||||
Passport::actingAs($this->emptyUser());
|
||||
$response = $this->get(route('api.v1.configuration.index'));
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('No access to method.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set configuration variables.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ConfigurationController
|
||||
* @covers \FireflyIII\Api\V1\Requests\ConfigurationRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
$data = [
|
||||
'value' => 1,
|
||||
|
||||
];
|
||||
|
||||
$demoConfig = new Configuration;
|
||||
$demoConfig->name = 'is_demo_site';
|
||||
$demoConfig->data = false;
|
||||
|
||||
$permConfig = new Configuration;
|
||||
$permConfig->name = 'permission_update_check';
|
||||
$permConfig->data = -1;
|
||||
|
||||
$lastConfig = new Configuration;
|
||||
$lastConfig->name = 'last_update_check';
|
||||
$lastConfig->data = 123456789;
|
||||
|
||||
$singleConfig = new Configuration;
|
||||
$singleConfig->name = 'single_user_mode';
|
||||
$singleConfig->data = true;
|
||||
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site'])->andReturn($demoConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check'])->andReturn($permConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check'])->andReturn($lastConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['single_user_mode'])->andReturn($singleConfig)->once();
|
||||
FireflyConfig::shouldReceive('set')->once()->withArgs(['permission_update_check', 1]);
|
||||
|
||||
|
||||
$expected = [
|
||||
'data' => [
|
||||
'is_demo_site' => false,
|
||||
'permission_update_check' => -1,
|
||||
'last_update_check' => 123456789,
|
||||
'single_user_mode' => true,
|
||||
],
|
||||
];
|
||||
$response = $this->post(route('api.v1.configuration.update', ['permission_update_check']), $data);
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson($expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set configuration variables.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ConfigurationController
|
||||
* @covers \FireflyIII\Api\V1\Requests\ConfigurationRequest
|
||||
*/
|
||||
public function testUpdateBoolean(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$data = [
|
||||
'value' => 'true',
|
||||
|
||||
];
|
||||
|
||||
$demoConfig = new Configuration;
|
||||
$demoConfig->name = 'is_demo_site';
|
||||
$demoConfig->data = false;
|
||||
|
||||
$permConfig = new Configuration;
|
||||
$permConfig->name = 'permission_update_check';
|
||||
$permConfig->data = -1;
|
||||
|
||||
$lastConfig = new Configuration;
|
||||
$lastConfig->name = 'last_update_check';
|
||||
$lastConfig->data = 123456789;
|
||||
|
||||
$singleConfig = new Configuration;
|
||||
$singleConfig->name = 'single_user_mode';
|
||||
$singleConfig->data = true;
|
||||
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site'])->andReturn($demoConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check'])->andReturn($permConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check'])->andReturn($lastConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['single_user_mode'])->andReturn($singleConfig)->once();
|
||||
FireflyConfig::shouldReceive('set')->once()->withArgs(['single_user_mode', true]);
|
||||
|
||||
|
||||
$expected = [
|
||||
'data' => [
|
||||
'is_demo_site' => false,
|
||||
'permission_update_check' => -1,
|
||||
'last_update_check' => 123456789,
|
||||
'single_user_mode' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->post(route('api.v1.configuration.update', ['single_user_mode']), $data);
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson($expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set configuration variable that you're not allowed to change
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ConfigurationController
|
||||
* @covers \FireflyIII\Api\V1\Requests\ConfigurationRequest
|
||||
*/
|
||||
public function testUpdateInvalid(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$data = [
|
||||
'value' => 'true',
|
||||
];
|
||||
$response = $this->post('/api/v1/configuration/last_update_check', $data);
|
||||
$response->assertStatus(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set configuration variables but you're not the owner.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ConfigurationController
|
||||
* @covers \FireflyIII\Api\V1\Requests\ConfigurationRequest
|
||||
*/
|
||||
public function testUpdateNotOwner(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(false);
|
||||
|
||||
Passport::actingAs($this->emptyUser());
|
||||
$response = $this->post(route('api.v1.configuration.update', ['single_user_mode']));
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('No access to method.');
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -74,450 +74,16 @@ class CurrencyControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the list of accounts.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testAccounts(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$currency = TransactionCurrency::first();
|
||||
$account = $this->getRandomAsset();
|
||||
$collection = new Collection([$account]);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(AccountTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getAccountsByType')->withAnyArgs()->andReturn($collection)->atLeast()->once();
|
||||
$repository->shouldReceive('getMetaValue')->atLeast()->once()->andReturn('1');
|
||||
|
||||
// test API
|
||||
|
||||
$response = $this->get(route('api.v1.currencies.accounts', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 1, 'count' => 1, 'per_page' => true, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(
|
||||
['links' => ['self' => true, 'first' => true, 'last' => true,],]
|
||||
);
|
||||
$response->assertSee('type=all'); // default returns this.
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all available budgets.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testAvailableBudgets(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$collection = new Collection([AvailableBudget::first()]);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$budgetRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$budgetRepos->shouldReceive('getAvailableBudgets')->once()->andReturn($collection);
|
||||
|
||||
// call API
|
||||
$currency = TransactionCurrency::first();
|
||||
$response = $this->get(route('api.v1.currencies.available_budgets', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all bills
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testBills(): void
|
||||
{
|
||||
// create stuff
|
||||
$paginator = new LengthAwarePaginator(new Collection([Bill::first()]), 0, 50, 1);
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BillRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(BillTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getPaginator')->withAnyArgs()->andReturn($paginator)->once();
|
||||
|
||||
// test API
|
||||
$currency = TransactionCurrency::first();
|
||||
$response = $this->get(route('api.v1.currencies.bills', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => true, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testBudgetLimits(): void
|
||||
{
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
$currency = TransactionCurrency::first();
|
||||
$budgetLimit = BudgetLimit::first();
|
||||
$budgetLimit->transaction_currency_id = $currency->id;
|
||||
$collection = new Collection([$budgetLimit]);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('getAllBudgetLimits')->once()->andReturn($collection);
|
||||
$currencyRepos->shouldReceive('setUser')->once();
|
||||
|
||||
$response = $this->get(route('api.v1.currencies.budget_limits', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testCer(): void
|
||||
{
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyExchangeRateTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls
|
||||
$repository->shouldReceive('setUser')->once()->atLeast()->once();
|
||||
$repository->shouldReceive('getExchangeRates')->once()->andReturn(new Collection);
|
||||
|
||||
|
||||
$currency = TransactionCurrency::first();
|
||||
$response = $this->get(route('api.v1.currencies.cer', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send delete
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->once()->withArgs([Mockery::any(), 'owner'])->andReturn(true);
|
||||
$repository->shouldReceive('currencyInUse')->once()->andReturn(false);
|
||||
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get a currency
|
||||
$currency = TransactionCurrency::first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/currencies/' . $currency->code);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testDisable(): void
|
||||
{
|
||||
// create stuff
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('disable')->once();
|
||||
$repository->shouldReceive('currencyInUse')->once()->andReturnFalse();
|
||||
|
||||
// test API
|
||||
$response = $this->post(route('api.v1.currencies.disable', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
['data' => [
|
||||
'type' => 'currencies',
|
||||
],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testDisableInUse(): void
|
||||
{
|
||||
// create stuff
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('currencyInUse')->once()->andReturnTrue();
|
||||
|
||||
// test API
|
||||
$response = $this->post(route('api.v1.currencies.disable', [$currency->code]));
|
||||
$response->assertStatus(409);
|
||||
$response->assertJson([]);
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testEnable(): void
|
||||
{
|
||||
// create stuff
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('enable')->once();
|
||||
|
||||
// test API
|
||||
$response = $this->post(route('api.v1.currencies.enable', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
['data' => [
|
||||
'type' => 'currencies',
|
||||
],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('getAll')->withNoArgs()->andReturn(new Collection)->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/currencies');
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(
|
||||
[
|
||||
'meta' => [
|
||||
'pagination' => [
|
||||
'total' => 0,
|
||||
'count' => 0,
|
||||
'per_page' => true, // depends on user preference.
|
||||
'current_page' => 1,
|
||||
'total_pages' => 1,
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
$response->assertJson(
|
||||
['links' => ['self' => true, 'first' => true, 'last' => true,],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testMakeDefault(): void
|
||||
{
|
||||
// create stuff
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('enable')->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// test API
|
||||
$response = $this->post(route('api.v1.currencies.default', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
['data' => [
|
||||
'type' => 'currencies',
|
||||
],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testRecurrences(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$recurrence = Recurrence::first();
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(RecurrenceTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$currencyRepos->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setUser');
|
||||
$repository->shouldReceive('getAll')->once()->andReturn(new Collection([$recurrence]));
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// call API
|
||||
$currency = TransactionCurrency::first();
|
||||
$response = $this->get(route('api.v1.currencies.recurrences', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testRules(): void
|
||||
{
|
||||
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleTransformer::class);
|
||||
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$ruleRepos->shouldReceive('getAll')->once()->andReturn(new Collection([Rule::first()]));
|
||||
$currencyRepos->shouldReceive('setUser')->once();
|
||||
|
||||
// call API
|
||||
$currency = TransactionCurrency::first();
|
||||
$response = $this->get(route('api.v1.currencies.rules', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test show of a currency.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
// create stuff
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/currencies/' . $currency->code);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
['data' => [
|
||||
'type' => 'currencies',
|
||||
],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store new currency.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
* @covers \FireflyIII\Api\V1\Requests\CurrencyRequest
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
@ -552,13 +118,11 @@ class CurrencyControllerTest extends TestCase
|
||||
* Store new currency and make it default.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
* @covers \FireflyIII\Api\V1\Requests\CurrencyRequest
|
||||
*/
|
||||
public function testStoreWithDefault(): void
|
||||
{
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
@ -595,110 +159,15 @@ class CurrencyControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testTransactionsBasic(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$currency = TransactionCurrency::first();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setCurrency')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.currencies.transactions', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testTransactionsRange(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$currency = TransactionCurrency::first();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setCurrency')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
|
||||
// test API
|
||||
$response = $this->get(
|
||||
route('api.v1.currencies.transactions', [$currency->code]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31'])
|
||||
);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update currency.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
* @covers \FireflyIII\Api\V1\Requests\CurrencyRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
@ -733,13 +202,11 @@ class CurrencyControllerTest extends TestCase
|
||||
* Update currency and make default.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
* @covers \FireflyIII\Api\V1\Requests\CurrencyRequest
|
||||
*/
|
||||
public function testUpdateWithDefault(): void
|
||||
{
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
$preference = new Preference;
|
||||
$preference->data = 'EUR';
|
||||
|
@ -1,173 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CurrencyExchangeRateControllerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\CurrencyExchangeRate;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Services\Currency\ExchangeRateInterface;
|
||||
use FireflyIII\Transformers\CurrencyExchangeRateTransformer;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class CurrencyExchangeRateControllerTest
|
||||
*/
|
||||
class CurrencyExchangeRateControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Passport::actingAs($this->user());
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyExchangeRateController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// mock repository
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$service = $this->mock(ExchangeRateInterface::class);
|
||||
$transformer = $this->mock(CurrencyExchangeRateTransformer::class);
|
||||
|
||||
$rate = new CurrencyExchangeRate();
|
||||
$rate->date = new Carbon();
|
||||
$rate->updated_at = new Carbon();
|
||||
$rate->created_at = new Carbon();
|
||||
$rate->rate = '0.5';
|
||||
$rate->to_currency_id = 1;
|
||||
$rate->from_currency_id = 2;
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(TransactionCurrency::whereCode('EUR')->first())->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['USD'])->andReturn(TransactionCurrency::whereCode('USD')->first())->once();
|
||||
$repository->shouldReceive('getExchangeRate')->andReturn(null)->once();
|
||||
$service->shouldReceive('setUser')->once();
|
||||
$service->shouldReceive('getRate')->once()->andReturn($rate);
|
||||
|
||||
// test API
|
||||
$params = [
|
||||
'from' => 'EUR',
|
||||
'to' => 'USD',
|
||||
'date' => '2018-01-01',
|
||||
];
|
||||
$response = $this->get('/api/v1/cer?' . http_build_query($params));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
['data' => [
|
||||
'type' => 'currency_exchange_rates',
|
||||
],
|
||||
]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyExchangeRateController
|
||||
*/
|
||||
public function testIndexBadDestination(): void
|
||||
{
|
||||
// mock repository
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$service = $this->mock(ExchangeRateInterface::class);
|
||||
$transformer = $this->mock(CurrencyExchangeRateTransformer::class);
|
||||
|
||||
$rate = new CurrencyExchangeRate();
|
||||
$rate->date = new Carbon();
|
||||
$rate->updated_at = new Carbon();
|
||||
$rate->created_at = new Carbon();
|
||||
$rate->rate = '0.5';
|
||||
$rate->to_currency_id = 1;
|
||||
$rate->from_currency_id = 2;
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(TransactionCurrency::whereCode('USD')->first())->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['USD'])->andReturn(null)->once();
|
||||
|
||||
// test API
|
||||
$params = [
|
||||
'from' => 'EUR',
|
||||
'to' => 'USD',
|
||||
'date' => '2018-01-01',
|
||||
];
|
||||
$response = $this->get('/api/v1/cer?' . http_build_query($params), ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Unknown destination currency.');
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyExchangeRateController
|
||||
*/
|
||||
public function testIndexBadSource(): void
|
||||
{
|
||||
// mock repository
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$service = $this->mock(ExchangeRateInterface::class);
|
||||
$transformer = $this->mock(CurrencyExchangeRateTransformer::class);
|
||||
|
||||
$rate = new CurrencyExchangeRate();
|
||||
$rate->date = new Carbon();
|
||||
$rate->updated_at = new Carbon();
|
||||
$rate->created_at = new Carbon();
|
||||
$rate->rate = '0.5';
|
||||
$rate->to_currency_id = 1;
|
||||
$rate->from_currency_id = 2;
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(null)->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['USD'])->andReturn(TransactionCurrency::whereCode('USD')->first())->once();
|
||||
|
||||
// test API
|
||||
$params = [
|
||||
'from' => 'EUR',
|
||||
'to' => 'USD',
|
||||
'date' => '2018-01-01',
|
||||
];
|
||||
$response = $this->get('/api/v1/cer?' . http_build_query($params), ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Unknown source currency.');
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -1,138 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ImportControllerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Transformers\ImportJobTransformer;
|
||||
use FireflyIII\Transformers\TransactionTransformer;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class ImportControllerTest
|
||||
*/
|
||||
class ImportControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Passport::actingAs($this->user());
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ImportController
|
||||
*/
|
||||
public function testListAll(): void
|
||||
{
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$transformer = $this->mock(ImportJobTransformer::class);
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('get')->once()->andReturn(new Collection);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
|
||||
$response = $this->get(route('api.v1.import.list'), ['Accept' => 'application/json']);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ImportController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
/** @var ImportJob $job */
|
||||
$job = $this->user()->importJobs()->first();
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$transformer = $this->mock(ImportJobTransformer::class);
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
|
||||
$response = $this->get(route('api.v1.import.show', [$job->key]), ['accept' => 'application/json']);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ImportController
|
||||
*/
|
||||
public function testTransactions(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
/** @var ImportJob $job */
|
||||
$job = $this->user()->importJobs()->first();
|
||||
$tag = $this->user()->tags()->first();
|
||||
$job->tag_id = $tag->id;
|
||||
$job->save();
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
|
||||
// paginator:
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$collector->shouldReceive('setUser')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setTag')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->once()->andReturn($paginator);
|
||||
$collector->shouldReceive('removeFilter')->once()->andReturnSelf();
|
||||
|
||||
$response = $this->get(
|
||||
route('api.v1.import.transactions', [$job->key]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31']),
|
||||
['accept' => 'application/json']
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
}
|
@ -23,19 +23,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use Exception;
|
||||
use FireflyIII\Models\LinkType;
|
||||
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Transformers\LinkTypeTransformer;
|
||||
use FireflyIII\Transformers\TransactionTransformer;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Class LinkTypeControllerTest
|
||||
@ -55,114 +51,7 @@ class LinkTypeControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// create editable link type:
|
||||
$linkType = LinkType::create(
|
||||
[
|
||||
'name' => 'random' . random_int(1, 100000),
|
||||
'outward' => 'outward' . random_int(1, 100000),
|
||||
'inward' => 'inward ' . random_int(1, 100000),
|
||||
'editable' => true,
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/link_types/' . $linkType->id);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
*/
|
||||
public function testDeleteNotEditable(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// create editable link type:
|
||||
$linkType = LinkType::create(
|
||||
[
|
||||
'name' => 'random' . random_int(1, 100000),
|
||||
'outward' => 'outward' . random_int(1, 100000),
|
||||
'inward' => 'inward ' . random_int(1, 100000),
|
||||
'editable' => false,
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/link_types/' . $linkType->id);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('You cannot delete this link type');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(LinkTypeTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('get')->once()->andReturn(new Collection);
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/link_types');
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$linkType = LinkType::first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(LinkTypeTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/link_types/' . $linkType->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
* @covers \FireflyIII\Api\V1\Requests\LinkTypeRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
@ -203,16 +92,13 @@ class LinkTypeControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
* @covers \FireflyIII\Api\V1\Requests\LinkTypeRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreNotOwner(): void
|
||||
{
|
||||
$linkType = LinkType::first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(LinkTypeTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
@ -236,48 +122,7 @@ class LinkTypeControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
*/
|
||||
public function testTransactions(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$linkType = LinkType::first();
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
// mock repositories:
|
||||
$linkTypeRepos = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$journalIds = $linkTypeRepos->shouldReceive('getJournalIds')->once()->andReturn([1, 2, 3]);
|
||||
$collector->shouldReceive('setUser')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setJournalIds')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->once()->andReturn($paginator);
|
||||
|
||||
$collector->shouldReceive('removeFilter')->once()->andReturnSelf();
|
||||
$linkTypeRepos->shouldReceive('setUser')->once();
|
||||
|
||||
$response = $this->get(
|
||||
route('api.v1.link_types.transactions', [$linkType->id]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31'])
|
||||
);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
* @covers \FireflyIII\Api\V1\Requests\LinkTypeRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
@ -327,14 +172,12 @@ class LinkTypeControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
* @covers \FireflyIII\Api\V1\Requests\LinkTypeRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testUpdateNotEditable(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(LinkTypeTransformer::class);
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
|
||||
// create editable link type:
|
||||
$linkType = LinkType::create(
|
||||
@ -367,14 +210,13 @@ class LinkTypeControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
* @covers \FireflyIII\Api\V1\Requests\LinkTypeRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testUpdateNotOwner(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(LinkTypeTransformer::class);
|
||||
|
||||
$userRepository->shouldReceive('hasRole')->once()->andReturn(false);
|
||||
|
||||
|
@ -23,13 +23,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use FireflyIII\Transformers\PiggyBankEventTransformer;
|
||||
use FireflyIII\Transformers\PiggyBankTransformer;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Mockery;
|
||||
@ -52,126 +51,8 @@ class PiggyBankControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy piggy bank over API
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{ // mock stuff:
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get piggy bank:
|
||||
$piggyBank = $this->user()->piggyBanks()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/piggy_banks/' . $piggyBank->id);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// create stuff
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(PiggyBankTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
$repository->shouldReceive('getPiggyBanks')->withAnyArgs()->andReturn(new Collection())->once();
|
||||
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
//$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
|
||||
$currencyRepos->shouldReceive('setUser');
|
||||
//$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::first());
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/piggy_banks');
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => true, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(
|
||||
['links' => ['self' => true, 'first' => true, 'last' => true,],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
|
||||
*/
|
||||
public function testPiggyBankEvents(): void
|
||||
{
|
||||
$piggyBank = $this->user()->piggyBanks()->first();
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$transformer = $this->mock(PiggyBankEventTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('getEvents')->once()->andReturn(new Collection);
|
||||
|
||||
$response = $this->get(route('api.v1.piggy_banks.events', [$piggyBank->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
// create stuff
|
||||
$piggy = $this->user()->piggyBanks()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(PiggyBankTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
//$currencyRepos->shouldReceive('setUser')->once();
|
||||
//$accountRepos->shouldReceive('setUser')->once();
|
||||
|
||||
$repository->shouldReceive('getCurrentAmount')->andReturn('12');
|
||||
$repository->shouldReceive('getSuggestedMonthlyAmount')->andReturn('12');
|
||||
|
||||
//$accountRepos->shouldReceive('setUser');
|
||||
//$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
|
||||
$currencyRepos->shouldReceive('setUser');
|
||||
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::first());
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/piggy_banks/' . $piggy->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => ['type' => 'piggy_banks', 'links' => true],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
|
||||
* @covers \FireflyIII\Api\V1\Requests\PiggyBankRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
@ -179,10 +60,8 @@ class PiggyBankControllerTest extends TestCase
|
||||
$piggy = $this->user()->piggyBanks()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(PiggyBankTransformer::class);
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$transformer = $this->mock(PiggyBankTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
@ -193,17 +72,8 @@ class PiggyBankControllerTest extends TestCase
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
//$accountRepos->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('store')->once()->andReturn($piggy);
|
||||
|
||||
//$repository->shouldReceive('getCurrentAmount')->andReturn('12')->once();
|
||||
//$repository->shouldReceive('getSuggestedMonthlyAmount')->andReturn('12')->once();
|
||||
|
||||
//$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();
|
||||
|
||||
//$currencyRepos->shouldReceive('setUser')->once();
|
||||
//$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::first())->once();
|
||||
|
||||
$data = [
|
||||
'name' => 'New piggy #' . random_int(1, 100000),
|
||||
'account_id' => 1,
|
||||
@ -220,15 +90,12 @@ class PiggyBankControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
|
||||
* @covers \FireflyIII\Api\V1\Requests\PiggyBankRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreNull(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(PiggyBankTransformer::class);
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
@ -251,7 +118,7 @@ class PiggyBankControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
|
||||
* @covers \FireflyIII\Api\V1\Requests\PiggyBankRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
@ -274,8 +141,6 @@ class PiggyBankControllerTest extends TestCase
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
//$currencyRepos->shouldReceive('setUser')->once();
|
||||
//$accountRepos->shouldReceive('setUser')->once();
|
||||
|
||||
$repository->shouldReceive('update')->once()->andReturn($piggy);
|
||||
|
||||
|
@ -51,34 +51,6 @@ class PreferencesControllerTest extends TestCase
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PreferenceController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$transformer = $this->mock(PreferenceTransformer::class);
|
||||
$available = ['language', 'customFiscalYear', 'fiscalYearStart', 'currencyPreference', 'transaction_journal_optional_fields', 'frontPageAccounts',
|
||||
'viewRange', 'listPageSize, twoFactorAuthEnabled',];
|
||||
|
||||
foreach ($available as $pref) {
|
||||
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), $pref])->once();
|
||||
}
|
||||
// extra call for frontpage preference
|
||||
$pref = new Preference;
|
||||
$pref->data = [1];
|
||||
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'frontPageAccounts', []])->once()
|
||||
->andReturn($pref);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/preferences');
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PreferenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\PreferenceRequest
|
||||
*/
|
||||
public function testUpdateArray(): void
|
||||
{
|
||||
$transformer = $this->mock(PreferenceTransformer::class);
|
||||
@ -100,7 +72,6 @@ class PreferencesControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PreferenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\PreferenceRequest
|
||||
*/
|
||||
public function testUpdateBoolean(): void
|
||||
{
|
||||
@ -123,7 +94,6 @@ class PreferencesControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PreferenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\PreferenceRequest
|
||||
*/
|
||||
public function testUpdateDefault(): void
|
||||
{
|
||||
@ -146,7 +116,6 @@ class PreferencesControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PreferenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\PreferenceRequest
|
||||
*/
|
||||
public function testUpdateInteger(): void
|
||||
{
|
||||
|
@ -60,92 +60,11 @@ class RecurrenceControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get a recurrence:
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/recurrences/' . $recurrence->id);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
$transformer = $this->mock(RecurrenceTransformer::class);
|
||||
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getAll')->once()->andReturn(new Collection);
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/recurrences');
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
/** @var Recurrence $recurrence */
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
$transformer = $this->mock(RecurrenceTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/recurrences/' . $recurrence->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreAssetId(): void
|
||||
{
|
||||
@ -231,7 +150,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit the minimum amount to store a recurring transaction (using source name field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreAssetName(): void
|
||||
{
|
||||
@ -319,7 +238,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit a deposit. Since most validators have been tested in other methods, dont bother too much.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreDeposit(): void
|
||||
{
|
||||
@ -408,7 +327,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Add a recurring with correct reference to a destination (expense).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreDestinationId(): void
|
||||
{
|
||||
@ -501,7 +420,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Add a recurring with correct reference to a destination (expense).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreDestinationName(): void
|
||||
{
|
||||
@ -592,7 +511,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Includes both repetition count and an end date.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailBothRepetitions(): void
|
||||
{
|
||||
@ -688,7 +607,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit foreign amount but no currency information.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailForeignCurrency(): void
|
||||
{
|
||||
@ -768,7 +687,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailInvalidDaily(): void
|
||||
{
|
||||
@ -847,7 +766,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Add a recurring but refer to an asset as destination.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailInvalidDestinationId(): void
|
||||
{
|
||||
@ -939,7 +858,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailInvalidMonthly(): void
|
||||
{
|
||||
@ -1017,7 +936,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailInvalidNdom(): void
|
||||
{
|
||||
@ -1095,7 +1014,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailInvalidNdomCount(): void
|
||||
{
|
||||
@ -1174,7 +1093,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailInvalidNdomHigh(): void
|
||||
{
|
||||
@ -1252,7 +1171,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailInvalidWeekly(): void
|
||||
{
|
||||
@ -1330,7 +1249,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit without a source account.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailNoAsset(): void
|
||||
{
|
||||
@ -1402,7 +1321,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit with an expense account.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailNotAsset(): void
|
||||
{
|
||||
@ -1480,7 +1399,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit with an invalid asset account name.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailNotAssetName(): void
|
||||
{
|
||||
@ -1565,7 +1484,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Dont include enough repetitions.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailRepetitions(): void
|
||||
{
|
||||
@ -1635,7 +1554,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Dont include enough repetitions.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailTransactions(): void
|
||||
{
|
||||
@ -1703,7 +1622,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit a transfer. Since most validators have been tested in other methods, dont bother too much.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreTransfer(): void
|
||||
{
|
||||
@ -1790,102 +1709,11 @@ class RecurrenceControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
*/
|
||||
public function testTransactions(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
// mock repositories:
|
||||
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
|
||||
$transformer->shouldReceive('setParameters')->atLeast()->once();
|
||||
|
||||
$journalIds = $recurringRepos->shouldReceive('getJournalIds')->once()->andReturn([1, 2, 3]);
|
||||
$collector->shouldReceive('setUser')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setJournalIds')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->once()->andReturn($paginator);
|
||||
|
||||
$collector->shouldReceive('removeFilter')->once()->andReturnSelf();
|
||||
$recurringRepos->shouldReceive('setUser')->once();
|
||||
|
||||
$response = $this->get(
|
||||
route('api.v1.recurrences.transactions', [$recurrence->id]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31'])
|
||||
);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
*/
|
||||
public function testTriggerError(): void
|
||||
{
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$cronjob = $this->mock(RecurringCronjob::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
$transformer = $this->mock(RecurrenceTransformer::class);
|
||||
$cronjob->shouldReceive('fire')->andThrow(FireflyException::class);
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
|
||||
$response = $this->post(route('api.v1.recurrences.trigger'));
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Could not fire recurring cron job.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
*/
|
||||
public function testTriggerFalse(): void
|
||||
{
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$cronjob = $this->mock(RecurringCronjob::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
$transformer = $this->mock(RecurrenceTransformer::class);
|
||||
$cronjob->shouldReceive('fire')->once()->andReturnFalse();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
$response = $this->post(route('api.v1.recurrences.trigger'));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
*/
|
||||
public function testTriggerTrue(): void
|
||||
{
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$cronjob = $this->mock(RecurringCronjob::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
$transformer = $this->mock(RecurrenceTransformer::class);
|
||||
$cronjob->shouldReceive('fire')->once()->andReturnTrue();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
$response = $this->post(route('api.v1.recurrences.trigger'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Just a basic test because the store() tests cover everything.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceUpdateRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
|
@ -55,76 +55,6 @@ class RuleControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
/** @var Rule $rule */
|
||||
$rule = $this->user()->rules()->first();
|
||||
|
||||
// mock stuff:
|
||||
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleRepos->shouldReceive('setUser')->once();
|
||||
$ruleRepos->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
$response = $this->delete('/api/v1/rules/' . $rule->id);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleRepos->shouldReceive('setUser')->once();
|
||||
$ruleRepos->shouldReceive('getAll')->once()->andReturn(new Collection);
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/rules');
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$rule = $this->user()->rules()->first();
|
||||
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleRepos->shouldReceive('setUser')->once();
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/rules/' . $rule->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleController
|
||||
|
@ -56,100 +56,6 @@ class RuleGroupControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
/** @var RuleGroup $ruleGroup */
|
||||
$ruleGroup = $this->user()->ruleGroups()->first();
|
||||
|
||||
// mock stuff:
|
||||
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleGroupTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
$response = $this->delete('/api/v1/rule_groups/' . $ruleGroup->id);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleGroupTransformer::class);
|
||||
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('get')->once()->andReturn(new Collection);
|
||||
|
||||
$transformer->shouldReceive('setParameters')->atLeast()->once();
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/rule_groups');
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||
*/
|
||||
public function testRules(): void
|
||||
{
|
||||
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleTransformer::class);
|
||||
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('getRules')->once()->andReturn(new Collection);
|
||||
|
||||
// call API
|
||||
$group = $this->user()->ruleGroups()->first();
|
||||
$response = $this->get(route('api.v1.rule_groups.rules', [$group->id]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
/** @var RuleGroup $ruleGroup */
|
||||
$ruleGroup = $this->user()->ruleGroups()->first();
|
||||
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleGroupTransformer::class);
|
||||
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('setUser')->once();
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/rule_groups/' . $ruleGroup->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||
|
@ -49,136 +49,6 @@ class TagControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Tag over API.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TagController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$tagRepos = $this->mock(TagRepositoryInterface::class);
|
||||
$tag = $this->user()->tags()->inRandomOrder()->first();
|
||||
|
||||
// mock calls:
|
||||
$tagRepos->shouldReceive('setUser')->times(2);
|
||||
$tagRepos->shouldReceive('destroy')->once()->andReturn(true);
|
||||
$tagRepos->shouldReceive('findByTag')->once()->withArgs([(string)$tag->id])->andReturnNull();
|
||||
$tagRepos->shouldReceive('findNull')->once()->withArgs([$tag->id])->andReturn($tag);
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.tags.delete', [$tag->id]));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Tag over API.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TagController
|
||||
*/
|
||||
public function testDeleteByTag(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$tagRepos = $this->mock(TagRepositoryInterface::class);
|
||||
$tag = $this->user()->tags()->inRandomOrder()->first();
|
||||
// mock calls:
|
||||
$tagRepos->shouldReceive('setUser')->times(2);
|
||||
$tagRepos->shouldReceive('destroy')->once()->andReturn(true);
|
||||
$tagRepos->shouldReceive('findByTag')->once()->withArgs([(string)$tag->tag])->andReturn($tag);
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.tags.delete', [$tag->tag]));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag index
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TagController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$tagRepos = $this->mock(TagRepositoryInterface::class);
|
||||
$transformer = $this->mock(TagTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$tagRepos->shouldReceive('setUser')->times(1);
|
||||
$tagRepos->shouldReceive('get')->once()->andReturn(new Collection());
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.tags.index'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Tag over API.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TagController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$tagRepos = $this->mock(TagRepositoryInterface::class);
|
||||
$tag = $this->user()->tags()->inRandomOrder()->first();
|
||||
$transformer = $this->mock(TagTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$tagRepos->shouldReceive('setUser')->times(2);
|
||||
$tagRepos->shouldReceive('findByTag')->once()->withArgs([(string)$tag->id])->andReturnNull();
|
||||
$tagRepos->shouldReceive('findNull')->once()->withArgs([$tag->id])->andReturn($tag);
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.tags.show', [$tag->id]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show Tag over API.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TagController
|
||||
*/
|
||||
public function testShowByTag(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$tagRepos = $this->mock(TagRepositoryInterface::class);
|
||||
$tag = $this->user()->tags()->inRandomOrder()->first();
|
||||
$transformer = $this->mock(TagTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$tagRepos->shouldReceive('setUser')->times(2);
|
||||
$tagRepos->shouldReceive('findByTag')->once()->withArgs([(string)$tag->tag])->andReturn($tag);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.tags.show', [$tag->tag]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Tag over API.
|
||||
*
|
||||
@ -208,52 +78,6 @@ class TagControllerTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show transactions.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TagController
|
||||
*/
|
||||
public function testTransactions(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$tagRepos = $this->mock(TagRepositoryInterface::class);
|
||||
$tag = $this->user()->tags()->inRandomOrder()->first();
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$paginator = new LengthAwarePaginator([], 0, 50);
|
||||
|
||||
// mock calls:
|
||||
$tagRepos->shouldReceive('setUser')->times(2);
|
||||
$tagRepos->shouldReceive('findByTag')->once()->withArgs([(string)$tag->id])->andReturnNull();
|
||||
$tagRepos->shouldReceive('findNull')->once()->withArgs([$tag->id])->andReturn($tag);
|
||||
|
||||
$collector->shouldReceive('setUser')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setTag')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->once()->andReturn($paginator);
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.tags.transactions', [$tag->id]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Tag over API.
|
||||
*
|
||||
|
@ -56,63 +56,6 @@ class TransactionControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testAttachments(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$attachmentRepos = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('getAttachmentsByTr')->once()->andReturn(new Collection);
|
||||
|
||||
// get account:
|
||||
$transaction = $this->user()->transactions()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.transactions.attachments', [$transaction->id]));
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy journal over API.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get account:
|
||||
$transaction = $this->user()->transactions()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/transactions/' . $transaction->id);
|
||||
$response->assertStatus(204);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit with bad currency code
|
||||
*
|
||||
@ -1323,234 +1266,6 @@ class TransactionControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->andReturn($this->user()->accounts()->where('account_type_id', 3)->get());
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$repository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
|
||||
// mock some calls:
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/transactions');
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index with range.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testIndexWithRange(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->andReturn($this->user()->accounts()->where('account_type_id', 3)->get());
|
||||
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$repository->shouldReceive('setUser');
|
||||
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock some calls:
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/transactions?start=2018-01-01&end=2018-01-31');
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(
|
||||
['meta' =>
|
||||
['pagination' =>
|
||||
[
|
||||
'total' => 0,
|
||||
'count' => 0,
|
||||
'per_page' => 50,
|
||||
'current_page' => 1,
|
||||
'total_pages' => 1,
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testPiggyBankEvents(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$transformer = $this->mock(PiggyBankEventTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('getPiggyBankEventsbyTr')->once()->andReturn(new Collection);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
|
||||
// get account:
|
||||
$transaction = $this->user()->transactions()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.transactions.piggy_bank_events', [$transaction->id]));
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a withdrawal.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testShowDeposit(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$deposit = $this->getRandomDeposit();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->andReturn($this->user()->accounts()->where('account_type_id', 3)->get());
|
||||
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$repository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setJournals')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('addFilter')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/transactions/' . $deposit->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
[
|
||||
'data' => [
|
||||
],
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a withdrawal.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testShowWithdrawal(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$withdrawal = $this->getRandomWithdrawal();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->andReturn($this->user()->accounts()->where('account_type_id', 3)->get());
|
||||
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$repository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setJournals')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('addFilter')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/transactions/' . $withdrawal->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
[
|
||||
'data' => [
|
||||
],
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit a transaction (withdrawal) with attached bill ID
|
||||
|
@ -53,102 +53,6 @@ class TransactionLinkControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$journalRepos->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroyLink')->once()->andReturn(true);
|
||||
|
||||
// get a link
|
||||
/** @var TransactionJournalLink $journalLink */
|
||||
$journalLink = TransactionJournalLink::first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/transaction_links/' . $journalLink->id);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$transaction = Transaction::first();
|
||||
$transaction->date = new Carbon;
|
||||
$transaction->transaction_type_type = 'Withdrawal';
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$transformer = $this->mock(TransactionLinkTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findByName')->once()->andReturn(null);
|
||||
$repository->shouldReceive('getJournalLinks')->once()->andReturn(new Collection);
|
||||
|
||||
$journalRepos->shouldReceive('setUser')->once();
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/transaction_links');
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$journalLink = TransactionJournalLink::first();
|
||||
$transaction = Transaction::first();
|
||||
$transaction->date = new Carbon;
|
||||
$transaction->transaction_type_type = 'Withdrawal';
|
||||
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$transformer = $this->mock(TransactionLinkTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$journalRepos->shouldReceive('setUser')->once();
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/transaction_links/' . $journalLink->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee($journalLink->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
|
||||
* @covers \FireflyIII\Api\V1\Requests\TransactionLinkRequest
|
||||
|
@ -50,110 +50,6 @@ class UserControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a user.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\UserController
|
||||
* @covers \FireflyIII\Api\V1\Requests\UserRequest
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
$userRepository->shouldReceive('destroy')->once();
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/users/2');
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a user as non admin
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\UserController
|
||||
* @covers \FireflyIII\Api\V1\Requests\UserRequest
|
||||
*/
|
||||
public function testDeleteNoAdmin(): void
|
||||
{
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(false);
|
||||
Passport::actingAs($this->emptyUser());
|
||||
|
||||
// create a user first:
|
||||
$user = User::create(['email' => 'some@newu' . random_int(1, 10000) . 'ser.nl', 'password' => 'hello', 'blocked' => 0]);
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/users/' . $user->id, [], ['Accept' => 'application/json']);
|
||||
$response->assertStatus(302);
|
||||
$this->assertDatabaseHas('users', ['id' => $user->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cannot delete yourself.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\UserController
|
||||
* @covers \FireflyIII\Api\V1\Requests\UserRequest
|
||||
*/
|
||||
public function testDeleteYourself(): void
|
||||
{
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
// create a user first:
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/users/' . $this->user()->id, [], ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('No access to method.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show list of users.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\UserController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(UserTransformer::class);
|
||||
|
||||
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(true);
|
||||
$repository->shouldReceive('all')->withAnyArgs()->andReturn(new Collection)->once();
|
||||
$transformer->shouldReceive('setParameters')->atLeast()->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/users', ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show single user.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\UserController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$user = User::first();
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(UserTransformer::class);
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(true);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/users/' . $user->id, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store new user.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user