mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Improve test coverage.
This commit is contained in:
@@ -24,8 +24,6 @@ declare(strict_types=1);
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollector;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
@@ -34,6 +32,8 @@ use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
@@ -269,38 +269,18 @@ class BudgetLimitControllerTest extends TestCase
|
||||
*/
|
||||
public function testTransactionsBasic(): void
|
||||
{
|
||||
$budgetLimit = BudgetLimit::first();
|
||||
|
||||
// get some transactions using the collector:
|
||||
Log::info('This transaction collector is OK, because it is used in a test:');
|
||||
$collector = new TransactionCollector;
|
||||
$collector->setUser($this->user());
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
|
||||
$collector->setAllAssetAccounts();
|
||||
$collector->setLimit(5)->setPage(1);
|
||||
try {
|
||||
$paginator = $collector->getPaginatedTransactions();
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
|
||||
// mock stuff:
|
||||
$budgetLimit = BudgetLimit::first();
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$billRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$budgetRepos->shouldReceive('setUser');
|
||||
|
||||
|
||||
$repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('Note');
|
||||
$repository->shouldReceive('getMetaField')->atLeast()->once()->andReturn(null);
|
||||
$repository->shouldReceive('getMetaDateString')->atLeast()->once()->andReturn('2018-01-01');
|
||||
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
@@ -321,7 +301,7 @@ class BudgetLimitControllerTest extends TestCase
|
||||
$response = $this->get(route('api.v1.budget_limits.transactions', [$budgetLimit->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => true, 'count' => true, 'per_page' => 5, 'current_page' => 1, 'total_pages' => true]],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
@@ -352,7 +332,6 @@ class BudgetLimitControllerTest extends TestCase
|
||||
];
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$repository->shouldReceive('findNull')->andReturn($budget)->once();
|
||||
$repository->shouldReceive('updateBudgetLimit')->andReturn($budgetLimit)->once();
|
||||
|
||||
|
||||
@@ -365,43 +344,4 @@ class BudgetLimitControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update of budget limit but submit bad budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BudgetLimitRequest
|
||||
*/
|
||||
public function testUpdateBadBudget(): void
|
||||
{
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$budgetLimit = BudgetLimit::create(
|
||||
[
|
||||
'budget_id' => $budget->id,
|
||||
'start_date' => '2018-01-01',
|
||||
'end_date' => '2018-01-31',
|
||||
'amount' => 1,
|
||||
]
|
||||
);
|
||||
$data
|
||||
= [
|
||||
'budget_id' => $budget->id,
|
||||
'start' => '2018-01-01',
|
||||
'end' => '2018-01-31',
|
||||
'amount' => 2,
|
||||
];
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$repository->shouldReceive('findNull')->andReturn(null)->once();
|
||||
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
// call API
|
||||
$response = $this->put('/api/v1/budgets/limits/' . $budgetLimit->id, $data);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Unknown budget.');
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user