Skip to content

Firefly III: a personal finances manager

These changes fix the tests.

James Cole1dec270907ce
diff --git a/app/Repositories/Journal/JournalTasker.php b/app/Repositories/Journal/JournalTasker.php
index 5958b0ff1c..5aacaa94ac 100644
--- a/app/Repositories/Journal/JournalTasker.php
+++ b/app/Repositories/Journal/JournalTasker.php
@@ -144,11 +144,11 @@ class JournalTasker implements JournalTaskerInterface
'transaction_currency_id' => $entry->transaction_currency_id,
'transaction_currency_code' => $entry->transaction_currency_code,
'transaction_currency_symbol' => $entry->transaction_currency_symbol,
- 'transaction_currency_dp' => $entry->transaction_currency_dp,
+ 'transaction_currency_dp' => $entry->transaction_currency_dp,
'foreign_currency_id' => $entry->foreign_currency_id,
'foreign_currency_code' => $entry->foreign_currency_code,
'foreign_currency_symbol' => $entry->foreign_currency_symbol,
- 'foreign_currency_dp' => $entry->foreign_currency_dp,
+ 'foreign_currency_dp' => $entry->foreign_currency_dp,
];
if ($entry->destination_account_type === AccountType::CASH) {
$transaction['destination_account_name'] = '';
diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php
index bd8d30b2a9..2727d4d86c 100644
--- a/database/factories/ModelFactory.php
+++ b/database/factories/ModelFactory.php
@@ -217,25 +217,31 @@ $factory->define(
$factory->define(
FireflyIII\Models\Transaction::class, function (Faker\Generator $faker) {
return [
- 'transaction_amount' => strval($faker->randomFloat(2, -100, 100)),
- 'destination_amount' => strval($faker->randomFloat(2, -100, 100)),
- 'opposing_account_id' => $faker->numberBetween(1, 10),
- 'source_account_id' => $faker->numberBetween(1, 10),
- 'opposing_account_name' => $faker->words(3, true),
- 'description' => $faker->words(3, true),
- 'source_account_name' => $faker->words(3, true),
- 'destination_account_id' => $faker->numberBetween(1, 10),
- 'date' => new Carbon,
- 'destination_account_name' => $faker->words(3, true),
- 'amount' => strval($faker->randomFloat(2, -100, 100)),
- 'budget_id' => 0,
- 'category' => $faker->words(3, true),
- 'transaction_journal_id' => $faker->numberBetween(1, 10),
- 'journal_id' => $faker->numberBetween(1, 10),
- 'transaction_currency_code' => 'EUR',
- 'transaction_type_type' => 'Withdrawal',
- 'account_encrypted' => 0,
- 'account_name' => 'Some name',
+ 'transaction_amount' => strval($faker->randomFloat(2, -100, 100)),
+ 'destination_amount' => strval($faker->randomFloat(2, -100, 100)),
+ 'opposing_account_id' => $faker->numberBetween(1, 10),
+ 'source_account_id' => $faker->numberBetween(1, 10),
+ 'opposing_account_name' => $faker->words(3, true),
+ 'description' => $faker->words(3, true),
+ 'source_account_name' => $faker->words(3, true),
+ 'destination_account_id' => $faker->numberBetween(1, 10),
+ 'date' => new Carbon,
+ 'destination_account_name' => $faker->words(3, true),
+ 'amount' => strval($faker->randomFloat(2, -100, 100)),
+ 'budget_id' => 0,
+ 'category' => $faker->words(3, true),
+ 'transaction_journal_id' => $faker->numberBetween(1, 10),
+ 'journal_id' => $faker->numberBetween(1, 10),
+ 'transaction_currency_code' => 'EUR',
+ 'transaction_type_type' => 'Withdrawal',
+ 'account_encrypted' => 0,
+ 'account_name' => 'Some name',
+ 'transaction_currency_id' => 1,
+ 'transaction_currency_symbol' => '€',
+ 'foreign_destination_amount' => null,
+ 'foreign_currency_id' => null,
+ 'foreign_currency_code' => null,
+ 'foreign_currency_symbol' => null,
];
}
);
\ No newline at end of file
diff --git a/tests/Feature/Controllers/JsonControllerTest.php b/tests/Feature/Controllers/JsonControllerTest.php
index 798575bbef..22c4152d77 100644
--- a/tests/Feature/Controllers/JsonControllerTest.php
+++ b/tests/Feature/Controllers/JsonControllerTest.php
@@ -21,7 +21,6 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
@@ -88,15 +87,17 @@ class JsonControllerTest extends TestCase
public function testBoxBillsPaid()
{
// mock stuff
+
$billRepos = $this->mock(BillRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$billRepos->shouldReceive('getBillsPaidInRange')->andReturn('-100');
$this->be($this->user());
+ $currency = Amount::getDefaultCurrency();
$response = $this->get(route('json.box.paid'));
$response->assertStatus(200);
- $response->assertExactJson(['amount' => Amount::format('100', false), 'amount_raw' => '100', 'box' => 'bills-paid']);
+ $response->assertExactJson(['amount' => Amount::formatAnything($currency, '100', false), 'amount_raw' => '100', 'box' => 'bills-paid']);
}
/**
@@ -105,6 +106,7 @@ class JsonControllerTest extends TestCase
public function testBoxBillsUnpaid()
{
// mock stuff
+
$billRepos = $this->mock(BillRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@@ -112,9 +114,10 @@ class JsonControllerTest extends TestCase
$this->be($this->user());
+ $currency = Amount::getDefaultCurrency();
$response = $this->get(route('json.box.unpaid'));
$response->assertStatus(200);
- $response->assertExactJson(['amount' => Amount::format('100', false), 'amount_raw' => '100', 'box' => 'bills-unpaid']);
+ $response->assertExactJson(['amount' => Amount::formatAnything($currency, '100', false), 'amount_raw' => '100', 'box' => 'bills-unpaid']);
}
/**
@@ -123,8 +126,7 @@ class JsonControllerTest extends TestCase
public function testBoxIn()
{
// mock stuff
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $tasker = $this->mock(AccountTaskerInterface::class);
+
$collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@@ -139,9 +141,10 @@ class JsonControllerTest extends TestCase
$this->be($this->user());
+ $currency = Amount::getDefaultCurrency();
$response = $this->get(route('json.box.in'));
$response->assertStatus(200);
- $response->assertExactJson(['amount' => Amount::format('100', false), 'amount_raw' => '100', 'box' => 'in']);
+ $response->assertExactJson(['amount' => Amount::formatAnything($currency, '100', false), 'amount_raw' => '100', 'box' => 'in']);
}
/**
@@ -150,8 +153,7 @@ class JsonControllerTest extends TestCase
public function testBoxOut()
{
// mock stuff
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $tasker = $this->mock(AccountTaskerInterface::class);
+
$collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@@ -165,9 +167,10 @@ class JsonControllerTest extends TestCase
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once();
$this->be($this->user());
+ $currency = Amount::getDefaultCurrency();
$response = $this->get(route('json.box.out'));
$response->assertStatus(200);
- $response->assertExactJson(['amount' => Amount::format('100', false), 'amount_raw' => '100', 'box' => 'out']);
+ $response->assertExactJson(['amount' => Amount::formatAnything($currency, '100', false), 'amount_raw' => '100', 'box' => 'out']);
}
/**
diff --git a/tests/Feature/Controllers/Transaction/SplitControllerTest.php b/tests/Feature/Controllers/Transaction/SplitControllerTest.php
index 00c5a5b3c6..578802bc8c 100644
--- a/tests/Feature/Controllers/Transaction/SplitControllerTest.php
+++ b/tests/Feature/Controllers/Transaction/SplitControllerTest.php
@@ -7,7 +7,7 @@
* See the LICENSE file for details.
*/
-declare(strict_types = 1);
+declare(strict_types=1);
namespace Tests\Feature\Controllers\Transaction;
@@ -38,13 +38,13 @@ class SplitControllerTest extends TestCase
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::arrayFromJournal
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::getTransactionDataFromJournal
*/
- public function testEditSingle()
+ public function testEdit()
{
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $transactions = factory(Transaction::class, 1)->make();
+ $transactions = factory(Transaction::class, 3)->make();
$tasker = $this->mock(JournalTaskerInterface::class);
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
@@ -62,6 +62,16 @@ class SplitControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
+ /**
+ * @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit
+ */
+ public function testEditOpeningBalance()
+ {
+ $opening = TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first();
+ $this->be($this->user());
+ $response = $this->get(route('transactions.split.edit', [$opening->id]));
+ $response->assertStatus(302);
+ }
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit
@@ -69,13 +79,13 @@ class SplitControllerTest extends TestCase
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::arrayFromJournal
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::getTransactionDataFromJournal
*/
- public function testEdit()
+ public function testEditSingle()
{
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $transactions = factory(Transaction::class, 3)->make();
+ $transactions = factory(Transaction::class, 1)->make();
$tasker = $this->mock(JournalTaskerInterface::class);
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
@@ -93,17 +103,6 @@ class SplitControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
- /**
- * @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit
- */
- public function testEditOpeningBalance()
- {
- $opening = TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first();
- $this->be($this->user());
- $response = $this->get(route('transactions.split.edit', [$opening->id]));
- $response->assertStatus(302);
- }
-
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::update
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::arrayFromInput
@@ -124,10 +123,11 @@ class SplitControllerTest extends TestCase
'tags' => '',
'transactions' => [
[
- 'description' => 'Split #1',
- 'source_account_name' => 'Job',
- 'amount' => 1591,
- 'category' => '',
+ 'description' => 'Split #1',
+ 'source_account_name' => 'Job',
+ 'transaction_currency_id' => 1,
+ 'amount' => 1591,
+ 'category' => '',
],
],
];