Fix some tests.

This commit is contained in:
James Cole
2018-03-23 05:31:45 +01:00
parent fb0a0c3fb5
commit 3e22c9860e
3 changed files with 68 additions and 48 deletions

View File

@@ -65,10 +65,10 @@ class SplitJournalFormRequest extends Request
switch ($data['type']) { switch ($data['type']) {
case 'withdrawal': case 'withdrawal':
$sourceId = $this->integer('journal_source_account_id'); $sourceId = $this->integer('journal_source_account_id');
$destinationName = $transaction['destination_name']; $destinationName = $transaction['destination_name'] ?? '';
break; break;
case 'deposit': case 'deposit':
$sourceName = $transaction['source_name']; $sourceName = $transaction['source_name'] ?? '';
$destinationId = $this->integer('journal_destination_account_id'); $destinationId = $this->integer('journal_destination_account_id');
break; break;
case 'transfer': case 'transfer':

View File

@@ -150,7 +150,7 @@ class AccountTransformer extends TransformerAbstract
if (strlen($role) === 0 || $type !== AccountType::ASSET) { if (strlen($role) === 0 || $type !== AccountType::ASSET) {
$role = null; $role = null;
} }
$currencyId = (int)$this->repository->getMetaValue($account, 'currency_id'); $currencyId = intval($this->repository->getMetaValue($account, 'currency_id'));
$currencyCode = null; $currencyCode = null;
$decimalPlaces = 2; $decimalPlaces = 2;
if ($currencyId > 0) { if ($currencyId > 0) {
@@ -197,7 +197,7 @@ class AccountTransformer extends TransformerAbstract
'currency_code' => $currencyCode, 'currency_code' => $currencyCode,
'current_balance' => round(app('steam')->balance($account, $date), $decimalPlaces), 'current_balance' => round(app('steam')->balance($account, $date), $decimalPlaces),
'current_balance_date' => $date->format('Y-m-d'), 'current_balance_date' => $date->format('Y-m-d'),
'notes' => $this->repository->getNote($account), 'notes' => $this->repository->getNoteText($account),
'monthly_payment_date' => $monthlyPaymentDate, 'monthly_payment_date' => $monthlyPaymentDate,
'credit_card_type' => $creditCardType, 'credit_card_type' => $creditCardType,
'account_number' => $this->repository->getMetaValue($account, 'accountNumber'), 'account_number' => $this->repository->getMetaValue($account, 'accountNumber'),

View File

@@ -31,6 +31,7 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Transformers\AccountTransformer; use FireflyIII\Transformers\AccountTransformer;
use Mockery;
use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\ParameterBag;
use Tests\TestCase; use Tests\TestCase;
@@ -50,7 +51,9 @@ class AccountTransformerTest extends TestCase
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null); $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);
$accountRepos->shouldReceive('getOpeningBalanceDate')->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: // make new account:
$account = Account::create( $account = Account::create(
[ [
@@ -86,7 +89,8 @@ class AccountTransformerTest extends TestCase
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null); $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);
$accountRepos->shouldReceive('getOpeningBalanceDate')->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: // make new account:
$account = Account::create( $account = Account::create(
[ [
@@ -119,12 +123,6 @@ class AccountTransformerTest extends TestCase
*/ */
public function testCCDataAsset() 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: // make new account:
$account = Account::create( $account = Account::create(
[ [
@@ -137,14 +135,6 @@ class AccountTransformerTest extends TestCase
'encrypted' => 0, 'encrypted' => 0,
] ]
); );
// add currency preference:
AccountMeta::create(
[
'account_id' => $account->id,
'name' => 'currency_id',
'data' => 1, // euro
]
);
// add a note: // add a note:
$note = Note::create( $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) // add credit card meta data (will be ignored)
AccountMeta::create( AccountMeta::create(
[ [
@@ -202,9 +213,6 @@ class AccountTransformerTest extends TestCase
*/ */
public function testIgnoreCCExpense() public function testIgnoreCCExpense()
{ {
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getMetaValue')->andReturn('2016-01-01');
// make new account: // make new account:
$account = Account::create( $account = Account::create(
@@ -218,15 +226,6 @@ class AccountTransformerTest extends TestCase
'encrypted' => 0, 'encrypted' => 0,
] ]
); );
// add currency preference:
AccountMeta::create(
[
'account_id' => $account->id,
'name' => 'currency_id',
'data' => 1, // euro
]
);
// add a note: // add a note:
$note = Note::create( $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) // add credit card meta data (will be ignored)
AccountMeta::create( AccountMeta::create(
[ [
@@ -287,7 +302,8 @@ class AccountTransformerTest extends TestCase
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn('45.67'); $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn('45.67');
$accountRepos->shouldReceive('getOpeningBalanceDate')->andReturn('2018-01-01'); $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: // make new account:
$account = Account::create( $account = Account::create(
[ [
@@ -344,7 +360,8 @@ class AccountTransformerTest extends TestCase
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null); $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturn(null);
$accountRepos->shouldReceive('getOpeningBalanceDate')->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: // make new account:
$account = Account::create( $account = Account::create(
[ [
@@ -384,11 +401,6 @@ class AccountTransformerTest extends TestCase
*/ */
public function testWithNotes() 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: // make new account:
$account = Account::create( $account = Account::create(
[ [
@@ -401,15 +413,6 @@ class AccountTransformerTest extends TestCase
'encrypted' => 0, 'encrypted' => 0,
] ]
); );
// add currency preference:
AccountMeta::create(
[
'account_id' => $account->id,
'name' => 'currency_id',
'data' => 1, // euro
]
);
// add a note: // add a note:
$note = Note::create( $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); $transformer = new AccountTransformer(new ParameterBag);
$result = $transformer->transform($account); $result = $transformer->transform($account);