mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Expand tests
This commit is contained in:
@@ -12,10 +12,13 @@ declare(strict_types = 1);
|
||||
namespace Tests\Feature\Controllers\Transaction;
|
||||
|
||||
|
||||
use DB;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -47,6 +50,10 @@ class ConvertControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndexDepositWithdrawal()
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once()->andReturn(new Collection);
|
||||
|
||||
$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]));
|
||||
@@ -54,11 +61,52 @@ class ConvertControllerTest extends TestCase
|
||||
$response->assertSee('Convert a deposit into a withdrawal');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::index
|
||||
*/
|
||||
public function testIndexSameType()
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once()->andReturn(new Collection);
|
||||
|
||||
$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');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::index
|
||||
*/
|
||||
public function testIndexSplit()
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once()->andReturn(new Collection);
|
||||
|
||||
$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::index
|
||||
*/
|
||||
public function testIndexTransferDeposit()
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once()->andReturn(new Collection);
|
||||
|
||||
$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]));
|
||||
@@ -71,6 +119,10 @@ class ConvertControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndexTransferWithdrawal()
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once()->andReturn(new Collection);
|
||||
|
||||
$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]));
|
||||
@@ -83,6 +135,10 @@ class ConvertControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndexWithdrawalDeposit()
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once()->andReturn(new Collection);
|
||||
|
||||
$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]));
|
||||
@@ -95,6 +151,10 @@ class ConvertControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndexWithdrawalTransfer()
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once()->andReturn(new Collection);
|
||||
|
||||
$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]));
|
||||
@@ -107,11 +167,169 @@ class ConvertControllerTest extends TestCase
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getSourceAccount
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getDestinationAccount
|
||||
*/
|
||||
public function testPostIndex()
|
||||
public function testPostIndexDepositTransfer()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
|
||||
$data = ['source_account_asset' => 1];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('transactions.convert.index', ['transfer', $deposit->id]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('transactions.show', [$deposit->id]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::postIndex
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getSourceAccount
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getDestinationAccount
|
||||
*/
|
||||
public function testPostIndexDepositWithdrawal()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
|
||||
$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);
|
||||
$response->assertRedirect(route('transactions.show', [$deposit->id]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::postIndex
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getSourceAccount
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getDestinationAccount
|
||||
*/
|
||||
public function testPostIndexErrored()
|
||||
{
|
||||
// mock stuff
|
||||
$messageBag = new MessageBag;
|
||||
$messageBag->add('fake', 'fake error');
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('convert')->andReturn($messageBag);
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
|
||||
// convert a withdrawal to a transfer. Requires the ID of another asset account.
|
||||
$data = [
|
||||
$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::postIndex
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getSourceAccount
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getDestinationAccount
|
||||
*/
|
||||
public function testPostIndexSameType()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
|
||||
$data = [
|
||||
'destination_account_asset' => 2,
|
||||
];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('transactions.convert.index', ['withdrawal', $withdrawal->id]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('error');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::postIndex
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getSourceAccount
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getDestinationAccount
|
||||
*/
|
||||
public function testPostIndexSplit()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$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 = [
|
||||
'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::postIndex
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getSourceAccount
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getDestinationAccount
|
||||
*/
|
||||
public function testPostIndexTransferDeposit()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$transfer = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->first();
|
||||
$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::postIndex
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getSourceAccount
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getDestinationAccount
|
||||
*/
|
||||
public function testPostIndexWithdrawalDeposit()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
||||
$repository->shouldReceive('first')->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::postIndex
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getSourceAccount
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getDestinationAccount
|
||||
*/
|
||||
public function testPostIndexWithdrawalTransfer()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
|
||||
$data = [
|
||||
'destination_account_asset' => 2,
|
||||
];
|
||||
$this->be($this->user());
|
||||
|
Reference in New Issue
Block a user