Expand tests

This commit is contained in:
James Cole
2018-02-25 17:38:24 +01:00
parent 1aaf5fd288
commit 1a643e2042
4 changed files with 172 additions and 46 deletions

View File

@@ -58,11 +58,23 @@ class SplitControllerTest extends TestCase
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
$account = $destination->account;
$transactions = factory(Transaction::class, 3)->make();
$tasker = $this->mock(JournalTaskerInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn($deposit);
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('getTransactionType')->once()->andReturn('Deposit');
$journalRepos->shouldReceive('getJournalDate')->andReturn('2018-01-01')->once();
$journalRepos->shouldReceive('getMetaField')->andReturn('');
$journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->once();
$journalRepos->shouldReceive('getJournalBudgetId')->andReturn(0);
$journalRepos->shouldReceive('getCategoryName')->andReturn('');
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
$accountRepository->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])
->andReturn(new Collection([$account]))->once();
@@ -88,6 +100,7 @@ class SplitControllerTest extends TestCase
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
$account = $destination->account;
@@ -100,6 +113,17 @@ class SplitControllerTest extends TestCase
$budgetRepository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
$tasker->shouldReceive('getTransactionsOverview')->andReturn($transactions->toArray());
$journalRepos->shouldReceive('first')->once()->andReturn($deposit);
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('getTransactionType')->once()->andReturn('Deposit');
$journalRepos->shouldReceive('getJournalDate')->andReturn('2018-01-01')->once();
$journalRepos->shouldReceive('getMetaField')->andReturn('');
$journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->once();
$journalRepos->shouldReceive('getJournalBudgetId')->andReturn(0);
$journalRepos->shouldReceive('getCategoryName')->andReturn('');
$old = [
'transactions' => [
[
@@ -165,7 +189,10 @@ class SplitControllerTest extends TestCase
*/
public function testEditOpeningBalance()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$opening = TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first();
$journalRepos->shouldReceive('first')->once()->andReturn($opening);
$this->be($this->user());
$response = $this->get(route('transactions.split.edit', [$opening->id]));
$response->assertStatus(302);
@@ -184,17 +211,21 @@ class SplitControllerTest extends TestCase
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$repository = $this->mock(JournalRepositoryInterface::class);
$note = new Note();
$note->id = 1;
$note->text = 'Hallo';
$transactions = factory(Transaction::class, 1)->make();
$tasker = $this->mock(JournalTaskerInterface::class);
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
$account = $destination->account;
$repository->shouldReceive('getNote')->andReturn($note);
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('first')->once()->andReturn($deposit);
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]));
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]));
$repository->shouldReceive('getTransactionType')->once()->andReturn('Deposit');
$repository->shouldReceive('getJournalDate')->once()->andReturn('2018-01-01');
$repository->shouldReceive('getMetaField')->andReturn('');
$repository->shouldReceive('getNoteText')->andReturn('Some note')->once();
$repository->shouldReceive('getJournalBudgetId')->andReturn(0);
$repository->shouldReceive('getCategoryName')->andReturn('');
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
$accountRepository->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])
@@ -240,8 +271,9 @@ class SplitControllerTest extends TestCase
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('updateSplitJournal')->andReturn($deposit);
$repository->shouldReceive('first')->times(2)->andReturn(new TransactionJournal);
$repository->shouldReceive('update')->andReturn($deposit);
$repository->shouldReceive('first')->andReturn($deposit);
$repository->shouldReceive('getTransactionType')->andReturn('Deposit');
$attachmentRepos = $this->mock(AttachmentHelperInterface::class);
$attachmentRepos->shouldReceive('saveAttachmentsForModel');
@@ -252,13 +284,6 @@ class SplitControllerTest extends TestCase
$response->assertStatus(302);
$response->assertRedirect(route('index'));
$response->assertSessionHas('success');
// journal is updated?
$response = $this->get(route('transactions.show', [$deposit->id]));
$response->assertStatus(200);
$response->assertSee('Updated salary');
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
@@ -267,11 +292,12 @@ class SplitControllerTest extends TestCase
*/
public function testUpdateOpeningBalance()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$this->session(['transactions.edit-split.uri' => 'http://localhost']);
$opening = TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first();
$data = [
'id' => $opening->id,
'what' => 'deposit',
'what' => 'opening balance',
'journal_description' => 'Updated salary',
'journal_currency_id' => 1,
'journal_destination_account_id' => 1,
@@ -288,6 +314,18 @@ class SplitControllerTest extends TestCase
],
],
];
$journalRepos->shouldReceive('first')->once()->andReturn($opening);
// $journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]));
// $journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]));
//$journalRepos->shouldReceive('getTransactionType')->once()->andReturn('Opening balance');
// $journalRepos->shouldReceive('getJournalDate')->andReturn('2018-01-01')->once();
// $journalRepos->shouldReceive('getMetaField')->andReturn('');
// $journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->once();
// $journalRepos->shouldReceive('getJournalBudgetId')->andReturn(0);
// $journalRepos->shouldReceive('getCategoryName')->andReturn('');
$this->be($this->user());
$response = $this->post(route('transactions.split.update', [$opening->id]), $data);
$response->assertStatus(302);