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());