Improve test coverage.

This commit is contained in:
James Cole
2018-03-03 17:16:47 +01:00
parent 9dc4c50527
commit 7542175258
28 changed files with 414 additions and 98 deletions

View File

@@ -138,6 +138,7 @@ class BulkControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\Transaction\BulkController::update
* @covers \FireflyIII\Http\Requests\BulkEditJournalRequest
*/
public function testUpdate()
{

View File

@@ -73,6 +73,7 @@ class LinkControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::store
* @covers \FireflyIII\Http\Requests\JournalLinkRequest
*/
public function testStore()
{
@@ -98,6 +99,7 @@ class LinkControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::store
* @covers \FireflyIII\Http\Requests\JournalLinkRequest
*/
public function testStoreAlreadyLinked()
{
@@ -122,6 +124,7 @@ class LinkControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::store
* @covers \FireflyIII\Http\Requests\JournalLinkRequest
*/
public function testStoreInvalid()
{

View File

@@ -230,7 +230,9 @@ class SingleControllerTest extends TestCase
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$account = $this->user()->accounts()->first();
$accountRepos->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection([$account]));
$accountRepos->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(
new Collection([$account])
);
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection)->once();
@@ -574,6 +576,7 @@ class SingleControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::groupedActiveAccountList
* @covers \FireflyIII\Http\Requests\JournalFormRequest
*/
public function testStoreError()
{
@@ -610,6 +613,7 @@ class SingleControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::groupedActiveAccountList
* @covers \FireflyIII\Http\Requests\JournalFormRequest
*/
public function testStoreSuccess()
{
@@ -659,8 +663,170 @@ class SingleControllerTest extends TestCase
$response->assertSessionHas('info');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::groupedActiveAccountList
* @covers \FireflyIII\Http\Requests\JournalFormRequest
*/
public function testStoreSuccessDeposit()
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$attRepos = $this->mock(AttachmentHelperInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
// mock results:
$journal = new TransactionJournal();
$journal->id = 1000;
$journal->description = 'New deposit';
$journalRepos->shouldReceive('store')->andReturn($journal);
$this->expectsEvents(StoredTransactionJournal::class);
$errors = new MessageBag;
$errors->add('attachments', 'Fake error');
$messages = new MessageBag;
$messages->add('attachments', 'Fake error');
// mock attachment helper, trigger an error AND and info thing.
$attRepos->shouldReceive('saveAttachmentsForModel');
$attRepos->shouldReceive('getErrors')->andReturn($errors);
$attRepos->shouldReceive('getMessages')->andReturn($messages);
$this->session(['transactions.create.uri' => 'http://localhost']);
$this->be($this->user());
$data = [
'what' => 'deposit',
'amount' => '10',
'amount_currency_id_amount' => 1,
'destination_account_id' => 1,
'source_account_name' => 'Some source',
'date' => '2016-01-01',
'description' => 'Test descr',
];
$response = $this->post(route('transactions.store', ['deposit']), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
$response->assertSessionHas('error');
$response->assertSessionHas('info');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::groupedActiveAccountList
* @covers \FireflyIII\Http\Requests\JournalFormRequest
*/
public function testStoreSuccessTransfer()
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$attRepos = $this->mock(AttachmentHelperInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
// mock results:
$journal = new TransactionJournal();
$journal->id = 1000;
$journal->description = 'New transfer';
$journalRepos->shouldReceive('store')->andReturn($journal);
$this->expectsEvents(StoredTransactionJournal::class);
$errors = new MessageBag;
$errors->add('attachments', 'Fake error');
$messages = new MessageBag;
$messages->add('attachments', 'Fake error');
// mock attachment helper, trigger an error AND and info thing.
$attRepos->shouldReceive('saveAttachmentsForModel');
$attRepos->shouldReceive('getErrors')->andReturn($errors);
$attRepos->shouldReceive('getMessages')->andReturn($messages);
$this->session(['transactions.create.uri' => 'http://localhost']);
$this->be($this->user());
$data = [
'what' => 'transfer',
'amount' => '10',
'amount_currency_id_amount' => 1,
'destination_account_id' => 1,
'source_account_id' => 2,
'date' => '2016-01-01',
'description' => 'Test descr',
];
$response = $this->post(route('transactions.store', ['transfer']), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
$response->assertSessionHas('error');
$response->assertSessionHas('info');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::groupedActiveAccountList
* @covers \FireflyIII\Http\Requests\JournalFormRequest
*/
public function testStoreSuccessTransferForeign()
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$attRepos = $this->mock(AttachmentHelperInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
// mock results:
$journal = new TransactionJournal();
$journal->id = 1000;
$journal->description = 'New transfer';
$journalRepos->shouldReceive('store')->andReturn($journal);
$this->expectsEvents(StoredTransactionJournal::class);
$errors = new MessageBag;
$errors->add('attachments', 'Fake error');
$messages = new MessageBag;
$messages->add('attachments', 'Fake error');
// mock attachment helper, trigger an error AND and info thing.
$attRepos->shouldReceive('saveAttachmentsForModel');
$attRepos->shouldReceive('getErrors')->andReturn($errors);
$attRepos->shouldReceive('getMessages')->andReturn($messages);
$this->session(['transactions.create.uri' => 'http://localhost']);
$this->be($this->user());
$data = [
'what' => 'transfer',
'amount' => '10',
'amount_currency_id_amount' => 1,
'source_account_currency' => 1,
'destination_account_currency' => 2,
'destination_account_id' => 1,
'source_account_id' => 2,
'date' => '2016-01-01',
'description' => 'Test descr',
];
$response = $this->post(route('transactions.store', ['transfer']), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
$response->assertSessionHas('error');
$response->assertSessionHas('info');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::update
* @covers \FireflyIII\Http\Requests\JournalFormRequest
*/
public function testUpdate()
{

View File

@@ -63,11 +63,11 @@ class SplitControllerTest extends TestCase
$attHelper = $this->mock(AttachmentHelperInterface::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;
$transactions = factory(Transaction::class, 3)->make();
$array = $transactions->toArray();
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
$account = $destination->account;
$transactions = factory(Transaction::class, 3)->make();
$array = $transactions->toArray();
$array[0]['category'] = '';
$journalRepos->shouldReceive('first')->once()->andReturn($deposit);
@@ -260,7 +260,8 @@ class SplitControllerTest extends TestCase
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::update
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::update
* @covers \FireflyIII\Http\Requests\SplitJournalFormRequest
*/
public function testUpdate()
{
@@ -315,8 +316,9 @@ class SplitControllerTest extends TestCase
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::update
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::isOpeningBalance
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::update
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::isOpeningBalance
* @covers \FireflyIII\Http\Requests\SplitJournalFormRequest
*/
public function testUpdateOpeningBalance()
{
@@ -356,4 +358,118 @@ class SplitControllerTest extends TestCase
$response->assertStatus(302);
$response->assertSessionMissing('success');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::update
* @covers \FireflyIII\Http\Requests\SplitJournalFormRequest
*/
public function testUpdateTransfer()
{
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$attHelper = $this->mock(AttachmentHelperInterface::class);
$tasker = $this->mock(JournalTaskerInterface::class);
$ruleRepos = $this->mock(RuleGroupRepositoryInterface::class);
$billRepos = $this->mock(BillRepositoryInterface::class);
$billRepos->shouldReceive('scan');
$ruleRepos->shouldReceive('getActiveGroups')->andReturn(new Collection);
$this->session(['transactions.edit-split.uri' => 'http://localhost']);
$transfer = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 3)->first();
$data = [
'id' => $transfer->id,
'what' => 'transfer',
'journal_description' => 'Some updated withdrawal',
'journal_currency_id' => 1,
'journal_source_account_id' => 1,
'journal_amount' => 1591,
'date' => '2014-01-24',
'tags' => '',
'transactions' => [
[
'description' => 'Split #1',
'source_account_id' => '1',
'destination_account_id' => '2',
'transaction_currency_id' => 1,
'amount' => 1591,
'category' => '',
],
],
];
// mock stuff
$journalRepos->shouldReceive('update')->andReturn($transfer);
$journalRepos->shouldReceive('first')->andReturn($transfer);
$journalRepos->shouldReceive('getTransactionType')->andReturn('Withdrawal');
$attHelper->shouldReceive('saveAttachmentsForModel');
$attHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
$this->be($this->user());
$response = $this->post(route('transactions.split.update', [$transfer->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('index'));
$response->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::update
* @covers \FireflyIII\Http\Requests\SplitJournalFormRequest
*/
public function testUpdateWithdrawal()
{
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$attHelper = $this->mock(AttachmentHelperInterface::class);
$tasker = $this->mock(JournalTaskerInterface::class);
$ruleRepos = $this->mock(RuleGroupRepositoryInterface::class);
$billRepos = $this->mock(BillRepositoryInterface::class);
$billRepos->shouldReceive('scan');
$ruleRepos->shouldReceive('getActiveGroups')->andReturn(new Collection);
$this->session(['transactions.edit-split.uri' => 'http://localhost']);
$withdrawal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->first();
$data = [
'id' => $withdrawal->id,
'what' => 'withdrawal',
'journal_description' => 'Some updated withdrawal',
'journal_currency_id' => 1,
'journal_source_account_id' => 1,
'journal_amount' => 1591,
'date' => '2014-01-24',
'tags' => '',
'transactions' => [
[
'description' => 'Split #1',
'source_account_id' => '1',
'destination_account_name' => 'some expense',
'transaction_currency_id' => 1,
'amount' => 1591,
'category' => '',
],
],
];
// mock stuff
$journalRepos->shouldReceive('update')->andReturn($withdrawal);
$journalRepos->shouldReceive('first')->andReturn($withdrawal);
$journalRepos->shouldReceive('getTransactionType')->andReturn('Withdrawal');
$attHelper->shouldReceive('saveAttachmentsForModel');
$attHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
$this->be($this->user());
$response = $this->post(route('transactions.split.update', [$withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('index'));
$response->assertSessionHas('success');
}
}