mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Fix test coverage.
This commit is contained in:
@@ -158,7 +158,7 @@ class CategoryController extends Controller
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function frontpage(CategoryRepositoryInterface $repository, AccountRepositoryInterface $accountRepository): JsonResponse
|
||||
public function frontPage(CategoryRepositoryInterface $repository, AccountRepositoryInterface $accountRepository): JsonResponse
|
||||
{
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
@@ -168,7 +168,7 @@ class CategoryController extends Controller
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.category.frontpage');
|
||||
if ($cache->has()) {
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
//return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// currency repos:
|
||||
@@ -200,14 +200,15 @@ class CategoryController extends Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// no category per currency:
|
||||
$noCategory = $repository->spentInPeriodPcWoCategory(new Collection, $start, $end);
|
||||
foreach ($noCategory as $currencyId => $spent) {
|
||||
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->findNull($currencyId);
|
||||
$tempData[] = [
|
||||
'name' => trans('firefly.no_category'),
|
||||
'spent' => bcmul($spent, '-1'),
|
||||
'spent_float' => (float)bcmul($spent, '-1'),
|
||||
'spent' => bcmul($spent['spent'], '-1'),
|
||||
'spent_float' => (float)bcmul($spent['spent'], '-1'),
|
||||
'currency_id' => $currencyId,
|
||||
];
|
||||
}
|
||||
|
@@ -133,9 +133,9 @@ class AccountTransformer extends AbstractTransformer
|
||||
*
|
||||
* @param string $accountType
|
||||
*
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
private function getAccountRole(Account $account, string $accountType): string
|
||||
private function getAccountRole(Account $account, string $accountType): ?string
|
||||
{
|
||||
$accountRole = $this->repository->getMetaValue($account, 'accountRole');
|
||||
if ('asset' !== $accountType || '' === (string)$accountRole) {
|
||||
@@ -146,13 +146,13 @@ class AccountTransformer extends AbstractTransformer
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param string $accountRole
|
||||
* @param string $accountType
|
||||
* @param Account $account
|
||||
* @param string|null $accountRole
|
||||
* @param string $accountType
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getCCInfo(Account $account, string $accountRole, string $accountType): array
|
||||
private function getCCInfo(Account $account, ?string $accountRole, string $accountType): array
|
||||
{
|
||||
$monthlyPaymentDate = null;
|
||||
$creditCardType = null;
|
||||
|
@@ -371,7 +371,7 @@ Route::group(
|
||||
['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers\Chart', 'prefix' => 'chart/category', 'as' => 'chart.category.'],
|
||||
function () {
|
||||
|
||||
Route::get('frontpage', ['uses' => 'CategoryController@frontpage', 'as' => 'frontpage']);
|
||||
Route::get('frontpage', ['uses' => 'CategoryController@frontPage', 'as' => 'frontpage']);
|
||||
Route::get('period/{category}', ['uses' => 'CategoryController@currentPeriod', 'as' => 'current']);
|
||||
Route::get('period/{category}/{date}', ['uses' => 'CategoryController@specificPeriod', 'as' => 'specific']);
|
||||
Route::get('all/{category}', ['uses' => 'CategoryController@all', 'as' => 'all']);
|
||||
|
@@ -60,6 +60,11 @@ class PreferencesControllerTest extends TestCase
|
||||
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();
|
||||
|
@@ -80,7 +80,7 @@ class AccountControllerTest extends TestCase
|
||||
$end = [$firstId => [1 => '121.45', 2 => '234.01',], $secondId => [1 => '121.45', 2 => '234.01',],];
|
||||
|
||||
// return them when collected:
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->andReturn($accounts);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE]])->andReturn($accounts);
|
||||
|
||||
// and return start and end balances:
|
||||
Steam::shouldReceive('balancesPerCurrencyByAccounts')->twice()->andReturn($start, $end);
|
||||
|
@@ -83,16 +83,37 @@ class CategoryControllerTest extends TestCase
|
||||
*
|
||||
* @param string $range
|
||||
*/
|
||||
public function testFrontpage(string $range): void
|
||||
public function testFrontPage(string $range): void
|
||||
{
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
// spent per currency data:
|
||||
$spentData = [
|
||||
1 => '-123.45',
|
||||
2 => '567.21',
|
||||
$spentNoCategory = [
|
||||
1 =>
|
||||
[
|
||||
'spent' => '-123.45',
|
||||
'currency_id' => 1,
|
||||
'currency_code' => 'X',
|
||||
'currency_symbol' => 'x',
|
||||
'currency_decimal_places' => 2,
|
||||
],
|
||||
];
|
||||
$spentData = [
|
||||
1 => [
|
||||
'name' => 'Car',
|
||||
'spent' => [
|
||||
1 => [
|
||||
'spent' => '-123.45',
|
||||
'currency_id' => 2,
|
||||
'currency_code' => 'a',
|
||||
'currency_symbol' => 'b',
|
||||
'currency_decimal_places' => 2,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// grab two categories from the user
|
||||
@@ -105,20 +126,10 @@ class CategoryControllerTest extends TestCase
|
||||
$repository->shouldReceive('getCategories')->andReturn($categories)->once();
|
||||
$accountRepos->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->andReturn($accounts);
|
||||
|
||||
$repository->shouldReceive('spentInPeriodPerCurrency')
|
||||
->times(2)->andReturn($spentData);
|
||||
$repository->shouldReceive('spentInPeriodPcWoCategory')->once()->andReturn($spentData);
|
||||
$repository->shouldReceive('spentInPeriodPerCurrency')->times(2)->andReturn($spentData);
|
||||
$repository->shouldReceive('spentInPeriodPcWoCategory')->once()->andReturn($spentNoCategory);
|
||||
|
||||
$currencyRepos->shouldReceive('findNull')->withArgs([1])->once()->andReturn(TransactionCurrency::find(1));
|
||||
$currencyRepos->shouldReceive('findNull')->withArgs([2])->once()->andReturn(TransactionCurrency::find(2));
|
||||
|
||||
//$category = factory(Category::class)->make();
|
||||
//$account = factory(Account::class)->make();
|
||||
|
||||
|
||||
// $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
|
||||
// $repository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||
// $repository->shouldReceive('spentInPeriodWithoutCategory')->andReturn('0');
|
||||
$generator->shouldReceive('multiSet')->andReturn([]);
|
||||
|
||||
$this->be($this->user());
|
||||
@@ -132,10 +143,10 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testReportPeriod(): void
|
||||
{
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$repository->shouldReceive('periodExpenses')->andReturn([])->once();
|
||||
@@ -152,10 +163,10 @@ class CategoryControllerTest extends TestCase
|
||||
*/
|
||||
public function testReportPeriodNoCategory(): void
|
||||
{
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$repository->shouldReceive('periodExpensesNoCategory')->andReturn([])->once();
|
||||
@@ -179,8 +190,8 @@ class CategoryControllerTest extends TestCase
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$account = factory(Account::class)->make();
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||
$date = new Carbon;
|
||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||
|
||||
|
Reference in New Issue
Block a user