Fix test for convert controller.

This commit is contained in:
James Cole
2019-07-13 20:57:06 +02:00
parent 7fd3f77c3e
commit 3eb695f2ad
4 changed files with 342 additions and 701 deletions

View File

@@ -23,19 +23,23 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Transaction;
use Amount;
use DB;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\Validation\AccountValidator;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
use Log;
use Mockery;
use Preferences;
use Steam;
use Tests\TestCase;
/**
@@ -62,30 +66,53 @@ class ConvertControllerTest extends TestCase
*/
public function testIndexDepositTransfer(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
$transformer = $this->mock(TransactionGroupTransformer::class);
$revenue = $this->getRandomRevenue();
$deposit = $this->getRandomDepositGroup();
$euro = $this->getEuro();
$asset = $this->getRandomAsset();
$loan = $this->getRandomLoan();
$expense = $this->getRandomExpense();
Steam::shouldReceive('balance')->atLeast()->once()->andReturn('100');
// mock calls:
$transformer->shouldReceive('transformObject')->atLeast()->once()->andReturn([]);
$accountRepos->shouldReceive('getActiveAccountsByType')
->atLeast()->once()->withArgs([[AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])
->andReturn(new Collection([$revenue]));
$accountRepos->shouldReceive('getActiveAccountsByType')
->atLeast()->once()->withArgs([[AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])
->andReturn(new Collection([$expense]));
$accountRepos->shouldReceive('getActiveAccountsByType')
->atLeast()->once()->withArgs([[AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])
->andReturn(new Collection([$loan]));
$accountRepos->shouldReceive('getActiveAccountsByType')
->atLeast()->once()->withArgs([[AccountType::ASSET]])
->andReturn(new Collection([$asset]));
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->withArgs([Mockery::any(), 'account_role'])->andReturn('', 'defaultAsset');
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
// $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();
// find deposit:
$deposit = $this->getRandomDeposit();
$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();
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
$account = factory(Account::class)->make();
$this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(2);
Amount::shouldReceive('formatAnything')->andReturn('0')->once();
// Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(2);
Amount::shouldReceive('formatAnything')->andReturn('0')->atLeast()->once();
$this->be($this->user());
@@ -94,56 +121,52 @@ class ConvertControllerTest extends TestCase
$response->assertSee('Convert a deposit into a transfer');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testIndexDepositWithdrawal(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
// find deposit:
$deposit = $this->getRandomDeposit();
$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();
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->twice();
Amount::shouldReceive('formatAnything')->andReturn('0')->once();
$this->be($this->user());
$response = $this->get(route('transactions.convert.index', ['withdrawal', $deposit->id]));
$response->assertStatus(200);
$response->assertSee('Convert a deposit into a withdrawal');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testIndexSameType(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
// mock stuff:
$this->mockDefaultSession();
$this->mock(UserRepositoryInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
$this->mock(TransactionGroupRepositoryInterface::class);
// find deposit:
$deposit = $this->getRandomDeposit();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$transformer = $this->mock(TransactionGroupTransformer::class);
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$revenue = $this->getRandomRevenue();
$deposit = $this->getRandomDepositGroup();
$euro = $this->getEuro();
$asset = $this->getRandomAsset();
$loan = $this->getRandomLoan();
$expense = $this->getRandomExpense();
Steam::shouldReceive('balance')->atLeast()->once()->andReturn('100');
// mock calls:
$transformer->shouldReceive('transformObject')->atLeast()->once()->andReturn([]);
$accountRepos->shouldReceive('getActiveAccountsByType')
->atLeast()->once()->withArgs([[AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])
->andReturn(new Collection([$revenue]));
$accountRepos->shouldReceive('getActiveAccountsByType')
->atLeast()->once()->withArgs([[AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])
->andReturn(new Collection([$expense]));
$accountRepos->shouldReceive('getActiveAccountsByType')
->atLeast()->once()->withArgs([[AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])
->andReturn(new Collection([$loan]));
$accountRepos->shouldReceive('getActiveAccountsByType')
->atLeast()->once()->withArgs([[AccountType::ASSET]])
->andReturn(new Collection([$asset]));
$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->withArgs([Mockery::any(), 'account_role'])->andReturn('', 'defaultAsset');
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
Amount::shouldReceive('formatAnything')->andReturn('0')->atLeast()->once();
$this->be($this->user());
@@ -152,199 +175,33 @@ class ConvertControllerTest extends TestCase
$response->assertSessionHas('info');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testIndexSplit(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$currencyRepos->shouldReceive('findNull')->andReturn($currency);
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->once();
$this->be($this->user());
$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')]);
$response = $this->get(route('transactions.convert.index', ['deposit', $withdrawal->id]));
$response->assertStatus(302);
$response->assertSessionHas('error');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testIndexTransferDeposit(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
// mock stuff:
// find transfer:
$transfer = $this->getRandomTransfer();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$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();
$this->be($this->user());
$response = $this->get(route('transactions.convert.index', ['deposit', $transfer->id]));
$response->assertStatus(200);
$response->assertSee('Convert a transfer into a deposit');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testIndexTransferWithdrawal(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
// find transfer:
$transfer = $this->getRandomTransfer();
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->once();
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(2);
Amount::shouldReceive('formatAnything')->andReturn('0')->once();
$this->be($this->user());
$response = $this->get(route('transactions.convert.index', ['withdrawal', $transfer->id]));
$response->assertStatus(200);
$response->assertSee('Convert a transfer into a withdrawal');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testIndexWithdrawalDeposit(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
// find withdrawal:
$withdrawal = $this->getRandomWithdrawal();
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->once();
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(2);
Amount::shouldReceive('formatAnything')->andReturn('0')->once();
$this->be($this->user());
$response = $this->get(route('transactions.convert.index', ['deposit', $withdrawal->id]));
$response->assertStatus(200);
$response->assertSee('Convert a withdrawal into a deposit');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testIndexWithdrawalTransfer(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
// find withdrawal:
$withdrawal = $this->getRandomWithdrawal();
// mock stuff:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->once();
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
$this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(2);
Amount::shouldReceive('formatAnything')->andReturn('0')->once();
$this->be($this->user());
$response = $this->get(route('transactions.convert.index', ['transfer', $withdrawal->id]));
$response->assertStatus(200);
$response->assertSee('Convert a withdrawal into a transfer');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testPostIndexDepositTransfer(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
$this->mockDefaultSession();
$repository = $this->mock(JournalRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$this->mock(RuleGroupRepositoryInterface::class);
$validator = $this->mock(AccountValidator::class);
$deposit = $this->getRandomDepositGroup();
return;
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);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn(new Collection);
$validator->shouldReceive('setUser')->atLeast()->once();
$validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['Transfer']);
$validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
$validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
// 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];
$data = ['source_account_id' => 1];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['transfer', $deposit->id]), $data);
$response = $this->post(route('transactions.convert.index.post', ['transfer', $deposit->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$deposit->id]));
}
@@ -352,316 +209,62 @@ class ConvertControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testPostIndexDepositWithdrawal(): void
public function testPostIndexBadSource(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
$this->mockDefaultSession();
$repository = $this->mock(JournalRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$this->mock(RuleGroupRepositoryInterface::class);
$validator = $this->mock(AccountValidator::class);
$deposit = $this->getRandomDepositGroup();
return;
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);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
// first journal:
$journal = $deposit->transactionJournals()->first();
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn(new Collection);
// get journal:
$deposit = $this->getRandomDeposit();
$source = $this->getRandomRevenue();
$destination = $this->getRandomAsset();
$expense = $this->getRandomExpense();
$repository->shouldReceive('convert')->andReturn(new MessageBag)->atLeast()->once();
$validator->shouldReceive('setUser')->atLeast()->once();
$validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['Transfer']);
$validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(false);
$validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
$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.'];
$data = ['source_account_id' => 1];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['withdrawal', $deposit->id]), $data);
$response = $this->post(route('transactions.convert.index.post', ['transfer', $deposit->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$deposit->id]));
$response->assertSessionHas('error', sprintf('Source information is invalid for transaction #%d.', $journal->id));
$response->assertRedirect(route('transactions.convert.index', ['transfer', $deposit->id]));
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testPostIndexDepositWithdrawalEmptyName(): void
public function testPostIndexBadDestination(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
$this->mockDefaultSession();
$repository = $this->mock(JournalRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$this->mock(RuleGroupRepositoryInterface::class);
$validator = $this->mock(AccountValidator::class);
$deposit = $this->getRandomDepositGroup();
return;
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);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
// first journal:
$journal = $deposit->transactionJournals()->first();
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn(new Collection);
// 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
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
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);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
// mock stuff
$messageBag = new MessageBag;
$messageBag->add('fake', 'fake error');
// 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,
];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['transfer', $withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.convert.index', ['transfer', $withdrawal->id]));
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testPostIndexSameType(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
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);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
// get journal:
$withdrawal = $this->getRandomWithdrawal();
$validator->shouldReceive('setUser')->atLeast()->once();
$validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['Transfer']);
$validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);
$validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(false);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->once();
$data = [
'destination_account_asset' => 2,
];
$data = ['source_account_id' => 1];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['withdrawal', $withdrawal->id]), $data);
$response = $this->post(route('transactions.convert.index.post', ['transfer', $deposit->id]), $data);
$response->assertStatus(302);
$response->assertSessionHas('error');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testPostIndexSplit(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
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);
// get journal:
$withdrawal = $this->getRandomSplitWithdrawal();
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->once();
$data = [
'destination_account_asset' => 2,
];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['transfer', $withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertSessionHas('error');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testPostIndexTransferDeposit(): void
{ $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
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);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn(new Collection);
// mock stuff
// get journal:
$transfer = $this->getRandomTransfer();
$source = $this->getRandomAsset();
$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 rev'];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['deposit', $transfer->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$transfer->id]));
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testPostIndexWithdrawalDeposit(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
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);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn(new Collection);
$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', ['deposit', $withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testPostIndexWithdrawalDepositEmptyName(): void
{ $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
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);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn(new Collection);
$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
{ $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
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);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn(new Collection);
$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]));
$response->assertSessionHas('error', sprintf('Destination information is invalid for transaction #%d.', $journal->id));
$response->assertRedirect(route('transactions.convert.index', ['transfer', $deposit->id]));
}
}

View File

@@ -443,6 +443,14 @@ abstract class TestCase extends BaseTestCase
return $this->getRandomGroup(TransactionType::WITHDRAWAL);
}
/**
* @return TransactionGroup
*/
protected function getRandomDepositGroup(): TransactionGroup
{
return $this->getRandomGroup(TransactionType::DEPOSIT);
}
/**
* @param string $class
*