mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 20:16:22 +00:00
Make sure the convert controller works again.
This commit is contained in:
@@ -22,13 +22,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Transaction;
|
||||
|
||||
use Amount;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -54,101 +57,35 @@ class BulkControllerTest extends TestCase
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\BulkController
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\BulkController
|
||||
*/
|
||||
public function testEdit(): void
|
||||
public function testEditWithdrawal(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$journalRepos = $this->mockDefaultSession();
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$withdrawal = $this->getRandomWithdrawal();
|
||||
$withdrawalArray = $this->getRandomWithdrawalAsArray();
|
||||
|
||||
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
|
||||
|
||||
$collector->shouldReceive('setTypes')
|
||||
->withArgs([[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]])->atLeast()->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withTagInformation')->atLeast()->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setJournalIds')->atLeast()->once()->withArgs([[$withdrawal->id]])->andReturnSelf();
|
||||
$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([$withdrawalArray]);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
||||
$journalRepos->shouldReceive('getTransactionType')->andReturn('Transfer');
|
||||
$journalRepos->shouldReceive('isJournalReconciled')->andReturn(false);
|
||||
|
||||
$transfers = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(4)->get()->pluck('id')->toArray();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('transactions.bulk.edit', $transfers));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Bulk edit a number of transactions');
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\BulkController
|
||||
*/
|
||||
public function testEditMultiple(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')
|
||||
->andReturn(new Collection([1, 2, 3]), new Collection, new Collection, new Collection, new Collection([1]));
|
||||
$journalRepos->shouldReceive('getJournalDestinationAccounts')
|
||||
->andReturn(new Collection, new Collection([1, 2, 3]), new Collection, new Collection, new Collection([1]));
|
||||
$journalRepos->shouldReceive('getTransactionType')
|
||||
->andReturn('Withdrawal', 'Opening balance', 'Withdrawal', 'Withdrawal', 'Withdrawal');
|
||||
$journalRepos->shouldReceive('isJournalReconciled')
|
||||
->andReturn(true, false, false, false, false);
|
||||
|
||||
// default transactions
|
||||
$collection = $this->user()->transactionJournals()->take(5)->get();
|
||||
$allIds = $collection->pluck('id')->toArray();
|
||||
$route = route('transactions.bulk.edit', implode(',', $allIds));
|
||||
$this->be($this->user());
|
||||
$response = $this->get($route);
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Bulk edit a number of transactions');
|
||||
$response->assertSessionHas('info');
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
$response->assertSee('marked as reconciled');
|
||||
$response->assertSee('multiple source accounts');
|
||||
$response->assertSee('multiple destination accounts');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\BulkController
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\BulkController
|
||||
*/
|
||||
public function testEditNull(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal, null);
|
||||
$journalRepos->shouldReceive('getTransactionType')->andReturn('Transfer');
|
||||
$journalRepos->shouldReceive('isJournalReconciled')->andReturn(false);
|
||||
|
||||
$transfers = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(4)->get()->pluck('id')->toArray();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('transactions.bulk.edit', $transfers));
|
||||
$response = $this->get(route('transactions.bulk.edit', [$withdrawal->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Bulk edit a number of transactions');
|
||||
// has bread crumb
|
||||
@@ -161,34 +98,26 @@ class BulkControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$tags = ['a', 'b', 'c'];
|
||||
$collection = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->take(4)->get();
|
||||
$allIds = $collection->pluck('id')->toArray();
|
||||
|
||||
$data = [
|
||||
'category' => 'Some new category',
|
||||
'budget_id' => 1,
|
||||
$budget = $this->getRandomBudget();
|
||||
$category = $this->getRandomCategory();
|
||||
$withdrawal = $this->getRandomWithdrawalAsArray();
|
||||
$data = [
|
||||
'category' => $category->name,
|
||||
'budget_id' => $budget->id,
|
||||
'tags' => 'a,b,c',
|
||||
'journals' => $allIds,
|
||||
'journals' => [$withdrawal['transaction_journal_id']],
|
||||
];
|
||||
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$repository = $this->mockDefaultSession();
|
||||
|
||||
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('findNull')->times(4)->andReturn(new TransactionJournal);
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$repository->shouldReceive('updateCategory')->times(4)->andReturn(new TransactionJournal())
|
||||
->withArgs([Mockery::any(), $data['category']]);
|
||||
$repository->shouldReceive('updateBudget')->atLeast()->once()->andReturn(new TransactionJournal())->withArgs([Mockery::any(), $data['budget_id']]);
|
||||
$repository->shouldReceive('updateCategory')->atLeast()->once()->andReturn(new TransactionJournal())->withArgs([Mockery::any(), $data['category']]);
|
||||
$repository->shouldReceive('updateTags')->atLeast()->once()->andReturn(new TransactionJournal())->withArgs([Mockery::any(), $tags]);
|
||||
|
||||
$repository->shouldReceive('updateBudget')->times(4)->andReturn(new TransactionJournal())
|
||||
->withArgs([Mockery::any(), $data['budget_id']]);
|
||||
|
||||
$repository->shouldReceive('updateTags')->times(4)->andReturn(new TransactionJournal())
|
||||
->withArgs([Mockery::any(), ['tags' => $tags]]);
|
||||
$repository->shouldReceive('findNull')->atLeast()->once()->andReturn(new TransactionJournal);
|
||||
|
||||
|
||||
$route = route('transactions.bulk.update');
|
||||
@@ -198,40 +127,34 @@ class BulkControllerTest extends TestCase
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\BulkController
|
||||
* @covers \FireflyIII\Http\Requests\BulkEditJournalRequest
|
||||
*/
|
||||
public function testUpdateNull(): void
|
||||
public function testUpdateIgnoreAll(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$tags = ['a', 'b', 'c'];
|
||||
$collection = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->take(4)->get();
|
||||
$allIds = $collection->pluck('id')->toArray();
|
||||
|
||||
$data = [
|
||||
'category' => 'Some new category',
|
||||
'budget_id' => 1,
|
||||
'tags' => 'a,b,c',
|
||||
'journals' => $allIds,
|
||||
$budget = $this->getRandomBudget();
|
||||
$category = $this->getRandomCategory();
|
||||
$withdrawal = $this->getRandomWithdrawalAsArray();
|
||||
$data = [
|
||||
'category' => $category->name,
|
||||
'budget_id' => $budget->id,
|
||||
'tags' => 'a,b,c',
|
||||
'journals' => [$withdrawal['transaction_journal_id']],
|
||||
'ignore_category' => '1',
|
||||
'ignore_budget' => '1',
|
||||
'ignore_tags' => '1',
|
||||
];
|
||||
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$repository = $this->mockDefaultSession();
|
||||
|
||||
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('findNull')->times(4)->andReturn(new TransactionJournal, null);
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$repository->shouldReceive('updateCategory')->times(1)->andReturn(new TransactionJournal())
|
||||
->withArgs([Mockery::any(), $data['category']]);
|
||||
|
||||
$repository->shouldReceive('updateBudget')->times(1)->andReturn(new TransactionJournal())
|
||||
->withArgs([Mockery::any(), $data['budget_id']]);
|
||||
|
||||
$repository->shouldReceive('updateTags')->times(1)->andReturn(new TransactionJournal())
|
||||
->withArgs([Mockery::any(), ['tags' => $tags]]);
|
||||
$repository->shouldNotReceive('updateBudget');
|
||||
$repository->shouldNotReceive('updateCategory');
|
||||
$repository->shouldNotReceive('updateTags');
|
||||
$repository->shouldReceive('findNull')->atLeast()->once()->andReturn(new TransactionJournal);
|
||||
|
||||
|
||||
$route = route('transactions.bulk.update');
|
||||
|
Reference in New Issue
Block a user