|
|
|
@ -63,7 +63,7 @@ class ConvertControllerTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
// mock stuff:
|
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
|
|
|
|
|
|
|
|
|
// find deposit:
|
|
|
|
@ -97,7 +97,7 @@ class ConvertControllerTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
// mock stuff:
|
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
|
|
|
|
|
|
|
|
|
// find deposit:
|
|
|
|
@ -130,7 +130,7 @@ class ConvertControllerTest extends TestCase
|
|
|
|
|
// find deposit:
|
|
|
|
|
$deposit = $this->getRandomDeposit();
|
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
|
|
|
|
|
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
|
|
|
|
|
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
|
|
|
@ -149,7 +149,7 @@ class ConvertControllerTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
// mock stuff:
|
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
|
|
|
|
|
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
|
|
|
|
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
|
|
|
@ -183,7 +183,7 @@ class ConvertControllerTest extends TestCase
|
|
|
|
|
// find transfer:
|
|
|
|
|
$transfer = $this->getRandomTransfer();
|
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
|
|
|
|
|
|
|
|
|
$journalRepos->shouldReceive('firstNull')->andReturn($transfer);
|
|
|
|
@ -206,7 +206,7 @@ class ConvertControllerTest extends TestCase
|
|
|
|
|
$transfer = $this->getRandomTransfer();
|
|
|
|
|
// mock stuff:
|
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
|
|
|
|
|
|
|
|
|
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
|
|
|
@ -235,7 +235,7 @@ class ConvertControllerTest extends TestCase
|
|
|
|
|
$withdrawal = $this->getRandomWithdrawal();
|
|
|
|
|
// mock stuff:
|
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
|
|
|
|
|
|
|
|
|
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
|
|
|
@ -263,7 +263,7 @@ class ConvertControllerTest extends TestCase
|
|
|
|
|
$withdrawal = $this->getRandomWithdrawal();
|
|
|
|
|
// mock stuff:
|
|
|
|
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
|
|
|
|
|
|
|
|
|
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
|
|
|
@ -291,17 +291,25 @@ class ConvertControllerTest extends TestCase
|
|
|
|
|
*/
|
|
|
|
|
public function testPostIndexDepositTransfer(): void
|
|
|
|
|
{
|
|
|
|
|
Log::info(sprintf('Now in test %s', __METHOD__));
|
|
|
|
|
// mock stuff
|
|
|
|
|
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
|
|
|
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
|
$accountRepos->shouldReceive('find')->andReturn(new Account);
|
|
|
|
|
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
|
|
|
|
|
$data = ['source_account_asset' => 1];
|
|
|
|
|
|
|
|
|
|
// get journal:
|
|
|
|
|
$deposit = $this->getRandomDeposit();
|
|
|
|
|
$source = $this->getRandomRevenue();
|
|
|
|
|
$destination = $this->getRandomAsset();
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$source]))->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$destination]))->atLeast()->once();
|
|
|
|
|
$accountRepos->shouldReceive('findNull')->andReturn(new Account)->atLeast()->once();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data = ['source_account_asset' => 1];
|
|
|
|
|
$this->be($this->user());
|
|
|
|
|
$response = $this->post(route('transactions.convert.index', ['transfer', $deposit->id]), $data);
|
|
|
|
|
$response->assertStatus(302);
|
|
|
|
@ -313,20 +321,25 @@ class ConvertControllerTest extends TestCase
|
|
|
|
|
*/
|
|
|
|
|
public function testPostIndexDepositWithdrawal(): void
|
|
|
|
|
{
|
|
|
|
|
Log::info(sprintf('Now in test %s', __METHOD__));
|
|
|
|
|
// mock stuff
|
|
|
|
|
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
|
|
|
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
|
$accountRepos->shouldReceive('store')->andReturn(new Account);
|
|
|
|
|
$account = $this->user()->accounts()->first();
|
|
|
|
|
|
|
|
|
|
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
|
|
|
|
|
$data = ['destination_account_expense' => 'New expense name.'];
|
|
|
|
|
// get journal:
|
|
|
|
|
$deposit = $this->getRandomDeposit();
|
|
|
|
|
$source = $this->getRandomRevenue();
|
|
|
|
|
$destination = $this->getRandomAsset();
|
|
|
|
|
$expense = $this->getRandomExpense();
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$source]))->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$destination]))->atLeast()->once();
|
|
|
|
|
$accountRepos->shouldReceive('store')->atLeast()->once()->andReturn($expense);
|
|
|
|
|
|
|
|
|
|
$data = ['destination_account_expense' => 'New expense name.'];
|
|
|
|
|
$this->be($this->user());
|
|
|
|
|
$response = $this->post(route('transactions.convert.index', ['withdrawal', $deposit->id]), $data);
|
|
|
|
|
$response->assertStatus(302);
|
|
|
|
@ -338,45 +351,58 @@ class ConvertControllerTest extends TestCase
|
|
|
|
|
*/
|
|
|
|
|
public function testPostIndexDepositWithdrawalEmptyName(): void
|
|
|
|
|
{
|
|
|
|
|
Log::info(sprintf('Now in test %s', __METHOD__));
|
|
|
|
|
// mock stuff
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
|
|
|
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
|
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
|
|
|
|
|
$data = ['destination_account_expense' => ''];
|
|
|
|
|
|
|
|
|
|
// get journal:
|
|
|
|
|
$deposit = $this->getRandomDeposit();
|
|
|
|
|
$source = $this->getRandomRevenue();
|
|
|
|
|
$destination = $this->getRandomAsset();
|
|
|
|
|
$expense = $this->getRandomExpense();
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$source]))->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$destination]))->atLeast()->once();
|
|
|
|
|
$accountRepos->shouldReceive('getCashAccount')->atLeast()->once()->andReturn($expense);
|
|
|
|
|
|
|
|
|
|
$data = ['destination_account_expense' => ''];
|
|
|
|
|
$this->be($this->user());
|
|
|
|
|
$response = $this->post(route('transactions.convert.index', ['withdrawal', $deposit->id]), $data);
|
|
|
|
|
$response->assertStatus(302);
|
|
|
|
|
$response->assertRedirect(route('transactions.show', [$deposit->id]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
|
|
|
|
|
*/
|
|
|
|
|
public function testPostIndexErrored(): void
|
|
|
|
|
{
|
|
|
|
|
Log::info(sprintf('Now in test %s', __METHOD__));
|
|
|
|
|
// mock stuff
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
|
|
|
|
|
$account = $this->user()->accounts()->first();
|
|
|
|
|
|
|
|
|
|
// find withdrawal:
|
|
|
|
|
$withdrawal = $this->getRandomWithdrawal();
|
|
|
|
|
|
|
|
|
|
// mock stuff
|
|
|
|
|
$messageBag = new MessageBag;
|
|
|
|
|
$messageBag->add('fake', 'fake error');
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn($messageBag);
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->twice();
|
|
|
|
|
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->twice();
|
|
|
|
|
$accountRepos->shouldReceive('findNull')->andReturn($account)->once();
|
|
|
|
|
// get journal:
|
|
|
|
|
$withdrawal = $this->getRandomWithdrawal();
|
|
|
|
|
$source = $this->getRandomRevenue();
|
|
|
|
|
$destination = $this->getRandomAsset();
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn($messageBag)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$source]))->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$destination]))->atLeast()->once();
|
|
|
|
|
$accountRepos->shouldReceive('findNull')->andReturn(new Account)->atLeast()->once();
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
|
'destination_account_asset' => 2,
|
|
|
|
|
];
|
|
|
|
@ -391,16 +417,17 @@ class ConvertControllerTest extends TestCase
|
|
|
|
|
*/
|
|
|
|
|
public function testPostIndexSameType(): void
|
|
|
|
|
{
|
|
|
|
|
Log::info(sprintf('Now in test %s', __METHOD__));
|
|
|
|
|
// mock stuff
|
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
|
|
|
// get journal:
|
|
|
|
|
$withdrawal = $this->getRandomWithdrawal();
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->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());
|
|
|
|
@ -414,21 +441,17 @@ class ConvertControllerTest extends TestCase
|
|
|
|
|
*/
|
|
|
|
|
public function testPostIndexSplit(): void
|
|
|
|
|
{
|
|
|
|
|
Log::info(sprintf('Now in test %s', __METHOD__));
|
|
|
|
|
// mock stuff
|
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
|
|
|
// get journal:
|
|
|
|
|
$withdrawal = $this->getRandomSplitWithdrawal();
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->once();
|
|
|
|
|
|
|
|
|
|
$withdrawal = TransactionJournal::where('transaction_type_id', 1)
|
|
|
|
|
->whereNull('transaction_journals.deleted_at')
|
|
|
|
|
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
|
|
|
|
->groupBy('transaction_journals.id')
|
|
|
|
|
->orderBy('ct', 'DESC')
|
|
|
|
|
->where('user_id', $this->user()->id)->first(['transaction_journals.id', DB::raw('count(transactions.`id`) as ct')]);
|
|
|
|
|
$data = [
|
|
|
|
|
$data = [
|
|
|
|
|
'destination_account_asset' => 2,
|
|
|
|
|
];
|
|
|
|
|
$this->be($this->user());
|
|
|
|
@ -442,22 +465,25 @@ class ConvertControllerTest extends TestCase
|
|
|
|
|
*/
|
|
|
|
|
public function testPostIndexTransferDeposit(): void
|
|
|
|
|
{
|
|
|
|
|
// find transfer:
|
|
|
|
|
$transfer = $this->getRandomTransfer();
|
|
|
|
|
Log::info(sprintf('Now in test %s', __METHOD__));
|
|
|
|
|
// mock stuff
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
|
|
|
|
|
|
// mock stuff
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
|
|
|
// get journal:
|
|
|
|
|
$transfer = $this->getRandomTransfer();
|
|
|
|
|
$source = $this->getRandomAsset();
|
|
|
|
|
$destination = $this->getRandomAsset();
|
|
|
|
|
$revenue = $this->getRandomRevenue();
|
|
|
|
|
|
|
|
|
|
$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();
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$source]))->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$destination]))->atLeast()->once();
|
|
|
|
|
$accountRepos->shouldReceive('store')->atLeast()->once()->andReturn($revenue);
|
|
|
|
|
|
|
|
|
|
$data = ['source_account_revenue' => 'New rev'];
|
|
|
|
|
$this->be($this->user());
|
|
|
|
@ -472,60 +498,82 @@ class ConvertControllerTest extends TestCase
|
|
|
|
|
public function testPostIndexWithdrawalDeposit(): void
|
|
|
|
|
{
|
|
|
|
|
// mock stuff
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
|
|
|
|
|
|
|
|
$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());
|
|
|
|
|
$response = $this->post(route('transactions.convert.index', ['deposit', $withdrawal->id]), $data);
|
|
|
|
|
$response->assertStatus(302);
|
|
|
|
|
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
|
|
|
|
|
*/
|
|
|
|
|
public function testPostIndexWithdrawalDepositEmptyName(): void
|
|
|
|
|
{
|
|
|
|
|
// mock stuff
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
|
|
|
|
|
|
|
|
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
|
|
|
|
|
$data = ['source_account_revenue' => ''];
|
|
|
|
|
$this->be($this->user());
|
|
|
|
|
$response = $this->post(route('transactions.convert.index', ['deposit', $withdrawal->id]), $data);
|
|
|
|
|
$response->assertStatus(302);
|
|
|
|
|
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
|
|
|
|
|
*/
|
|
|
|
|
public function testPostIndexWithdrawalTransfer(): void
|
|
|
|
|
{
|
|
|
|
|
// mock stuff
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
|
|
|
|
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
|
$accountRepos->shouldReceive('findNull')->andReturn(new Account);
|
|
|
|
|
|
|
|
|
|
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
|
|
|
|
|
$data = ['destination_account_asset' => 2,];
|
|
|
|
|
$withdrawal = $this->getRandomWithdrawal();
|
|
|
|
|
$source = $this->getRandomExpense();
|
|
|
|
|
$destination = $this->getRandomAsset();
|
|
|
|
|
$revenue = $this->getRandomRevenue();
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$source]))->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$destination]))->atLeast()->once();
|
|
|
|
|
$accountRepos->shouldReceive('store')->atLeast()->once()->andReturn($revenue);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data = ['source_account_revenue' => 'New revenue name.'];
|
|
|
|
|
$this->be($this->user());
|
|
|
|
|
$response = $this->post(route('transactions.convert.index', ['transfer', $withdrawal->id]), $data);
|
|
|
|
|
$response = $this->post(route('transactions.convert.index', ['deposit', $withdrawal->id]), $data);
|
|
|
|
|
$response->assertStatus(302);
|
|
|
|
|
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
|
|
|
|
|
*/
|
|
|
|
|
public function testPostIndexWithdrawalDepositEmptyName(): void
|
|
|
|
|
{
|
|
|
|
|
// mock stuff
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
|
|
|
|
|
|
$withdrawal = $this->getRandomWithdrawal();
|
|
|
|
|
$source = $this->getRandomExpense();
|
|
|
|
|
$destination = $this->getRandomAsset();
|
|
|
|
|
$revenue = $this->getRandomRevenue();
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$source]))->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$destination]))->atLeast()->once();
|
|
|
|
|
$accountRepos->shouldReceive('getCashAccount')->atLeast()->once()->andReturn($revenue);
|
|
|
|
|
|
|
|
|
|
$data = ['source_account_revenue' => ''];
|
|
|
|
|
$this->be($this->user());
|
|
|
|
|
$response = $this->post(route('transactions.convert.index', ['deposit', $withdrawal->id]), $data);
|
|
|
|
|
$response->assertStatus(302);
|
|
|
|
|
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
|
|
|
|
|
*/
|
|
|
|
|
public function testPostIndexWithdrawalTransfer(): void
|
|
|
|
|
{
|
|
|
|
|
// mock stuff
|
|
|
|
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
|
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
|
|
|
|
|
|
$withdrawal = $this->getRandomWithdrawal();
|
|
|
|
|
$source = $this->getRandomExpense();
|
|
|
|
|
$destination = $this->getRandomAsset();
|
|
|
|
|
$newDest = $this->getRandomAsset();
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('convert')->andReturn(new MessageBag)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$source]))->atLeast()->once();
|
|
|
|
|
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$destination]))->atLeast()->once();
|
|
|
|
|
$accountRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($newDest);
|
|
|
|
|
|
|
|
|
|
$data = ['destination_account_asset' => 2,];
|
|
|
|
|
$this->be($this->user());
|
|
|
|
|
$response = $this->post(route('transactions.convert.index', ['transfer', $withdrawal->id]), $data);
|
|
|
|
|
$response->assertStatus(302);
|
|
|
|
|
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|