mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 12:11:19 +00:00
Expand tests.
This commit is contained in:
@@ -48,9 +48,16 @@ class ConvertControllerTest extends TestCase
|
||||
public function testIndexDepositTransfer()
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once()->andReturn(new Collection);
|
||||
|
||||
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
|
||||
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
|
||||
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->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]));
|
||||
@@ -64,9 +71,15 @@ class ConvertControllerTest extends TestCase
|
||||
public function testIndexDepositWithdrawal()
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once()->andReturn(new Collection);
|
||||
|
||||
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
|
||||
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
|
||||
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->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]));
|
||||
@@ -80,9 +93,13 @@ class ConvertControllerTest extends TestCase
|
||||
public function testIndexSameType()
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once()->andReturn(new Collection);
|
||||
|
||||
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
|
||||
$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]));
|
||||
@@ -96,9 +113,13 @@ class ConvertControllerTest extends TestCase
|
||||
public function testIndexSplit()
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once()->andReturn(new Collection);
|
||||
|
||||
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
|
||||
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
@@ -117,9 +138,15 @@ class ConvertControllerTest extends TestCase
|
||||
public function testIndexTransferDeposit()
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once()->andReturn(new Collection);
|
||||
|
||||
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
|
||||
$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]));
|
||||
@@ -133,9 +160,15 @@ class ConvertControllerTest extends TestCase
|
||||
public function testIndexTransferWithdrawal()
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once()->andReturn(new Collection);
|
||||
|
||||
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
|
||||
$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', ['withdrawal', $transfer->id]));
|
||||
@@ -149,9 +182,15 @@ class ConvertControllerTest extends TestCase
|
||||
public function testIndexWithdrawalDeposit()
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once()->andReturn(new Collection);
|
||||
|
||||
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
|
||||
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
|
||||
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->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]));
|
||||
@@ -165,9 +204,15 @@ class ConvertControllerTest extends TestCase
|
||||
public function testIndexWithdrawalTransfer()
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once()->andReturn(new Collection);
|
||||
|
||||
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
|
||||
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
|
||||
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->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]));
|
||||
@@ -183,12 +228,18 @@ class ConvertControllerTest extends TestCase
|
||||
public function testPostIndexDepositTransfer()
|
||||
{
|
||||
// mock stuff
|
||||
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$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];
|
||||
@@ -206,12 +257,16 @@ class ConvertControllerTest extends TestCase
|
||||
public function testPostIndexDepositWithdrawal()
|
||||
{
|
||||
// mock stuff
|
||||
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$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.'];
|
||||
@@ -236,6 +291,11 @@ class ConvertControllerTest extends TestCase
|
||||
$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' => ''];
|
||||
$this->be($this->user());
|
||||
@@ -251,6 +311,10 @@ class ConvertControllerTest extends TestCase
|
||||
*/
|
||||
public function testPostIndexErrored()
|
||||
{
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$account = $this->user()->accounts()->first();
|
||||
|
||||
|
||||
// mock stuff
|
||||
$messageBag = new MessageBag;
|
||||
$messageBag->add('fake', 'fake error');
|
||||
@@ -258,6 +322,11 @@ class ConvertControllerTest extends TestCase
|
||||
$repository->shouldReceive('convert')->andReturn($messageBag);
|
||||
$repository->shouldReceive('first')->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();
|
||||
|
||||
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
|
||||
$data = [
|
||||
'destination_account_asset' => 2,
|
||||
@@ -276,7 +345,8 @@ class ConvertControllerTest extends TestCase
|
||||
public function testPostIndexSameType()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
@@ -298,6 +368,7 @@ class ConvertControllerTest extends TestCase
|
||||
public function testPostIndexSplit()
|
||||
{
|
||||
// mock stuff
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
@@ -332,6 +403,10 @@ class ConvertControllerTest extends TestCase
|
||||
$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();
|
||||
|
||||
$transfer = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->first();
|
||||
$data = ['source_account_revenue' => 'New rev'];
|
||||
$this->be($this->user());
|
||||
@@ -355,6 +430,10 @@ class ConvertControllerTest extends TestCase
|
||||
$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());
|
||||
@@ -378,6 +457,10 @@ class ConvertControllerTest extends TestCase
|
||||
$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());
|
||||
@@ -399,12 +482,14 @@ class ConvertControllerTest extends TestCase
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('find')->andReturn(new Account);
|
||||
$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,
|
||||
];
|
||||
$data = ['destination_account_asset' => 2,];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('transactions.convert.index', ['transfer', $withdrawal->id]), $data);
|
||||
$response->assertStatus(302);
|
||||
|
Reference in New Issue
Block a user