mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Full API coverage.
This commit is contained in:
@@ -26,6 +26,7 @@ namespace FireflyIII\Api\V1\Controllers\Chart;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Api\V1\Controllers\Controller;
|
use FireflyIII\Api\V1\Controllers\Controller;
|
||||||
|
use FireflyIII\Api\V1\Requests\DateRequest;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
@@ -35,7 +36,6 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
|||||||
use FireflyIII\Support\Http\Api\ApiSupport;
|
use FireflyIII\Support\Http\Api\ApiSupport;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AccountController
|
* Class AccountController
|
||||||
@@ -50,6 +50,7 @@ class AccountController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* AccountController constructor.
|
* AccountController constructor.
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@@ -70,22 +71,20 @@ class AccountController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param DateRequest $request
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function expenseOverview(Request $request): JsonResponse
|
public function expenseOverview(DateRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
// parameters for chart:
|
// parameters for chart:
|
||||||
$start = (string)$request->get('start');
|
$dates = $request->getAll();
|
||||||
$end = (string)$request->get('end');
|
|
||||||
if ('' === $start || '' === $end) {
|
|
||||||
throw new FireflyException('Start and end are mandatory parameters.');
|
|
||||||
}
|
|
||||||
/** @var Carbon $start */
|
/** @var Carbon $start */
|
||||||
$start = Carbon::createFromFormat('Y-m-d', $start);
|
$start = $dates['start'];
|
||||||
$end = Carbon::createFromFormat('Y-m-d', $end);
|
/** @var Carbon $end */
|
||||||
|
$end = $dates['end'];
|
||||||
|
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
|
|
||||||
// prep some vars:
|
// prep some vars:
|
||||||
@@ -159,31 +158,30 @@ class AccountController extends Controller
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param DateRequest $request
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function overview(Request $request): JsonResponse
|
public function overview(DateRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
// parameters for chart:
|
// parameters for chart:
|
||||||
$start = (string)$request->get('start');
|
$dates = $request->getAll();
|
||||||
$end = (string)$request->get('end');
|
/** @var Carbon $start */
|
||||||
if ('' === $start || '' === $end) {
|
$start = $dates['start'];
|
||||||
throw new FireflyException('Start and end are mandatory parameters.');
|
/** @var Carbon $end */
|
||||||
}
|
$end = $dates['end'];
|
||||||
|
|
||||||
$start = Carbon::createFromFormat('Y-m-d', $start);
|
|
||||||
$end = Carbon::createFromFormat('Y-m-d', $end);
|
|
||||||
|
|
||||||
// user's preferences
|
// user's preferences
|
||||||
$defaultSet = $this->repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray();
|
$defaultSet = $this->repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray();
|
||||||
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet);
|
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet);
|
||||||
$default = app('amount')->getDefaultCurrency();
|
$default = app('amount')->getDefaultCurrency();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
if (0 === count($frontPage->data)) {
|
if (0 === count($frontPage->data)) {
|
||||||
$frontPage->data = $defaultSet;
|
$frontPage->data = $defaultSet;
|
||||||
$frontPage->save();
|
$frontPage->save();
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
// get accounts:
|
// get accounts:
|
||||||
$accounts = $this->repository->getAccountsById($frontPage->data);
|
$accounts = $this->repository->getAccountsById($frontPage->data);
|
||||||
@@ -192,7 +190,7 @@ class AccountController extends Controller
|
|||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$currency = $this->repository->getAccountCurrency($account);
|
$currency = $this->repository->getAccountCurrency($account);
|
||||||
if (null === $currency) {
|
if (null === $currency) {
|
||||||
$currency = $default;
|
$currency = $default; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
$currentSet = [
|
$currentSet = [
|
||||||
'label' => $account->name,
|
'label' => $account->name,
|
||||||
@@ -223,22 +221,20 @@ class AccountController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param DateRequest $request
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function revenueOverview(Request $request): JsonResponse
|
public function revenueOverview(DateRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
// parameters for chart:
|
// parameters for chart:
|
||||||
$start = (string)$request->get('start');
|
$dates = $request->getAll();
|
||||||
$end = (string)$request->get('end');
|
|
||||||
if ('' === $start || '' === $end) {
|
|
||||||
throw new FireflyException('Start and end are mandatory parameters.');
|
|
||||||
}
|
|
||||||
/** @var Carbon $start */
|
/** @var Carbon $start */
|
||||||
$start = Carbon::createFromFormat('Y-m-d', $start);
|
$start = $dates['start'];
|
||||||
$end = Carbon::createFromFormat('Y-m-d', $end);
|
/** @var Carbon $end */
|
||||||
|
$end = $dates['end'];
|
||||||
|
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
|
|
||||||
// prep some vars:
|
// prep some vars:
|
||||||
@@ -269,7 +265,8 @@ class AccountController extends Controller
|
|||||||
$tempData[] = [
|
$tempData[] = [
|
||||||
'name' => $accountNames[$accountId],
|
'name' => $accountNames[$accountId],
|
||||||
'difference' => bcmul($diff, '-1'),
|
'difference' => bcmul($diff, '-1'),
|
||||||
'diff_float' => (float)$diff * -1,
|
// For some reason this line is never covered in code coverage:
|
||||||
|
'diff_float' => ((float)$diff) * -1, // @codeCoverageIgnore
|
||||||
'currency_id' => $currencyId,
|
'currency_id' => $currencyId,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,7 @@ class AvailableBudgetController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* AvailableBudgetController constructor.
|
* AvailableBudgetController constructor.
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@@ -26,6 +26,7 @@ namespace FireflyIII\Api\V1\Controllers\Chart;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Api\V1\Controllers\Controller;
|
use FireflyIII\Api\V1\Controllers\Controller;
|
||||||
|
use FireflyIII\Api\V1\Requests\DateRequest;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
@@ -43,6 +44,7 @@ class CategoryController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* AccountController constructor.
|
* AccountController constructor.
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@@ -61,23 +63,21 @@ class CategoryController extends Controller
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param DateRequest $request
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function overview(Request $request): JsonResponse
|
public function overview(DateRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
// parameters for chart:
|
// parameters for chart:
|
||||||
$start = (string)$request->get('start');
|
$dates = $request->getAll();
|
||||||
$end = (string)$request->get('end');
|
|
||||||
if ('' === $start || '' === $end) {
|
|
||||||
throw new FireflyException('Start and end are mandatory parameters.');
|
|
||||||
}
|
|
||||||
/** @var Carbon $start */
|
/** @var Carbon $start */
|
||||||
$start = Carbon::createFromFormat('Y-m-d', $start);
|
$start = $dates['start'];
|
||||||
/** @var Carbon $end */
|
/** @var Carbon $end */
|
||||||
$end = Carbon::createFromFormat('Y-m-d', $end);
|
$end = $dates['end'];
|
||||||
|
|
||||||
|
|
||||||
$tempData = [];
|
$tempData = [];
|
||||||
$spent = $this->categoryRepository->spentInPeriodPerCurrency(new Collection, new Collection, $start, $end);
|
$spent = $this->categoryRepository->spentInPeriodPerCurrency(new Collection, new Collection, $start, $end);
|
||||||
$earned = $this->categoryRepository->earnedInPeriodPerCurrency(new Collection, new Collection, $start, $end);
|
$earned = $this->categoryRepository->earnedInPeriodPerCurrency(new Collection, new Collection, $start, $end);
|
||||||
@@ -129,7 +129,7 @@ class CategoryController extends Controller
|
|||||||
'entries' => [],
|
'entries' => [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$amount = round($income['spent'], $decimalPlaces);
|
$amount = round($income['earned'], $decimalPlaces);
|
||||||
$categories[$categoryName] = isset($categories[$categoryName]) ? $categories[$categoryName] + $amount : $amount;
|
$categories[$categoryName] = isset($categories[$categoryName]) ? $categories[$categoryName] + $amount : $amount;
|
||||||
$tempData[$key]['entries'][$categoryName]
|
$tempData[$key]['entries'][$categoryName]
|
||||||
= $amount;
|
= $amount;
|
||||||
|
@@ -27,6 +27,7 @@ namespace FireflyIII\Api\V1\Controllers;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use FireflyIII\Api\V1\Requests\DateRequest;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
use FireflyIII\Helpers\Report\NetWorthInterface;
|
use FireflyIII\Helpers\Report\NetWorthInterface;
|
||||||
@@ -91,18 +92,13 @@ class SummaryController extends Controller
|
|||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function basic(Request $request): JsonResponse
|
public function basic(DateRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
// parameters for boxes:
|
// parameters for boxes:
|
||||||
$start = (string)$request->get('start');
|
$dates = $request->getAll();
|
||||||
$end = (string)$request->get('end');
|
$start = $dates['start'];
|
||||||
if ('' === $start || '' === $end) {
|
$end = $dates['end'];
|
||||||
throw new FireflyException('Start and end are mandatory parameters.');
|
|
||||||
}
|
|
||||||
/** @var Carbon $start */
|
|
||||||
$start = Carbon::createFromFormat('Y-m-d', $start);
|
|
||||||
/** @var Carbon $end */
|
|
||||||
$end = Carbon::createFromFormat('Y-m-d', $end);
|
|
||||||
// balance information:
|
// balance information:
|
||||||
$balanceData = $this->getBalanceInformation($start, $end);
|
$balanceData = $this->getBalanceInformation($start, $end);
|
||||||
$billData = $this->getBillInformation($start, $end);
|
$billData = $this->getBillInformation($start, $end);
|
||||||
@@ -366,7 +362,7 @@ class SummaryController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0.0;
|
return 0.0; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -404,7 +400,7 @@ class SummaryController extends Controller
|
|||||||
|
|
||||||
$netWorthSet = $netWorthHelper->getNetWorthByCurrency($filtered, $date);
|
$netWorthSet = $netWorthHelper->getNetWorthByCurrency($filtered, $date);
|
||||||
$return = [];
|
$return = [];
|
||||||
foreach ($netWorthSet as $index => $data) {
|
foreach ($netWorthSet as $data) {
|
||||||
/** @var TransactionCurrency $currency */
|
/** @var TransactionCurrency $currency */
|
||||||
$currency = $data['currency'];
|
$currency = $data['currency'];
|
||||||
$amount = round($data['balance'], $currency->decimal_places);
|
$amount = round($data['balance'], $currency->decimal_places);
|
||||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Api\V1\Controllers;
|
namespace FireflyIII\Api\V1\Controllers;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Api\V1\Requests\DateRequest;
|
||||||
use FireflyIII\Api\V1\Requests\TagRequest;
|
use FireflyIII\Api\V1\Requests\TagRequest;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
@@ -36,6 +37,7 @@ use FireflyIII\User;
|
|||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use League\Fractal\Manager;
|
use League\Fractal\Manager;
|
||||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||||
use League\Fractal\Resource\Collection as FractalCollection;
|
use League\Fractal\Resource\Collection as FractalCollection;
|
||||||
@@ -53,7 +55,7 @@ class TagController extends Controller
|
|||||||
private $repository;
|
private $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RuleController constructor.
|
* TagController constructor.
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
@@ -74,54 +76,23 @@ class TagController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param DateRequest $request
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function cloud(Request $request): JsonResponse
|
public function cloud(DateRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
// parameters for cloud:
|
// parameters for boxes:
|
||||||
$start = (string)$request->get('start');
|
$dates = $request->getAll();
|
||||||
$end = (string)$request->get('end');
|
$start = $dates['start'];
|
||||||
if ('' === $start || '' === $end) {
|
$end = $dates['end'];
|
||||||
throw new FireflyException('Start and end are mandatory parameters.');
|
|
||||||
}
|
|
||||||
/** @var Carbon $start */
|
|
||||||
$start = Carbon::createFromFormat('Y-m-d', $start);
|
|
||||||
/** @var Carbon $end */
|
|
||||||
$end = Carbon::createFromFormat('Y-m-d', $end);
|
|
||||||
|
|
||||||
// get all tags:
|
// get all tags:
|
||||||
$tags = $this->repository->get();
|
$tags = $this->repository->get();
|
||||||
$min = null;
|
$cloud = $this->getTagCloud($tags, $start, $end);
|
||||||
$max = 0;
|
|
||||||
$return = [
|
|
||||||
'tags' => [],
|
|
||||||
];
|
|
||||||
/** @var Tag $tag */
|
|
||||||
foreach ($tags as $tag) {
|
|
||||||
$earned = (float)$this->repository->earnedInPeriod($tag, $start, $end);
|
|
||||||
$spent = (float)$this->repository->spentInPeriod($tag, $start, $end);
|
|
||||||
$size = ($spent * -1) + $earned;
|
|
||||||
$min = $min ?? $size;
|
|
||||||
if ($size > 0) {
|
|
||||||
$max = $size > $max ? $size : $max;
|
|
||||||
$return['tags'][] = [
|
|
||||||
'tag' => $tag->tag,
|
|
||||||
'id' => $tag->id,
|
|
||||||
'size' => $size,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($return['tags'] as $index => $info) {
|
|
||||||
$return['tags'][$index]['relative'] = $return['tags'][$index]['size'] / $max;
|
|
||||||
}
|
|
||||||
$return['min'] = $min;
|
|
||||||
$return['max'] = $max;
|
|
||||||
|
|
||||||
|
return response()->json($cloud);
|
||||||
return response()->json($return);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -305,4 +276,54 @@ class TagController extends Controller
|
|||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $tags
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getTagCloud(Collection $tags, Carbon $start, Carbon $end): array
|
||||||
|
{
|
||||||
|
$min = null;
|
||||||
|
$max = 0;
|
||||||
|
$cloud = [
|
||||||
|
'tags' => [],
|
||||||
|
];
|
||||||
|
/** @var Tag $tag */
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$earned = (float)$this->repository->earnedInPeriod($tag, $start, $end);
|
||||||
|
$spent = (float)$this->repository->spentInPeriod($tag, $start, $end);
|
||||||
|
$size = ($spent * -1) + $earned;
|
||||||
|
$min = $min ?? $size;
|
||||||
|
if ($size > 0) {
|
||||||
|
$max = $size > $max ? $size : $max;
|
||||||
|
$cloud['tags'][] = [
|
||||||
|
'tag' => $tag->tag,
|
||||||
|
'id' => $tag->id,
|
||||||
|
'size' => $size,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$cloud = $this->analyseTagCloud($cloud, $min, $max);
|
||||||
|
|
||||||
|
return $cloud;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $cloud
|
||||||
|
* @param float $min
|
||||||
|
* @param float $max
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function analyseTagCloud(array $cloud, float $min, float $max): array
|
||||||
|
{
|
||||||
|
foreach (array_keys($cloud['tags']) as $index) {
|
||||||
|
$cloud['tags'][$index]['relative'] = round($cloud['tags'][$index]['size'] / $max, 4);
|
||||||
|
}
|
||||||
|
$cloud['min'] = $min;
|
||||||
|
$cloud['max'] = $max;
|
||||||
|
|
||||||
|
return $cloud;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
68
app/Api/V1/Requests/DateRequest.php
Normal file
68
app/Api/V1/Requests/DateRequest.php
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* DateRequest.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace FireflyIII\Api\V1\Requests;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request class for end points that require date parameters.
|
||||||
|
*
|
||||||
|
* Class DateRequest
|
||||||
|
*/
|
||||||
|
class DateRequest extends Request
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'start' => $this->date('start'),
|
||||||
|
'end' => $this->date('end'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The rules that the incoming request must be matched against.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'start' => 'required|date',
|
||||||
|
'end' => 'required|date|after:start',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@@ -77,6 +77,7 @@ class AvailableBudget extends Model
|
|||||||
'deleted_at' => 'datetime',
|
'deleted_at' => 'datetime',
|
||||||
'start_date' => 'date',
|
'start_date' => 'date',
|
||||||
'end_date' => 'date',
|
'end_date' => 'date',
|
||||||
|
'transaction_currency_id' => 'int',
|
||||||
];
|
];
|
||||||
/** @var array Fields that can be filled */
|
/** @var array Fields that can be filled */
|
||||||
protected $fillable = ['user_id', 'transaction_currency_id', 'amount', 'start_date', 'end_date'];
|
protected $fillable = ['user_id', 'transaction_currency_id', 'amount', 'start_date', 'end_date'];
|
||||||
|
@@ -156,14 +156,14 @@ class CategoryRepository implements CategoryRepositoryInterface
|
|||||||
$currencyId = (int)$journal['currency_id'];
|
$currencyId = (int)$journal['currency_id'];
|
||||||
if (!isset($return[$currencyId])) {
|
if (!isset($return[$currencyId])) {
|
||||||
$return[$currencyId] = [
|
$return[$currencyId] = [
|
||||||
'spent' => '0',
|
'earned' => '0',
|
||||||
'currency_id' => $currencyId,
|
'currency_id' => $currencyId,
|
||||||
'currency_symbol' => $journal['currency_symbol'],
|
'currency_symbol' => $journal['currency_symbol'],
|
||||||
'currency_code' => $journal['currency_code'],
|
'currency_code' => $journal['currency_code'],
|
||||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$return[$currencyId]['spent'] = bcadd($return[$currencyId]['spent'], $journal['amount']);
|
$return[$currencyId]['earned'] = bcadd($return[$currencyId]['earned'], $journal['amount']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
@@ -1379,4 +1379,15 @@ return [
|
|||||||
'will_jump_monday' => 'Will be created on Monday instead of the weekends.',
|
'will_jump_monday' => 'Will be created on Monday instead of the weekends.',
|
||||||
'except_weekends' => 'Except weekends',
|
'except_weekends' => 'Except weekends',
|
||||||
'recurrence_deleted' => 'Recurring transaction ":title" deleted',
|
'recurrence_deleted' => 'Recurring transaction ":title" deleted',
|
||||||
|
|
||||||
|
// new lines for summary controller.
|
||||||
|
'box_balance_in_currency' => 'Balance (:currency)',
|
||||||
|
'box_spent_in_currency' => 'Spent (:currency)',
|
||||||
|
'box_earned_in_currency' => 'Earned (:currency)',
|
||||||
|
'box_bill_paid_in_currency' => 'Bills paid (:currency)',
|
||||||
|
'box_bill_unpaid_in_currency' => 'Bills unpaid (:currency)',
|
||||||
|
'box_left_to_spend_in_currency' => 'Left to spend (:currency)',
|
||||||
|
'box_net_worth_in_currency' => 'Net worth (:currency)',
|
||||||
|
'box_spend_per_day' => 'Left to spend per day: :amount',
|
||||||
|
|
||||||
];
|
];
|
||||||
|
175
tests/Api/V1/Controllers/Chart/AccountControllerTest.php
Normal file
175
tests/Api/V1/Controllers/Chart/AccountControllerTest.php
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AccountControllerTest.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests\Api\V1\Controllers\Chart;
|
||||||
|
|
||||||
|
|
||||||
|
use Amount;
|
||||||
|
use FireflyIII\Models\AccountType;
|
||||||
|
use FireflyIII\Models\Preference;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Laravel\Passport\Passport;
|
||||||
|
use Log;
|
||||||
|
use Preferences;
|
||||||
|
use Steam;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AccountControllerTest
|
||||||
|
*/
|
||||||
|
class AccountControllerTest 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\Chart\AccountController
|
||||||
|
* @covers \FireflyIII\Api\V1\Requests\DateRequest
|
||||||
|
*/
|
||||||
|
public function testOverview(): void
|
||||||
|
{
|
||||||
|
// mock repositories
|
||||||
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
|
$asset = $this->getRandomAsset();
|
||||||
|
$euro = $this->getEuro();
|
||||||
|
// mock calls
|
||||||
|
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->atLeast()->once()->andReturn(new Collection([$asset]));
|
||||||
|
$repository->shouldReceive('getAccountsById')->withArgs([[$asset->id]])->atLeast()->once()->andReturn(new Collection([$asset]));
|
||||||
|
$repository->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
|
||||||
|
|
||||||
|
// mock Steam:
|
||||||
|
Steam::shouldReceive('balanceInRange')->atLeast()->once()->andReturn(['2019-01-01' => '-123',]);
|
||||||
|
|
||||||
|
// mock Preferences:
|
||||||
|
$preference = new Preference;
|
||||||
|
$preference->data = [$asset->id];
|
||||||
|
Preferences::shouldReceive('get')->withArgs(['frontPageAccounts', [$asset->id]])->andReturn($preference);
|
||||||
|
|
||||||
|
// mock Amount
|
||||||
|
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||||
|
|
||||||
|
|
||||||
|
$parameters = [
|
||||||
|
'start' => '2019-01-01',
|
||||||
|
'end' => '2019-01-31',
|
||||||
|
];
|
||||||
|
$response = $this->get(route('api.v1.chart.account.overview') . '?' . http_build_query($parameters), ['Accept' => 'application/json']);
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Api\V1\Controllers\Chart\AccountController
|
||||||
|
* @covers \FireflyIII\Api\V1\Requests\DateRequest
|
||||||
|
*/
|
||||||
|
public function testRevenueOverview(): void
|
||||||
|
{
|
||||||
|
// mock repositories
|
||||||
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
|
$revenue = $this->getRandomRevenue();
|
||||||
|
$euro = $this->getEuro();
|
||||||
|
// mock calls:
|
||||||
|
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])
|
||||||
|
->atLeast()->once()->andReturn(new Collection([$revenue]));
|
||||||
|
$currencyRepos->shouldReceive('findNull')
|
||||||
|
->atLeast()->once()->withArgs([1])->andReturn($euro);
|
||||||
|
|
||||||
|
// mock Steam, first start and then end.
|
||||||
|
$startBalances = [
|
||||||
|
$revenue->id => [
|
||||||
|
1 => '10',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$endBalances = [
|
||||||
|
$revenue->id => [
|
||||||
|
1 => '20',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
Steam::shouldReceive('balancesPerCurrencyByAccounts')->times(2)
|
||||||
|
->andReturn($startBalances, $endBalances);
|
||||||
|
|
||||||
|
$parameters = [
|
||||||
|
'start' => '2019-01-01',
|
||||||
|
'end' => '2019-01-31',
|
||||||
|
];
|
||||||
|
$response = $this->get(route('api.v1.chart.account.revenue') . '?' . http_build_query($parameters), ['Accept' => 'application/json']);
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Api\V1\Controllers\Chart\AccountController
|
||||||
|
*/
|
||||||
|
public function testExpenseOverview(): void
|
||||||
|
{
|
||||||
|
// mock repositories
|
||||||
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
|
|
||||||
|
$expense = $this->getRandomExpense();
|
||||||
|
$euro = $this->getEuro();
|
||||||
|
// mock calls:
|
||||||
|
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE]])
|
||||||
|
->atLeast()->once()->andReturn(new Collection([$expense]));
|
||||||
|
$currencyRepos->shouldReceive('findNull')
|
||||||
|
->atLeast()->once()->withArgs([1])->andReturn($euro);
|
||||||
|
|
||||||
|
// mock Steam, first start and then end.
|
||||||
|
$startBalances = [
|
||||||
|
$expense->id => [
|
||||||
|
1 => '-10',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$endBalances = [
|
||||||
|
$expense->id => [
|
||||||
|
1 => '-20',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
Steam::shouldReceive('balancesPerCurrencyByAccounts')->times(2)
|
||||||
|
->andReturn($startBalances, $endBalances);
|
||||||
|
|
||||||
|
$parameters = [
|
||||||
|
'start' => '2019-01-01',
|
||||||
|
'end' => '2019-01-31',
|
||||||
|
];
|
||||||
|
$response = $this->get(route('api.v1.chart.account.expense') . '?' . http_build_query($parameters), ['Accept' => 'application/json']);
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
118
tests/Api/V1/Controllers/Chart/AvailableBudgetControllerTest.php
Normal file
118
tests/Api/V1/Controllers/Chart/AvailableBudgetControllerTest.php
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AvailableBudgetControllerTest.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests\Api\V1\Controllers\Chart;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Laravel\Passport\Passport;
|
||||||
|
use Log;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AvailableBudgetControllerTest
|
||||||
|
*/
|
||||||
|
class AvailableBudgetControllerTest 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\Chart\AvailableBudgetController
|
||||||
|
*/
|
||||||
|
public function testOverview(): void
|
||||||
|
{
|
||||||
|
$availableBudget = $this->user()->availableBudgets()->first();
|
||||||
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
|
||||||
|
// get data:
|
||||||
|
$budget = $this->getBudget();
|
||||||
|
|
||||||
|
// mock calls:
|
||||||
|
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$repository->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
|
||||||
|
$repository->shouldReceive('spentInPeriodMc')->atLeast()->once()->
|
||||||
|
andReturn(
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'currency_id' => 1,
|
||||||
|
'currency_code' => 'EUR',
|
||||||
|
'currency_symbol' => 'x',
|
||||||
|
'currency_decimal_places' => 2,
|
||||||
|
'amount' => 321.21,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$parameters = [
|
||||||
|
'start' => '2019-01-01',
|
||||||
|
'end' => '2019-01-31',
|
||||||
|
];
|
||||||
|
$response = $this->get(route('api.v1.chart.ab.overview', [$availableBudget->id]) . '?'
|
||||||
|
. http_build_query($parameters), ['Accept' => 'application/json']);
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Api\V1\Controllers\Chart\AvailableBudgetController
|
||||||
|
*/
|
||||||
|
public function testOverviewNothingLeft(): void
|
||||||
|
{
|
||||||
|
$availableBudget = $this->user()->availableBudgets()->first();
|
||||||
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
|
||||||
|
// get data:
|
||||||
|
$budget = $this->getBudget();
|
||||||
|
|
||||||
|
// mock calls:
|
||||||
|
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$repository->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
|
||||||
|
$repository->shouldReceive('spentInPeriodMc')->atLeast()->once()->
|
||||||
|
andReturn(
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'currency_id' => 1,
|
||||||
|
'currency_code' => 'EUR',
|
||||||
|
'currency_symbol' => 'x',
|
||||||
|
'currency_decimal_places' => 2,
|
||||||
|
'amount' => -3321.21,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$parameters = [
|
||||||
|
'start' => '2019-01-01',
|
||||||
|
'end' => '2019-01-31',
|
||||||
|
];
|
||||||
|
$response = $this->get(route('api.v1.chart.ab.overview', [$availableBudget->id]) . '?'
|
||||||
|
. http_build_query($parameters), ['Accept' => 'application/json']);
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
119
tests/Api/V1/Controllers/Chart/CategoryControllerTest.php
Normal file
119
tests/Api/V1/Controllers/Chart/CategoryControllerTest.php
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* CategoryControllerTest.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests\Api\V1\Controllers\Chart;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
|
use Laravel\Passport\Passport;
|
||||||
|
use Log;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CategoryControllerTest
|
||||||
|
*/
|
||||||
|
class CategoryControllerTest 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\Chart\CategoryController
|
||||||
|
*/
|
||||||
|
public function testOverview(): void
|
||||||
|
{
|
||||||
|
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||||
|
|
||||||
|
$spent = [
|
||||||
|
2 => [
|
||||||
|
'name' => 'Some other category',
|
||||||
|
'spent' => [
|
||||||
|
// earned in this currency.
|
||||||
|
1 => [
|
||||||
|
'currency_decimal_places' => 2,
|
||||||
|
'currency_symbol' => 'x',
|
||||||
|
'currency_code' => 'EUR',
|
||||||
|
'currency_id' => 1,
|
||||||
|
'spent' => '-522',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$earned = [
|
||||||
|
1 => [
|
||||||
|
'name' => 'Some category',
|
||||||
|
'earned' => [
|
||||||
|
// earned in this currency.
|
||||||
|
2 => [
|
||||||
|
'currency_decimal_places' => 2,
|
||||||
|
'currency_id' => 1,
|
||||||
|
'currency_symbol' => 'x',
|
||||||
|
'currency_code' => 'EUR',
|
||||||
|
'earned' => '123',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$earnedNoCategory = [
|
||||||
|
1 => [
|
||||||
|
'currency_decimal_places' => 2,
|
||||||
|
'currency_id' => 3,
|
||||||
|
'currency_symbol' => 'x',
|
||||||
|
'currency_code' => 'EUR',
|
||||||
|
'earned' => '123',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$spentNoCategory = [
|
||||||
|
5 => [
|
||||||
|
'currency_decimal_places' => 2,
|
||||||
|
'currency_symbol' => 'x',
|
||||||
|
'currency_code' => 'EUR',
|
||||||
|
'currency_id' => 4,
|
||||||
|
'spent' => '-345',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
// mock calls:
|
||||||
|
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$repository->shouldReceive('spentInPeriodPerCurrency')->atLeast()->once()->andReturn($spent);
|
||||||
|
$repository->shouldReceive('earnedInPeriodPerCurrency')->atLeast()->once()->andReturn($earned);
|
||||||
|
|
||||||
|
$repository->shouldReceive('earnedInPeriodPcWoCategory')->atLeast()->once()->andReturn($earnedNoCategory);
|
||||||
|
$repository->shouldReceive('spentInPeriodPcWoCategory')->atLeast()->once()->andReturn($spentNoCategory);
|
||||||
|
|
||||||
|
$parameters = [
|
||||||
|
'start' => '2019-01-01',
|
||||||
|
'end' => '2019-01-31',
|
||||||
|
];
|
||||||
|
$response = $this->get(route('api.v1.chart.category.overview') . '?' . http_build_query($parameters), ['Accept' => 'application/json']);
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -198,7 +198,8 @@ class RuleControllerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @covers \FireflyIII\Api\V1\Controllers\RuleController
|
||||||
|
* @covers \FireflyIII\Api\V1\Requests\RuleTestRequest
|
||||||
*/
|
*/
|
||||||
public function testTestRule(): void
|
public function testTestRule(): void
|
||||||
{
|
{
|
||||||
@@ -242,6 +243,7 @@ class RuleControllerTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Api\V1\Controllers\RuleController
|
* @covers \FireflyIII\Api\V1\Controllers\RuleController
|
||||||
|
* @covers \FireflyIII\Api\V1\Requests\RuleTriggerRequest
|
||||||
*/
|
*/
|
||||||
public function testTriggerRule(): void
|
public function testTriggerRule(): void
|
||||||
{
|
{
|
||||||
|
@@ -26,15 +26,12 @@ namespace Tests\Api\V1\Controllers;
|
|||||||
|
|
||||||
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
|
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
|
||||||
use FireflyIII\Jobs\Job;
|
use FireflyIII\Jobs\Job;
|
||||||
use FireflyIII\Models\Rule;
|
|
||||||
use FireflyIII\Models\RuleGroup;
|
use FireflyIII\Models\RuleGroup;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
|
||||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||||
use FireflyIII\TransactionRules\TransactionMatcher;
|
use FireflyIII\TransactionRules\TransactionMatcher;
|
||||||
use FireflyIII\Transformers\RuleGroupTransformer;
|
use FireflyIII\Transformers\RuleGroupTransformer;
|
||||||
use FireflyIII\Transformers\RuleTransformer;
|
|
||||||
use FireflyIII\Transformers\TransactionGroupTransformer;
|
use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
@@ -98,6 +95,7 @@ class RuleGroupControllerTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||||
|
* @covers \FireflyIII\Api\V1\Requests\RuleGroupTestRequest
|
||||||
*/
|
*/
|
||||||
public function testTestGroupBasic(): void
|
public function testTestGroupBasic(): void
|
||||||
{
|
{
|
||||||
@@ -140,6 +138,7 @@ class RuleGroupControllerTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||||
|
* @covers \FireflyIII\Api\V1\Requests\RuleGroupTestRequest
|
||||||
*/
|
*/
|
||||||
public function testTestGroupEmpty(): void
|
public function testTestGroupEmpty(): void
|
||||||
{
|
{
|
||||||
@@ -159,6 +158,7 @@ class RuleGroupControllerTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||||
|
* @covers \FireflyIII\Api\V1\Requests\RuleGroupTriggerRequest
|
||||||
*/
|
*/
|
||||||
public function testTrigger(): void
|
public function testTrigger(): void
|
||||||
{
|
{
|
||||||
@@ -228,7 +228,6 @@ class RuleGroupControllerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||||
*/
|
*/
|
||||||
|
258
tests/Api/V1/Controllers/SummaryControllerTest.php
Normal file
258
tests/Api/V1/Controllers/SummaryControllerTest.php
Normal file
@@ -0,0 +1,258 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* SummaryControllerTest.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests\Api\V1\Controllers;
|
||||||
|
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
|
use FireflyIII\Helpers\Report\NetWorthInterface;
|
||||||
|
use FireflyIII\Models\AccountType;
|
||||||
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Laravel\Passport\Passport;
|
||||||
|
use Log;
|
||||||
|
use Mockery;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class SummaryControllerTest
|
||||||
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||||
|
*/
|
||||||
|
class SummaryControllerTest 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\SummaryController
|
||||||
|
*/
|
||||||
|
public function testBasicInThePast(): void
|
||||||
|
{
|
||||||
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||||
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
|
$collector = $this->mock(GroupCollectorInterface::class);
|
||||||
|
$netWorth = $this->mock(NetWorthInterface::class);
|
||||||
|
|
||||||
|
// data
|
||||||
|
$euro = TransactionCurrency::find(1);
|
||||||
|
$budget = $this->user()->budgets()->inRandomOrder()->first();
|
||||||
|
$account = $this->getRandomAsset();
|
||||||
|
$journals = [
|
||||||
|
[
|
||||||
|
'amount' => '10',
|
||||||
|
'currency_id' => 1,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$netWorthData = [
|
||||||
|
[
|
||||||
|
'currency' => $euro,
|
||||||
|
'balance' => '232',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
// mock calls.
|
||||||
|
$accountRepos->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$billRepos->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$budgetRepos->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$netWorth->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
|
||||||
|
// mock collector calls:
|
||||||
|
$collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();
|
||||||
|
|
||||||
|
// used to get balance information (deposits)
|
||||||
|
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->atLeast()->once()->andReturnSelf();
|
||||||
|
|
||||||
|
// same, but for withdrawals
|
||||||
|
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->atLeast()->once()->andReturnSelf();
|
||||||
|
|
||||||
|
// system always returns one basic transaction (see above)
|
||||||
|
$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($journals);
|
||||||
|
|
||||||
|
// currency repos does some basic collecting
|
||||||
|
$currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn($euro);
|
||||||
|
|
||||||
|
// bill repository return value
|
||||||
|
$billRepos->shouldReceive('getBillsPaidInRangePerCurrency')->atLeast()->once()->andReturn([1 => '123']);
|
||||||
|
$billRepos->shouldReceive('getBillsUnpaidInRangePerCurrency')->atLeast()->once()->andReturn([1 => '123']);
|
||||||
|
|
||||||
|
// budget repos
|
||||||
|
$budgetRepos->shouldReceive('getAvailableBudgetWithCurrency')->atLeast()->once()->andReturn([1 => '123']);
|
||||||
|
$budgetRepos->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
|
||||||
|
$budgetRepos->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn(
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'currency_id' => 1,
|
||||||
|
'currency_code' => 'EUR',
|
||||||
|
'currency_symbol' => 'x',
|
||||||
|
'currency_decimal_places' => 2,
|
||||||
|
'amount' => 321.21,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// account repos:
|
||||||
|
$accountRepos->shouldReceive('getActiveAccountsByType')->atLeast()->once()
|
||||||
|
->withArgs([[AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE]])->andReturn(new Collection([$account]));
|
||||||
|
$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->withArgs([Mockery::any(), 'include_net_worth'])->andReturn(true);
|
||||||
|
|
||||||
|
// net worth calculator
|
||||||
|
$netWorth->shouldReceive('getNetWorthByCurrency')->atLeast()->once()->andReturn($netWorthData);
|
||||||
|
|
||||||
|
$parameters = [
|
||||||
|
'start' => '2019-01-01',
|
||||||
|
'end' => '2019-01-31',
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->get(route('api.v1.summary.basic') . '?' . http_build_query($parameters));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
// TODO after 4.8.0: check if JSON is correct
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Also includes NULL currencies for better coverage.
|
||||||
|
*
|
||||||
|
* @covers \FireflyIII\Api\V1\Controllers\SummaryController
|
||||||
|
*/
|
||||||
|
public function testBasicInTheFuture(): void
|
||||||
|
{
|
||||||
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||||
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
|
$collector = $this->mock(GroupCollectorInterface::class);
|
||||||
|
$netWorth = $this->mock(NetWorthInterface::class);
|
||||||
|
$date = new Carbon();
|
||||||
|
$date->addWeek();
|
||||||
|
|
||||||
|
// data
|
||||||
|
$euro = TransactionCurrency::find(1);
|
||||||
|
$budget = $this->user()->budgets()->inRandomOrder()->first();
|
||||||
|
$account = $this->getRandomAsset();
|
||||||
|
$journals = [
|
||||||
|
[
|
||||||
|
'amount' => '10',
|
||||||
|
'currency_id' => 1,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'amount' => '10',
|
||||||
|
'currency_id' => 2,
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
|
$netWorthData = [
|
||||||
|
[
|
||||||
|
'currency' => $euro,
|
||||||
|
'balance' => '232',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'currency' => $euro,
|
||||||
|
'balance' => '0',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
// mock calls.
|
||||||
|
$accountRepos->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$billRepos->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$budgetRepos->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$netWorth->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
|
||||||
|
// mock collector calls:
|
||||||
|
$collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();
|
||||||
|
|
||||||
|
// used to get balance information (deposits)
|
||||||
|
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->atLeast()->once()->andReturnSelf();
|
||||||
|
|
||||||
|
// same, but for withdrawals
|
||||||
|
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->atLeast()->once()->andReturnSelf();
|
||||||
|
|
||||||
|
// system always returns one basic transaction (see above)
|
||||||
|
$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($journals);
|
||||||
|
|
||||||
|
// currency repos does some basic collecting
|
||||||
|
$currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn($euro);
|
||||||
|
$currencyRepos->shouldReceive('findNull')->withArgs([2])->atLeast()->once()->andReturn(null);
|
||||||
|
|
||||||
|
// bill repository return value
|
||||||
|
$billRepos->shouldReceive('getBillsPaidInRangePerCurrency')->atLeast()->once()->andReturn([1 => '123', 2 => '456']);
|
||||||
|
$billRepos->shouldReceive('getBillsUnpaidInRangePerCurrency')->atLeast()->once()->andReturn([1 => '123', 2 => '456']);
|
||||||
|
|
||||||
|
// budget repos
|
||||||
|
$budgetRepos->shouldReceive('getAvailableBudgetWithCurrency')->atLeast()->once()->andReturn([1 => '123', 2 => '456']);
|
||||||
|
$budgetRepos->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
|
||||||
|
$budgetRepos->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn(
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'currency_id' => 3,
|
||||||
|
'currency_code' => 'EUR',
|
||||||
|
'currency_symbol' => 'x',
|
||||||
|
'currency_decimal_places' => 2,
|
||||||
|
'amount' => 321.21,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'currency_id' => 1,
|
||||||
|
'currency_code' => 'EUR',
|
||||||
|
'currency_symbol' => 'x',
|
||||||
|
'currency_decimal_places' => 2,
|
||||||
|
'amount' => 321.21,
|
||||||
|
],
|
||||||
|
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// account repos:
|
||||||
|
$accountRepos->shouldReceive('getActiveAccountsByType')->atLeast()->once()
|
||||||
|
->withArgs([[AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE]])->andReturn(new Collection([$account]));
|
||||||
|
$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->withArgs([Mockery::any(), 'include_net_worth'])->andReturn(true);
|
||||||
|
|
||||||
|
// net worth calculator
|
||||||
|
$netWorth->shouldReceive('getNetWorthByCurrency')->atLeast()->once()->andReturn($netWorthData);
|
||||||
|
|
||||||
|
$parameters = [
|
||||||
|
'start' => $date->format('Y-m-d'),
|
||||||
|
'end' => $date->addWeek()->format('Y-m-d'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->get(route('api.v1.summary.basic') . '?' . http_build_query($parameters));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
// TODO after 4.8.0: check if JSON is correct
|
||||||
|
}
|
||||||
|
}
|
@@ -23,7 +23,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Tests\Api\V1\Controllers;
|
namespace Tests\Api\V1\Controllers;
|
||||||
|
|
||||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
|
||||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||||
use FireflyIII\Transformers\TagTransformer;
|
use FireflyIII\Transformers\TagTransformer;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
@@ -77,6 +76,46 @@ class TagControllerTest extends TestCase
|
|||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Api\V1\Controllers\TagController
|
||||||
|
*/
|
||||||
|
public function testCloud(): void
|
||||||
|
{
|
||||||
|
$tagRepos = $this->mock(TagRepositoryInterface::class);
|
||||||
|
$tags = $this->user()->tags()->inRandomOrder()->limit(3)->get();
|
||||||
|
|
||||||
|
$tagRepos->shouldReceive('setUser')->times(1);
|
||||||
|
$tagRepos->shouldReceive('get')->atLeast()->once()->andReturn($tags);
|
||||||
|
$tagRepos->shouldReceive('earnedInPeriod')->times(3)->andReturn('0');
|
||||||
|
$tagRepos->shouldReceive('spentInPeriod')->times(3)->andReturn('-10', '-20', '-30');
|
||||||
|
|
||||||
|
// call API
|
||||||
|
$parameters = [
|
||||||
|
'start' => '2019-01-01',
|
||||||
|
'end' => '2019-01-05',
|
||||||
|
];
|
||||||
|
$response = $this->get(route('api.v1.tag-cloud.cloud') . '?' . http_build_query($parameters));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$response->assertJson(
|
||||||
|
[
|
||||||
|
'tags' => [
|
||||||
|
[
|
||||||
|
'size' => 10,
|
||||||
|
'relative' => 0.3333,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'size' => 20,
|
||||||
|
'relative' => 0.6667,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'size' => 30,
|
||||||
|
'relative' => 1,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update Tag over API.
|
* Update Tag over API.
|
||||||
*
|
*
|
||||||
|
@@ -25,7 +25,6 @@ namespace Tests\Api\V1\Controllers;
|
|||||||
|
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
|
||||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournalLink;
|
use FireflyIII\Models\TransactionJournalLink;
|
||||||
|
@@ -31,7 +31,9 @@ use FireflyIII\Exceptions\FireflyException;
|
|||||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
|
use FireflyIII\Models\Budget;
|
||||||
use FireflyIII\Models\Preference;
|
use FireflyIII\Models\Preference;
|
||||||
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Models\TransactionGroup;
|
use FireflyIII\Models\TransactionGroup;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
@@ -49,7 +51,6 @@ use RuntimeException;
|
|||||||
*/
|
*/
|
||||||
abstract class TestCase extends BaseTestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User $user
|
* @param User $user
|
||||||
* @param string $range
|
* @param string $range
|
||||||
@@ -100,8 +101,6 @@ abstract class TestCase extends BaseTestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
use CreatesApplication;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return User
|
* @return User
|
||||||
*/
|
*/
|
||||||
@@ -122,6 +121,8 @@ abstract class TestCase extends BaseTestCase
|
|||||||
return User::find(2);
|
return User::find(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use CreatesApplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int|null $except
|
* @param int|null $except
|
||||||
*
|
*
|
||||||
@@ -194,8 +195,6 @@ abstract class TestCase extends BaseTestCase
|
|||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
// $repository = $this->mock(JournalRepositoryInterface::class);
|
|
||||||
// $repository->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,6 +205,22 @@ abstract class TestCase extends BaseTestCase
|
|||||||
return User::find(1);
|
return User::find(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Budget
|
||||||
|
*/
|
||||||
|
protected function getBudget(): Budget
|
||||||
|
{
|
||||||
|
return $this->user()->budgets()->inRandomOrder()->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return TransactionCurrency
|
||||||
|
*/
|
||||||
|
protected function getEuro(): TransactionCurrency
|
||||||
|
{
|
||||||
|
return TransactionCurrency::find(1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return TransactionGroup
|
* @return TransactionGroup
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user