mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Clean up API code and fix test code.
This commit is contained in:
@@ -23,12 +23,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use Preferences;
|
||||
use Amount;
|
||||
use FireflyIII\Factory\TransactionCurrencyFactory;
|
||||
use FireflyIII\Models\AvailableBudget;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Transformers\AvailableBudgetTransformer;
|
||||
use Laravel\Passport\Passport;
|
||||
@@ -62,7 +61,7 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
public function testStore(): void
|
||||
{
|
||||
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$abRepository = $this->mock(AvailableBudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$availableBudget = new AvailableBudget;
|
||||
@@ -76,8 +75,8 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
$factory->shouldReceive('find')->withArgs([2, ''])->once()->andReturn(TransactionCurrency::find(2));
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setAvailableBudget')->once()->andReturn($availableBudget);
|
||||
$abRepository->shouldReceive('setUser')->atLeast()->once();
|
||||
$abRepository->shouldReceive('store')->once()->andReturn($availableBudget);
|
||||
|
||||
// data to submit
|
||||
$data = [
|
||||
@@ -104,9 +103,9 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
{
|
||||
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$abRepository = $this->mock(AvailableBudgetRepositoryInterface::class);
|
||||
$availableBudget = new AvailableBudget;
|
||||
|
||||
// mock transformer
|
||||
@@ -120,8 +119,8 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
Amount::shouldReceive('getDefaultCurrency')->once()->andReturn(TransactionCurrency::find(5));
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('setAvailableBudget')->once()->andReturn($availableBudget);
|
||||
$abRepository->shouldReceive('setUser')->atLeast()->once();
|
||||
$abRepository->shouldReceive('store')->once()->andReturn($availableBudget);
|
||||
|
||||
// data to submit
|
||||
$data = [
|
||||
@@ -149,9 +148,9 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
$availableBudget = $this->user()->availableBudgets()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$abRepository = $this->mock(AvailableBudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
@@ -164,8 +163,8 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
Amount::shouldReceive('getDefaultCurrency')->once()->andReturn(TransactionCurrency::find(5));
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setAvailableBudget')->once()->andReturn($availableBudget);
|
||||
$abRepository->shouldReceive('setUser')->once();
|
||||
$abRepository->shouldReceive('store')->once()->andReturn($availableBudget);
|
||||
|
||||
// data to submit
|
||||
$data = [
|
||||
@@ -193,11 +192,11 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
{
|
||||
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||
// mock repositories
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$abRepository = $this->mock(AvailableBudgetRepositoryInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$euro = $this->getEuro();
|
||||
$euro = $this->getEuro();
|
||||
// mock facades:
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
|
||||
@@ -214,8 +213,8 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
$availableBudget = $this->user()->availableBudgets()->first();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
$repository->shouldReceive('updateAvailableBudget')->once()->andReturn($availableBudget);
|
||||
$abRepository->shouldReceive('setUser');
|
||||
$abRepository->shouldReceive('updateAvailableBudget')->once()->andReturn($availableBudget);
|
||||
$currencyRepository->shouldReceive('findNull')->andReturn($this->getEuro());
|
||||
|
||||
// data to submit
|
||||
|
@@ -24,9 +24,9 @@ declare(strict_types=1);
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
|
||||
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Transformers\BudgetLimitTransformer;
|
||||
use FireflyIII\Transformers\BudgetTransformer;
|
||||
@@ -66,9 +66,11 @@ class BudgetControllerTest extends TestCase
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetTransformer::class);
|
||||
$blRepository = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$blRepository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('store')->once()->andReturn($budget);
|
||||
|
||||
// mock transformer
|
||||
@@ -107,10 +109,12 @@ class BudgetControllerTest extends TestCase
|
||||
'amount' => 1,
|
||||
];
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$blRepository = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
|
||||
$repository->shouldReceive('storeBudgetLimit')->andReturn($budgetLimit)->once();
|
||||
$blRepository->shouldReceive('storeBudgetLimit')->andReturn($budgetLimit)->once();
|
||||
$blRepository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
@@ -140,11 +144,13 @@ class BudgetControllerTest extends TestCase
|
||||
// mock repositories
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetTransformer::class);
|
||||
$blRepository = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
/** @var Budget $budget */
|
||||
$budget = $this->user()->budgets()->first();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
$blRepository->shouldReceive('setUser');
|
||||
$repository->shouldReceive('update')->once()->andReturn(new Budget);
|
||||
|
||||
// mock calls to transformer:
|
||||
|
@@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
|
||||
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Transformers\BudgetLimitTransformer;
|
||||
use Laravel\Passport\Passport;
|
||||
@@ -58,8 +58,10 @@ class BudgetLimitControllerTest extends TestCase
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$blRepository = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
@@ -83,13 +85,13 @@ class BudgetLimitControllerTest extends TestCase
|
||||
'amount' => 1,
|
||||
];
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$repository->shouldReceive('findNull')->andReturn($budget)->once();
|
||||
$repository->shouldReceive('storeBudgetLimit')->andReturn($budgetLimit)->once();
|
||||
$blRepository->shouldReceive('storeBudgetLimit')->andReturn($budgetLimit)->once();
|
||||
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$blRepository->shouldReceive('setUser')->once();
|
||||
|
||||
// call API
|
||||
$response = $this->post(route('api.v1.budget_limits.store'), $data, ['Accept' => 'application/json']);
|
||||
@@ -113,8 +115,9 @@ class BudgetLimitControllerTest extends TestCase
|
||||
];
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$repository->shouldReceive('findNull')->andReturn(null)->once();
|
||||
//$repository->shouldReceive('findNull')->andReturn(null)->once();
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
$blRepository = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
@@ -134,6 +137,7 @@ class BudgetLimitControllerTest extends TestCase
|
||||
public function testUpdate(): void
|
||||
{
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
$blRepository = $this->mock(BudgetLimitRepositoryInterface::class);
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$budgetLimit = BudgetLimit::create(
|
||||
[
|
||||
@@ -152,7 +156,7 @@ class BudgetLimitControllerTest extends TestCase
|
||||
];
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$repository->shouldReceive('updateBudgetLimit')->andReturn($budgetLimit)->once();
|
||||
$blRepository->shouldReceive('updateBudgetLimit')->andReturn($budgetLimit)->once();
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
@@ -162,6 +166,7 @@ class BudgetLimitControllerTest extends TestCase
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$blRepository->shouldReceive('setUser')->once();
|
||||
|
||||
// call API
|
||||
$response = $this->put(route('api.v1.budget_limits.update', [$budgetLimit->id]), $data);
|
||||
|
@@ -24,6 +24,7 @@ namespace Tests\Api\V1\Controllers\Chart;
|
||||
|
||||
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
@@ -54,15 +55,16 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
{
|
||||
$availableBudget = $this->user()->availableBudgets()->first();
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$opsRepository = $this->mock(OperationsRepositoryInterface::class);
|
||||
|
||||
// get data:
|
||||
$budget = $this->getBudget();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$opsRepository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
|
||||
$repository->shouldReceive('spentInPeriodMc')->atLeast()->once()->
|
||||
andReturn(
|
||||
$opsRepository->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn(
|
||||
[
|
||||
[
|
||||
'currency_id' => 1,
|
||||
@@ -78,8 +80,10 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
'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 = $this->get(
|
||||
route('api.v1.chart.ab.overview', [$availableBudget->id]) . '?'
|
||||
. http_build_query($parameters), ['Accept' => 'application/json']
|
||||
);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
@@ -90,15 +94,15 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
{
|
||||
$availableBudget = $this->user()->availableBudgets()->first();
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
|
||||
$opsRepository = $this->mock(OperationsRepositoryInterface::class);
|
||||
// get data:
|
||||
$budget = $this->getBudget();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$opsRepository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
|
||||
$repository->shouldReceive('spentInPeriodMc')->atLeast()->once()->
|
||||
andReturn(
|
||||
$opsRepository->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn(
|
||||
[
|
||||
[
|
||||
'currency_id' => 1,
|
||||
@@ -114,8 +118,10 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
'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 = $this->get(
|
||||
route('api.v1.chart.ab.overview', [$availableBudget->id]) . '?'
|
||||
. http_build_query($parameters), ['Accept' => 'application/json']
|
||||
);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
|
@@ -27,11 +27,12 @@ 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\AvailableBudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Passport\Passport;
|
||||
@@ -57,95 +58,6 @@ class SummaryControllerTest extends TestCase
|
||||
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 = $this->getEuro();
|
||||
$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.
|
||||
*
|
||||
@@ -159,6 +71,8 @@ class SummaryControllerTest extends TestCase
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$netWorth = $this->mock(NetWorthInterface::class);
|
||||
$abRepos = $this->mock(AvailableBudgetRepositoryInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
$date = new Carbon();
|
||||
$date->addWeek();
|
||||
|
||||
@@ -194,6 +108,8 @@ class SummaryControllerTest extends TestCase
|
||||
$budgetRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$netWorth->shouldReceive('setUser')->atLeast()->once();
|
||||
$opsRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$abRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// mock collector calls:
|
||||
$collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
|
||||
@@ -217,9 +133,9 @@ class SummaryControllerTest extends TestCase
|
||||
$billRepos->shouldReceive('getBillsUnpaidInRangePerCurrency')->atLeast()->once()->andReturn([1 => '123', 2 => '456']);
|
||||
|
||||
// budget repos
|
||||
$budgetRepos->shouldReceive('getAvailableBudgetWithCurrency')->atLeast()->once()->andReturn([1 => '123', 2 => '456']);
|
||||
$abRepos->shouldReceive('getAvailableBudgetWithCurrency')->atLeast()->once()->andReturn([1 => '123', 2 => '456']);
|
||||
$budgetRepos->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
|
||||
$budgetRepos->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn(
|
||||
$opsRepos->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn(
|
||||
[
|
||||
[
|
||||
'currency_id' => 3,
|
||||
@@ -256,4 +172,97 @@ class SummaryControllerTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
// TODO AFTER 4.8,0: check if JSON is correct
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
$abRepos = $this->mock(AvailableBudgetRepositoryInterface::class);
|
||||
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
|
||||
|
||||
// data
|
||||
$euro = $this->getEuro();
|
||||
$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();
|
||||
$abRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$opsRepos->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
|
||||
$abRepos->shouldReceive('getAvailableBudgetWithCurrency')->atLeast()->once()->andReturn([1 => '123']);
|
||||
$budgetRepos->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
|
||||
$opsRepos->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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user