Fix tests.

This commit is contained in:
James Cole
2018-07-01 09:27:22 +02:00
parent 0502f2a4a5
commit db149ca6e1
50 changed files with 551 additions and 647 deletions

View File

@@ -25,7 +25,6 @@ namespace Tests\Feature\Controllers\Transaction;
use Amount;
use DB;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -64,7 +63,15 @@ class ConvertControllerTest extends TestCase
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
// find deposit:
$loop = 0;
do {
$deposit = TransactionJournal::where('transaction_type_id', 2)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $deposit->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->once();
@@ -75,15 +82,12 @@ class ConvertControllerTest extends TestCase
$this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')
->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->andReturn(new Collection([$account]))->once();
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(3);
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(2);
Amount::shouldReceive('formatAnything')->andReturn('0')->once();
$this->be($this->user());
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$response = $this->get(route('transactions.convert.index', ['transfer', $deposit->id]));
$response->assertStatus(200);
$response->assertSee('Convert a deposit into a transfer');
@@ -96,7 +100,16 @@ class ConvertControllerTest extends TestCase
{
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
// find deposit:
$loop = 0;
do {
$deposit = TransactionJournal::where('transaction_type_id', 2)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $deposit->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->once();
@@ -107,7 +120,7 @@ class ConvertControllerTest extends TestCase
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->twice();
Amount::shouldReceive('formatAnything')->andReturn('0')->once();
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$this->be($this->user());
$response = $this->get(route('transactions.convert.index', ['withdrawal', $deposit->id]));
$response->assertStatus(200);
@@ -120,12 +133,21 @@ class ConvertControllerTest extends TestCase
public function testIndexSameType(): void
{
// mock stuff:
// find deposit:
$loop = 0;
do {
$deposit = TransactionJournal::where('transaction_type_id', 2)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $deposit->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$this->be($this->user());
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$response = $this->get(route('transactions.convert.index', ['deposit', $deposit->id]));
$response->assertStatus(302);
$response->assertSessionHas('info');
@@ -166,14 +188,21 @@ class ConvertControllerTest extends TestCase
public function testIndexTransferDeposit(): void
{
// mock stuff:
// find transfer:
$loop = 0;
do {
$transfer = TransactionJournal::where('transaction_type_id', 3)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $transfer->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('firstNull')->andReturn($transfer);
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->once();
$transfer = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->first();
$this->be($this->user());
$response = $this->get(route('transactions.convert.index', ['deposit', $transfer->id]));
$response->assertStatus(200);
@@ -185,6 +214,14 @@ class ConvertControllerTest extends TestCase
*/
public function testIndexTransferWithdrawal(): void
{
// find transfer:
$loop = 0;
do {
$transfer = TransactionJournal::where('transaction_type_id', 3)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $transfer->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
@@ -197,7 +234,6 @@ class ConvertControllerTest extends TestCase
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(2);
Amount::shouldReceive('formatAnything')->andReturn('0')->once();
$transfer = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->first();
$this->be($this->user());
$response = $this->get(route('transactions.convert.index', ['withdrawal', $transfer->id]));
$response->assertStatus(200);
@@ -209,6 +245,15 @@ class ConvertControllerTest extends TestCase
*/
public function testIndexWithdrawalDeposit(): void
{
// find withdrawal:
$loop = 0;
do {
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $withdrawal->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
@@ -221,7 +266,6 @@ class ConvertControllerTest extends TestCase
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(2);
Amount::shouldReceive('formatAnything')->andReturn('0')->once();
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
$this->be($this->user());
$response = $this->get(route('transactions.convert.index', ['deposit', $withdrawal->id]));
$response->assertStatus(200);
@@ -233,6 +277,14 @@ class ConvertControllerTest extends TestCase
*/
public function testIndexWithdrawalTransfer(): void
{
// find withdrawal:
$loop = 0;
do {
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $withdrawal->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
@@ -242,17 +294,13 @@ class ConvertControllerTest extends TestCase
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
$account = factory(Account::class)->make();
$this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')
->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->andReturn(new Collection([$account]))->once();
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(3);
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(2);
Amount::shouldReceive('formatAnything')->andReturn('0')->once();
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
$this->be($this->user());
$response = $this->get(route('transactions.convert.index', ['transfer', $withdrawal->id]));
$response->assertStatus(200);
@@ -274,12 +322,6 @@ class ConvertControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('find')->andReturn(new Account);
$account = $this->user()->accounts()->first();
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->twice();
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->twice();
$accountRepos->shouldReceive('findNull')->andReturn($account)->once();
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$data = ['source_account_asset' => 1];
$this->be($this->user());
@@ -304,8 +346,6 @@ class ConvertControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('store')->andReturn(new Account);
$account = $this->user()->accounts()->first();
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->twice();
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->twice();
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$data = ['destination_account_expense' => 'New expense name.'];
@@ -328,15 +368,8 @@ class ConvertControllerTest extends TestCase
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getCashAccount')->andReturn(new Account)->once();
$account = $this->user()->accounts()->first();
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->twice();
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->twice();
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$data = ['destination_account_expense' => ''];
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$data = ['destination_account_expense' => ''];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['withdrawal', $deposit->id]), $data);
$response->assertStatus(302);
@@ -353,6 +386,14 @@ class ConvertControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$account = $this->user()->accounts()->first();
// find withdrawal:
$loop = 0;
do {
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $withdrawal->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
// mock stuff
$messageBag = new MessageBag;
@@ -364,10 +405,7 @@ class ConvertControllerTest extends TestCase
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->twice();
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->twice();
$accountRepos->shouldReceive('findNull')->andReturn($account)->once();
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
$data = [
$data = [
'destination_account_asset' => 2,
];
$this->be($this->user());
@@ -434,6 +472,14 @@ class ConvertControllerTest extends TestCase
*/
public function testPostIndexTransferDeposit(): void
{
// find transfer:
$loop = 0;
do {
$transfer = TransactionJournal::where('transaction_type_id', 3)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $transfer->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('convert')->andReturn(new MessageBag);
@@ -446,8 +492,7 @@ class ConvertControllerTest extends TestCase
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->twice();
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->twice();
$transfer = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->first();
$data = ['source_account_revenue' => 'New rev'];
$data = ['source_account_revenue' => 'New rev'];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['deposit', $transfer->id]), $data);
$response->assertStatus(302);
@@ -466,13 +511,6 @@ class ConvertControllerTest extends TestCase
$repository->shouldReceive('convert')->andReturn(new MessageBag);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('store')->andReturn(new Account)->once();
$account = $this->user()->accounts()->first();
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->twice();
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->twice();
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
$data = ['source_account_revenue' => 'New revenue name.'];
$this->be($this->user());
@@ -493,13 +531,6 @@ class ConvertControllerTest extends TestCase
$repository->shouldReceive('convert')->andReturn(new MessageBag);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getCashAccount')->andReturn(new Account)->once();
$account = $this->user()->accounts()->first();
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->twice();
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->twice();
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
$data = ['source_account_revenue' => ''];
$this->be($this->user());
@@ -523,10 +554,6 @@ class ConvertControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('findNull')->andReturn(new Account);
$account = $this->user()->accounts()->first();
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->twice();
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->twice();
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
$data = ['destination_account_asset' => 2,];
$this->be($this->user());

View File

@@ -33,7 +33,6 @@ use FireflyIII\Models\Note;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
@@ -352,7 +351,7 @@ class SingleControllerTest extends TestCase
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
$response->assertSee(' name="destinationt_name" type="text" value="">');
$response->assertSee(' name="destination_name" type="text" value="">');
}
/**
@@ -592,8 +591,8 @@ class SingleControllerTest extends TestCase
'what' => 'withdrawal',
'amount' => '10',
'amount_currency_id_amount' => 1,
'source_id' => 1,
'destination_name' => 'Some destination',
'source_id' => 1,
'destination_name' => 'Some destination',
'date' => '2016-01-01',
'description' => 'Test descr',
];
@@ -645,8 +644,8 @@ class SingleControllerTest extends TestCase
'what' => 'withdrawal',
'amount' => '10',
'amount_currency_id_amount' => 1,
'source_id' => 1,
'destination_name' => 'Some destination',
'source_id' => 1,
'destination_name' => 'Some destination',
'date' => '2016-01-01',
'description' => 'Test descr',
];
@@ -700,8 +699,8 @@ class SingleControllerTest extends TestCase
'what' => 'deposit',
'amount' => '10',
'amount_currency_id_amount' => 1,
'destination_id' => 1,
'source_name' => 'Some source',
'destination_id' => 1,
'source_name' => 'Some source',
'date' => '2016-01-01',
'description' => 'Test descr',
];
@@ -756,8 +755,8 @@ class SingleControllerTest extends TestCase
'what' => 'transfer',
'amount' => '10',
'amount_currency_id_amount' => 1,
'destination_id' => 1,
'source_id' => 2,
'destination_id' => 1,
'source_id' => 2,
'date' => '2016-01-01',
'description' => 'Test descr',
];
@@ -814,8 +813,8 @@ class SingleControllerTest extends TestCase
'amount_currency_id_amount' => 1,
'source_account_currency' => 1,
'destination_account_currency' => 2,
'destination_id' => 1,
'source_id' => 2,
'destination_id' => 1,
'source_id' => 2,
'date' => '2016-01-01',
'description' => 'Test descr',
];
@@ -858,13 +857,15 @@ class SingleControllerTest extends TestCase
$this->assertTrue(false, $e->getMessage());
}
$journal = new TransactionJournal();
$type = TransactionType::find(1);
$journal->id = 1000;
$journal->description = 'New journal';
$journal->transactionType()->associate($type);
// find withdrawal:
$loop = 0;
do {
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
$count = $withdrawal->transactions()->count();
$loop++;
} while ($count !== 2 && $loop < 30);
$journalRepos->shouldReceive('update')->andReturn($journal);
$journalRepos->shouldReceive('update')->andReturn($withdrawal);
$this->session(['transactions.edit.uri' => 'http://localhost']);
$this->be($this->user());
@@ -872,8 +873,8 @@ class SingleControllerTest extends TestCase
'id' => 123,
'what' => 'withdrawal',
'description' => 'Updated groceries',
'source_id' => 1,
'destination_name' => 'PLUS',
'source_id' => 1,
'destination_name' => 'PLUS',
'amount' => '123',
'amount_currency_id_amount' => 1,
'budget_id' => 1,
@@ -882,13 +883,13 @@ class SingleControllerTest extends TestCase
'date' => '2016-01-01',
];
$response = $this->post(route('transactions.update', [123]), $data);
$response = $this->post(route('transactions.update', [$withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
$response = $this->get(route('transactions.show', [123]));
$response = $this->get(route('transactions.show', [$withdrawal->id]));
$response->assertStatus(200);
$response->assertSee('Updated groceries');
$response->assertSee($withdrawal->description);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}