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