Fix tests

This commit is contained in:
James Cole
2018-04-27 11:29:09 +02:00
parent 28bcff99f6
commit bb25132865
20 changed files with 81 additions and 118 deletions

View File

@@ -182,6 +182,8 @@ class AccountControllerTest extends TestCase
Steam::shouldReceive('balancesByAccounts')->andReturn([$account->id => '100']);
Steam::shouldReceive('getLastActivities')->andReturn([]);
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(),'accountNumber'])->andReturn('123');
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('accounts.index', ['asset']));

View File

@@ -66,6 +66,8 @@ class PiggyBankControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$piggyRepos->shouldReceive('getCurrentAmount')->andReturn('0');
$piggyRepos->shouldReceive('leftOnAccount')->andReturn('0');
$this->be($this->user());
$response = $this->get(route('piggy-banks.add', [1]));
$response->assertStatus(200);
@@ -81,6 +83,7 @@ class PiggyBankControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$piggyRepos->shouldReceive('getCurrentAmount')->andReturn('0');
$piggyRepos->shouldReceive('leftOnAccount')->andReturn('0');
$this->be($this->user());
$response = $this->get(route('piggy-banks.add-money-mobile', [1]));
@@ -200,8 +203,9 @@ class PiggyBankControllerTest extends TestCase
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('getPiggyBanks')->andReturn(new Collection([$one, $two]));
$repository->shouldReceive('getCurrentAmount')->andReturn('10');
$repository->shouldReceive('setUser');
Steam::shouldReceive('balanceIgnoreVirtual')->twice()->andReturn('1');
Steam::shouldReceive('balance')->twice()->andReturn('1');
$this->be($this->user());
$response = $this->get(route('piggy-banks.index'));

View File

@@ -86,16 +86,16 @@ class BulkControllerTest extends TestCase
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection);
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('getJournalSourceAccounts')
->andReturn(new Collection([1, 2, 3]), new Collection, new Collection, new Collection);
->andReturn(new Collection([1, 2, 3]), new Collection, new Collection, new Collection, new Collection([1]));
$journalRepos->shouldReceive('getJournalDestinationAccounts')
->andReturn(new Collection, new Collection([1, 2, 3]), new Collection, new Collection);
->andReturn(new Collection, new Collection([1, 2, 3]), new Collection, new Collection, new Collection([1]));
$journalRepos->shouldReceive('getTransactionType')
->andReturn('Withdrawal', 'Opening balance');
->andReturn('Withdrawal', 'Opening balance', 'Withdrawal', 'Withdrawal', 'Withdrawal');
$journalRepos->shouldReceive('isJournalReconciled')
->andReturn(true, false);
->andReturn(true, false, false, false, false);
// default transactions
$collection = $this->user()->transactionJournals()->take(4)->get();
$collection = $this->user()->transactionJournals()->take(5)->get();
$allIds = $collection->pluck('id')->toArray();
$route = route('transactions.bulk.edit', implode(',', $allIds));
$this->be($this->user());
@@ -110,43 +110,6 @@ class BulkControllerTest extends TestCase
$response->assertSee('multiple destination accounts');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\BulkController::edit
*/
public function testEditMultipleNothingLeft()
{
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection);
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('getJournalSourceAccounts')
->andReturn(new Collection([1, 2, 3]), new Collection, new Collection, new Collection);
$journalRepos->shouldReceive('getJournalDestinationAccounts')
->andReturn(new Collection, new Collection([1, 2, 3]), new Collection, new Collection);
$journalRepos->shouldReceive('getTransactionType')
->andReturn('Withdrawal', 'Opening balance');
$journalRepos->shouldReceive('isJournalReconciled')
->andReturn(true, true);
// default transactions
$collection = $this->user()->transactionJournals()->take(4)->get();
$allIds = $collection->pluck('id')->toArray();
$route = route('transactions.bulk.edit', implode(',', $allIds));
$this->be($this->user());
$response = $this->get($route);
$response->assertStatus(200);
$response->assertSee('Bulk edit a number of transactions');
$response->assertSessionHas('info');
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
$response->assertSessionHas('error', 'You have selected no valid transactions to edit.');
$response->assertSee('marked as reconciled');
$response->assertSee('multiple source accounts');
$response->assertSee('multiple destination accounts');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\BulkController::update
* @covers \FireflyIII\Http\Requests\BulkEditJournalRequest
@@ -166,7 +129,7 @@ class BulkControllerTest extends TestCase
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('find')->times(4)->andReturn(new TransactionJournal);
$repository->shouldReceive('findNull')->times(4)->andReturn(new TransactionJournal);
$repository->shouldReceive('updateCategory')->times(4)->andReturn(new TransactionJournal())
->withArgs([Mockery::any(), $data['category']]);

