Improve test coverage.

This commit is contained in:
James Cole
2018-03-04 07:56:30 +01:00
parent 7542175258
commit 2ab44fb33a
10 changed files with 603 additions and 55 deletions

View File

@@ -32,6 +32,7 @@ use FireflyIII\Factory\TransactionJournalMetaFactory;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Services\Internal\Update\JournalUpdateService;
use FireflyIII\Services\Internal\Update\TransactionUpdateService;
use Mockery;
use Tests\TestCase;
/**
@@ -81,6 +82,95 @@ class JournalUpdateServiceTest extends TestCase
$this->assertEquals(0, $result->transactions()->count());
}
/**
* @covers \FireflyIII\Services\Internal\Update\JournalUpdateService
* @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
*/
public function testUpdateBasicEmptyNote()
{
// mock other stuff:
$transactionFactory = $this->mock(TransactionFactory::class);
$transactionService = $this->mock(TransactionUpdateService::class);
$billFactory = $this->mock(BillFactory::class);
$tagFactory = $this->mock(TagFactory::class);
$metaFactory = $this->mock(TransactionJournalMetaFactory::class);
// mock calls
$billFactory->shouldReceive('setUser');
$billFactory->shouldReceive('find')->andReturn(null);
$transactionService->shouldReceive('setUser');
$transactionFactory->shouldReceive('setUser');
$tagFactory->shouldReceive('setUser');
$metaFactory->shouldReceive('setUser');
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 2)->first();
$data = [
'description' => 'Updated journal #' . rand(1, 1000),
'date' => new Carbon('2018-01-01'),
'bill_id' => null,
'bill_name' => null,
'tags' => [],
'notes' => '',
'transactions' => [],
];
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);
$result = $service->update($journal, $data);
$this->assertEquals($data['description'], $result->description);
$this->assertEquals(0, $result->transactions()->count());
$this->assertEquals(0, $result->notes()->count());
}
/**
* @covers \FireflyIII\Services\Internal\Update\JournalUpdateService
*/
public function testUpdateBudget()
{
$budget = $this->user()->budgets()->first();
$service = $this->mock(TransactionUpdateService::class);
$service->shouldReceive('setUser');
$service->shouldReceive('updateBudget')->withArgs([Mockery::any(), $budget->id])->twice();
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
// call update service to update budget. Should call transaction service twice.
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);
$service->updateBudget($journal, $budget->id);
}
/**
* @covers \FireflyIII\Services\Internal\Update\JournalUpdateService
*/
public function testUpdateCategory()
{
$service = $this->mock(TransactionUpdateService::class);
$service->shouldReceive('setUser');
$service->shouldReceive('updateCategory')->withArgs([Mockery::any(), 'New category'])->twice();
do {
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
// call update service to update budget. Should call transaction service twice.
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);
$service->updateCategory($journal, 'New category');
}
/**
* @covers \FireflyIII\Services\Internal\Update\JournalUpdateService
* @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait