mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-16 14:48:11 +00:00
Expand tests.
This commit is contained in:
@@ -46,6 +46,10 @@ class MassControllerTest extends TestCase
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
|
||||
$withdrawals = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->take(2)->get()->pluck('id')->toArray();
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('transactions.mass.delete', $withdrawals));
|
||||
@@ -60,6 +64,7 @@ class MassControllerTest extends TestCase
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
|
||||
$deposits = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->take(2)->get();
|
||||
$depositIds = $deposits->pluck('id')->toArray();
|
||||
|
||||
@@ -85,6 +90,20 @@ class MassControllerTest extends TestCase
|
||||
*/
|
||||
public function testEdit()
|
||||
{
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
$transfers = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(2)->get();
|
||||
$transfersArray = $transfers->pluck('id')->toArray();
|
||||
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
// mock data for edit page:
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('getTransactionType')->andReturn('Transfer');
|
||||
$journalRepos->shouldReceive('isJournalReconciled')->andReturn(false);
|
||||
$journalRepos->shouldReceive('getFirstPosTransaction')->andReturn($transfers->first()->transactions()->first());
|
||||
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
|
||||
@@ -93,10 +112,10 @@ class MassControllerTest extends TestCase
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection);
|
||||
|
||||
$transfers = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(2)->get()->pluck('id')->toArray();
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('transactions.mass.edit', $transfers));
|
||||
$response = $this->get(route('transactions.mass.edit', $transfersArray));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Edit a number of transactions');
|
||||
// has bread crumb
|
||||
@@ -108,45 +127,30 @@ class MassControllerTest extends TestCase
|
||||
*/
|
||||
public function testEditMultiple()
|
||||
{
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection);
|
||||
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
|
||||
|
||||
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')
|
||||
->andReturn(new Collection([1, 2, 3]), new Collection, new Collection, new Collection);
|
||||
$journalRepos->shouldReceive('getJournalDestinationAccounts')
|
||||
->andReturn(new Collection, new Collection([1, 2, 3]), new Collection, new Collection);
|
||||
$journalRepos->shouldReceive('getTransactionType')
|
||||
->andReturn('Withdrawal', 'Opening balance');
|
||||
$journalRepos->shouldReceive('isJournalReconciled')
|
||||
->andReturn(true, false);
|
||||
|
||||
|
||||
// default transactions
|
||||
$collection = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(2)->get();
|
||||
|
||||
// add deposit (with multiple sources)
|
||||
$collection->push(
|
||||
TransactionJournal::where('transaction_type_id', 2)
|
||||
->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')])
|
||||
);
|
||||
|
||||
// add withdrawal (with multiple destinations)
|
||||
$collection->push(
|
||||
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')])
|
||||
);
|
||||
|
||||
// add reconcile transaction
|
||||
$collection->push(
|
||||
TransactionJournal::where('transaction_type_id', 5)
|
||||
->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')])
|
||||
);
|
||||
|
||||
// add opening balance:
|
||||
$collection->push(TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first());
|
||||
$collection = $this->user()->transactionJournals()->take(4)->get();
|
||||
$allIds = $collection->pluck('id')->toArray();
|
||||
$route = route('transactions.mass.edit', join(',', $allIds));
|
||||
$this->be($this->user());
|
||||
@@ -165,20 +169,28 @@ class MassControllerTest extends TestCase
|
||||
*/
|
||||
public function testEditMultipleNothingLeft()
|
||||
{
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection);
|
||||
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
|
||||
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')
|
||||
->andReturn(new Collection([1, 2, 3]), new Collection, new Collection, new Collection);
|
||||
$journalRepos->shouldReceive('getJournalDestinationAccounts')
|
||||
->andReturn(new Collection, new Collection([1, 2, 3]), new Collection, new Collection);
|
||||
$journalRepos->shouldReceive('getTransactionType')
|
||||
->andReturn('Withdrawal', 'Opening balance');
|
||||
$journalRepos->shouldReceive('isJournalReconciled')
|
||||
->andReturn(true, true);
|
||||
|
||||
// default transactions
|
||||
$collection = new Collection;
|
||||
$collection->push(
|
||||
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')])
|
||||
);
|
||||
$collection = $this->user()->transactionJournals()->take(4)->get();
|
||||
$allIds = $collection->pluck('id')->toArray();
|
||||
|
||||
$this->be($this->user());
|
||||
@@ -198,11 +210,13 @@ class MassControllerTest extends TestCase
|
||||
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)
|
||||
->whereNull('deleted_at')
|
||||
->first();
|
||||
|
||||
// mock stuff
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('update')->once();
|
||||
$repository->shouldReceive('find')->once()->andReturn($deposit);
|
||||
$repository->shouldReceive('getTransactionType')->andReturn('Deposit');
|
||||
|
||||
$this->session(['transactions.mass-edit.uri' => 'http://localhost']);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user