mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-16 18:25:00 -06:00
Fix some tests.
This commit is contained in:
parent
fb0a0c3fb5
commit
3e22c9860e
@ -65,10 +65,10 @@ class SplitJournalFormRequest extends Request
|
||||
switch ($data['type']) {
|
||||
case 'withdrawal':
|
||||
$sourceId = $this->integer('journal_source_account_id');
|
||||
$destinationName = $transaction['destination_name'];
|
||||
$destinationName = $transaction['destination_name'] ?? '';
|
||||
break;
|
||||
case 'deposit':
|
||||
$sourceName = $transaction['source_name'];
|
||||
$sourceName = $transaction['source_name'] ?? '';
|
||||
$destinationId = $this->integer('journal_destination_account_id');
|
||||
break;
|
||||
case 'transfer':
|
||||
|
@ -150,7 +150,7 @@ class AccountTransformer extends TransformerAbstract
|
||||
if (strlen($role) === 0 || $type !== AccountType::ASSET) {
|
||||
$role = null;
|
||||
}
|
||||
$currencyId = (int)$this->repository->getMetaValue($account, 'currency_id');
|
||||
$currencyId = intval($this->repository->getMetaValue($account, 'currency_id'));
|
||||
$currencyCode = null;
|
||||
$decimalPlaces = 2;
|
||||
if ($currencyId > 0) {
|
||||
@ -197,7 +197,7 @@ class AccountTransformer extends TransformerAbstract
|
||||
'currency_code' => $currencyCode,
|
||||
'current_balance' => round(app('steam')->balance($account, $date), $decimalPlaces),
|
||||
'current_balance_date' => $date->format('Y-m-d'),
|
||||
'notes' => $this->repository->getNote($account),
|
||||
'notes' => $this->repository->getNoteText($account),
|
||||
'monthly_payment_date' => $monthlyPaymentDate,
|
||||
'credit_card_type' => $creditCardType,
|
||||
'account_number' => $this->repository->getMetaValue($account, 'accountNumber'),
|
||||
|
@ -31,6 +31,7 @@ use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Transformers\AccountTransformer;
|
||||
use Mockery;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -50,7 +51,9 @@ class AccountTransformerTest extends TestCase
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);
|
||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null);
|
||||
$accountRepos->shouldReceive('getMetaValue')->andReturn('2016-01-01');
|
||||
$accountRepos->shouldReceive('getMetaValue')->andReturn('1');
|
||||
$accountRepos->shouldReceive('getNoteText')->andReturn('');
|
||||
|
||||
// make new account:
|
||||
$account = Account::create(
|
||||
[
|
||||
@ -86,7 +89,8 @@ class AccountTransformerTest extends TestCase
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);
|
||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null);
|
||||
$accountRepos->shouldReceive('getMetaValue')->andReturn('2016-01-01');
|
||||
$accountRepos->shouldReceive('getMetaValue')->andReturn('1');
|
||||
$accountRepos->shouldReceive('getNoteText')->andReturn('');
|
||||
// make new account:
|
||||
$account = Account::create(
|
||||
[
|
||||
@ -119,12 +123,6 @@ class AccountTransformerTest extends TestCase
|
||||
*/
|
||||
public function testCCDataAsset()
|
||||
{
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getMetaValue')->andReturn('2016-01-01');
|
||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);
|
||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null);
|
||||
|
||||
// make new account:
|
||||
$account = Account::create(
|
||||
[
|
||||
@ -137,14 +135,6 @@ class AccountTransformerTest extends TestCase
|
||||
'encrypted' => 0,
|
||||
]
|
||||
);
|
||||
// add currency preference:
|
||||
AccountMeta::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'currency_id',
|
||||
'data' => 1, // euro
|
||||
]
|
||||
);
|
||||
|
||||
// add a note:
|
||||
$note = Note::create(
|
||||
@ -156,6 +146,27 @@ class AccountTransformerTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccMonthlyPaymentDate'])->andReturn('2018-02-01');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccType'])->andReturn('monthlyFull');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('123');
|
||||
$accountRepos->shouldReceive('getNoteText')->andReturn($note->text);
|
||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);
|
||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null);
|
||||
|
||||
// add currency preference:
|
||||
AccountMeta::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'currency_id',
|
||||
'data' => 1, // euro
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
// add credit card meta data (will be ignored)
|
||||
AccountMeta::create(
|
||||
[
|
||||
@ -202,9 +213,6 @@ class AccountTransformerTest extends TestCase
|
||||
*/
|
||||
public function testIgnoreCCExpense()
|
||||
{
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getMetaValue')->andReturn('2016-01-01');
|
||||
|
||||
// make new account:
|
||||
$account = Account::create(
|
||||
@ -218,15 +226,6 @@ class AccountTransformerTest extends TestCase
|
||||
'encrypted' => 0,
|
||||
]
|
||||
);
|
||||
// add currency preference:
|
||||
AccountMeta::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'currency_id',
|
||||
'data' => 1, // euro
|
||||
]
|
||||
);
|
||||
|
||||
// add a note:
|
||||
$note = Note::create(
|
||||
[
|
||||
@ -237,6 +236,22 @@ class AccountTransformerTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getMetaValue')->andReturn('1');
|
||||
$accountRepos->shouldReceive('getNoteText')->andReturn($note->text);
|
||||
|
||||
|
||||
// add currency preference:
|
||||
AccountMeta::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'currency_id',
|
||||
'data' => 1, // euro
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
// add credit card meta data (will be ignored)
|
||||
AccountMeta::create(
|
||||
[
|
||||
@ -287,7 +302,8 @@ class AccountTransformerTest extends TestCase
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn('45.67');
|
||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn('2018-01-01');
|
||||
$accountRepos->shouldReceive('getMetaValue')->andReturn('2016-01-01');
|
||||
$accountRepos->shouldReceive('getMetaValue')->andReturn('1');
|
||||
$accountRepos->shouldReceive('getNoteText')->andReturn('');
|
||||
// make new account:
|
||||
$account = Account::create(
|
||||
[
|
||||
@ -344,7 +360,8 @@ class AccountTransformerTest extends TestCase
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);
|
||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null);
|
||||
$accountRepos->shouldReceive('getMetaValue')->andReturn('2016-01-01');
|
||||
$accountRepos->shouldReceive('getMetaValue')->andReturn('1');
|
||||
$accountRepos->shouldReceive('getNote')->andReturn('');
|
||||
// make new account:
|
||||
$account = Account::create(
|
||||
[
|
||||
@ -384,11 +401,6 @@ class AccountTransformerTest extends TestCase
|
||||
*/
|
||||
public function testWithNotes()
|
||||
{
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);
|
||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null);
|
||||
$accountRepos->shouldReceive('getMetaValue')->andReturn('2016-01-01');
|
||||
// make new account:
|
||||
$account = Account::create(
|
||||
[
|
||||
@ -401,15 +413,6 @@ class AccountTransformerTest extends TestCase
|
||||
'encrypted' => 0,
|
||||
]
|
||||
);
|
||||
// add currency preference:
|
||||
AccountMeta::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'currency_id',
|
||||
'data' => 1, // euro
|
||||
]
|
||||
);
|
||||
|
||||
// add a note:
|
||||
$note = Note::create(
|
||||
[
|
||||
@ -420,6 +423,23 @@ class AccountTransformerTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);
|
||||
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn(null);
|
||||
$accountRepos->shouldReceive('getMetaValue')->andReturn('1');
|
||||
$accountRepos->shouldReceive('getNoteText')->andReturn($note->text);
|
||||
|
||||
// add currency preference:
|
||||
AccountMeta::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'currency_id',
|
||||
'data' => 1, // euro
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
$transformer = new AccountTransformer(new ParameterBag);
|
||||
$result = $transformer->transform($account);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user