mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-19 19:01:39 +00:00
Fix test cases.
This commit is contained in:
@@ -28,6 +28,7 @@ use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\Actions\SetDestinationAccount;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -47,6 +48,7 @@ class SetDestinationAccountTest extends TestCase
|
||||
*/
|
||||
public function testActDepositExisting()
|
||||
{
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$type = TransactionType::whereType(TransactionType::DEPOSIT)->first();
|
||||
$journal = TransactionJournal::where('transaction_type_id', $type->id)->first();
|
||||
$destinationTr = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
@@ -56,6 +58,10 @@ class SetDestinationAccountTest extends TestCase
|
||||
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $destination->id)->first();
|
||||
$this->assertNotEquals($destination->id, $account->id);
|
||||
|
||||
// find account? Return account:
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('findByName')->andReturn($account);
|
||||
|
||||
// fire the action:
|
||||
$ruleAction = new RuleAction;
|
||||
$ruleAction->action_value = $account->name;
|
||||
@@ -71,34 +77,6 @@ class SetDestinationAccountTest extends TestCase
|
||||
$this->assertEquals($newDestination->id, $account->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give deposit new asset account (will fail)
|
||||
*
|
||||
* @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount::__construct()
|
||||
* @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount::act()
|
||||
* @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount::findAssetAccount()
|
||||
*/
|
||||
public function testActDepositNew()
|
||||
{
|
||||
$type = TransactionType::whereType(TransactionType::DEPOSIT)->first();
|
||||
$journal = TransactionJournal::where('transaction_type_id', $type->id)->first();
|
||||
$destinationTr = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$destination = $destinationTr->account;
|
||||
|
||||
// fire the action:
|
||||
$ruleAction = new RuleAction;
|
||||
$ruleAction->action_value = 'Some new asset ' . rand(1, 1000);
|
||||
$action = new SetDestinationAccount($ruleAction);
|
||||
$result = $action->act($journal);
|
||||
$this->assertFalse($result);
|
||||
|
||||
// test journal for still having old account
|
||||
$journal = TransactionJournal::find($journal->id);
|
||||
$destinationTr = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$newDestination = $destinationTr->account;
|
||||
$this->assertEquals($destination->id, $newDestination->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give withdrawal existing expense account.
|
||||
*
|
||||
@@ -108,6 +86,7 @@ class SetDestinationAccountTest extends TestCase
|
||||
*/
|
||||
public function testActWithdrawalExisting()
|
||||
{
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
|
||||
$journal = TransactionJournal::where('transaction_type_id', $type->id)->first();
|
||||
$destinationTr = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
@@ -117,6 +96,10 @@ class SetDestinationAccountTest extends TestCase
|
||||
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $destination->id)->first();
|
||||
$this->assertNotEquals($destination->id, $account->id);
|
||||
|
||||
// find account? Return account:
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('findByName')->andReturn($account);
|
||||
|
||||
// fire the action:
|
||||
$ruleAction = new RuleAction;
|
||||
$ruleAction->action_value = $account->name;
|
||||
@@ -132,34 +115,6 @@ class SetDestinationAccountTest extends TestCase
|
||||
$this->assertEquals($newDestination->id, $account->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give withdrawal new expense account.
|
||||
*
|
||||
* @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount::__construct()
|
||||
* @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount::act()
|
||||
* @covers \FireflyIII\TransactionRules\Actions\SetDestinationAccount::findExpenseAccount
|
||||
*/
|
||||
public function testActWithdrawalNew()
|
||||
{
|
||||
$type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
|
||||
$journal = TransactionJournal::where('transaction_type_id', $type->id)->first();
|
||||
$destinationTr = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$destination = $destinationTr->account;
|
||||
|
||||
// fire the action:
|
||||
$ruleAction = new RuleAction;
|
||||
$ruleAction->action_value = 'Some new expense ' . rand(1, 1000);
|
||||
$action = new SetDestinationAccount($ruleAction);
|
||||
$result = $action->act($journal);
|
||||
$this->assertTrue($result);
|
||||
|
||||
// test journal for new account
|
||||
$journal = TransactionJournal::find($journal->id);
|
||||
$destinationTr = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$newDestination = $destinationTr->account;
|
||||
$this->assertNotEquals($destination->id, $newDestination->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test this on a split journal.
|
||||
*
|
||||
@@ -168,10 +123,15 @@ class SetDestinationAccountTest extends TestCase
|
||||
*/
|
||||
public function testSplitJournal()
|
||||
{
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transaction = Transaction::orderBy('count', 'DESC')->groupBy('transaction_journal_id')
|
||||
->get(['transaction_journal_id', DB::raw('COUNT(transaction_journal_id) as count')])
|
||||
->first();
|
||||
$journal = TransactionJournal::find($transaction->transaction_journal_id);
|
||||
|
||||
// mock
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
|
||||
// fire the action:
|
||||
$ruleAction = new RuleAction;
|
||||
$ruleAction->action_value = 'Some new asset ' . rand(1, 1000);
|
||||
|
Reference in New Issue
Block a user