View File

@@ -81,7 +81,7 @@ class MassControllerTest extends TestCase
// mock deletion:
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('find')->andReturnValues([$deposits[0], $deposits[1]])->times(2);
$repository->shouldReceive('findNull')->andReturnValues([$deposits[0], $deposits[1]])->times(2);
$repository->shouldReceive('destroy')->times(2);
$this->session(['transactions.mass-delete.uri' => 'http://localhost']);
@@ -150,17 +150,17 @@ class MassControllerTest extends TestCase
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('getJournalSourceAccounts')
->andReturn(new Collection([1, 2, 3]), new Collection, new Collection, new Collection);
->andReturn(new Collection([1, 2, 3]), new Collection, new Collection, new Collection, new Collection([1]));
$journalRepos->shouldReceive('getJournalDestinationAccounts')
->andReturn(new Collection, new Collection([1, 2, 3]), new Collection, new Collection);
->andReturn(new Collection, new Collection([1, 2, 3]), new Collection, new Collection, new Collection([1]));
$journalRepos->shouldReceive('getTransactionType')
->andReturn('Withdrawal', 'Opening balance');
->andReturn('Withdrawal', 'Opening balance', 'Withdrawal', 'Withdrawal', 'Withdrawal');
$journalRepos->shouldReceive('isJournalReconciled')
->andReturn(true, false);
->andReturn(true, false, false, false, false);
// default transactions
$collection = $this->user()->transactionJournals()->take(4)->get();
$collection = $this->user()->transactionJournals()->take(5)->get();
$allIds = $collection->pluck('id')->toArray();
$route = route('transactions.mass.edit', implode(',', $allIds));
$this->be($this->user());
@@ -174,43 +174,6 @@ class MassControllerTest extends TestCase
$response->assertSee('multiple destination accounts');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\MassController::edit
*/
public function testEditMultipleNothingLeft()
{
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
// mock stuff:
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
$journalRepos->shouldReceive('getJournalSourceAccounts')
->andReturn(new Collection([1, 2, 3]), new Collection, new Collection, new Collection);
$journalRepos->shouldReceive('getJournalDestinationAccounts')
->andReturn(new Collection, new Collection([1, 2, 3]), new Collection, new Collection);
$journalRepos->shouldReceive('getTransactionType')
->andReturn('Withdrawal', 'Opening balance');
$journalRepos->shouldReceive('isJournalReconciled')
->andReturn(true, true);
// default transactions
$collection = $this->user()->transactionJournals()->take(4)->get();
$allIds = $collection->pluck('id')->toArray();
$this->be($this->user());
$response = $this->get(route('transactions.mass.edit', implode(',', $allIds)));
$response->assertStatus(200);
$response->assertSee('Edit a number of transactions');
$response->assertSessionHas('error', 'You have selected no valid transactions to edit.');
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\MassController::update

View File

@@ -209,6 +209,8 @@ class SingleControllerTest extends TestCase
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('destroy')->once();
$journalRepos->shouldReceive('getTransactionType')->once()->andReturn('Withdrawal');
$this->session(['transactions.delete.uri' => 'http://localhost']);
$this->be($this->user());