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

@@ -29,6 +29,7 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\Note;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
use FireflyIII\Services\Internal\Update\AccountUpdateService;
use Tests\TestCase;
@@ -109,6 +110,62 @@ class AccountUpdateServiceTest extends TestCase
$this->assertEquals($data['name'], $account->name);
}
/**
* @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
*/
public function testUpdateBasicEmptyNote()
{
/** @var Account $account */
$account = $this->user()->accounts()->first();
$data = [
'name' => 'Some new name #' . rand(1, 1000),
'active' => true,
'virtualBalance' => '0',
'iban' => null,
'accountRole' => 'defaultAsset',
'notes' => '',
];
/** @var AccountUpdateService $service */
$service = app(AccountUpdateService::class);
$account = $service->update($account, $data);
$this->assertEquals($data['name'], $account->name);
$this->assertEquals(0, $account->notes()->count());
}
/**
* @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
*/
public function testUpdateBasicExistingNote()
{
/** @var Account $account */
$account = $this->user()->accounts()->first();
$note = new Note;
$note->noteable()->associate($account);
$note->text = 'Hi there';
$note->save();
$data = [
'name' => 'Some new name #' . rand(1, 1000),
'active' => true,
'virtualBalance' => '0',
'iban' => null,
'accountRole' => 'defaultAsset',
'notes' => '',
];
/** @var AccountUpdateService $service */
$service = app(AccountUpdateService::class);
$account = $service->update($account, $data);
$this->assertEquals($data['name'], $account->name);
$this->assertEquals(0, $account->notes()->count());
}
/**
* @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
@@ -161,6 +218,61 @@ class AccountUpdateServiceTest extends TestCase
$this->assertEquals($data['notes'], $note->text);
}
/**
* @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
*/
public function testUpdateExistingIBZero()
{
$deleteService = $this->mock(JournalDestroyService::class);
$deleteService->shouldReceive('destroy')->once();
/** @var Account $account */
$account = Account::create(
['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . rand(1, 1000),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
$opposing = $this->user()->accounts()->first();
$journal = TransactionJournal::create(
['user_id' => $this->user()->id, 'transaction_type_id' => 4, 'transaction_currency_id' => 1, 'description' => 'IB',
'date' => '2018-01-01', 'completed' => true,
]
);
// transactions:
Transaction::create(
['account_id' => $account->id, 'transaction_journal_id' => $journal->id,
'transaction_currency_id' => 1, 'amount' => '100', 'identifier' => 0,]
);
Transaction::create(
['account_id' => $opposing->id, 'transaction_journal_id' => $journal->id,
'transaction_currency_id' => 1, 'amount' => '-100', 'identifier' => 0,]
);
$data = [
'name' => 'Some new name #' . rand(1, 1000),
'active' => true,
'virtualBalance' => '0',
'iban' => null,
'accountRole' => 'defaultAsset',
'openingBalance' => '0',
'openingBalanceDate' => new Carbon('2018-01-01'),
'notes' => 'Hello',
'currency_id' => 1,
];
/** @var AccountUpdateService $service */
$service = app(AccountUpdateService::class);
$account = $service->update($account, $data);
$this->assertEquals($data['name'], $account->name);
$this->assertEquals(1, $account->transactions()->count());
$this->assertEquals(100, $account->transactions()->first()->amount);
/** @var Note $note */
$note = $account->notes()->first();
$this->assertEquals($data['notes'], $note->text);
}
/**
* @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait