Skip to content

Firefly III: a personal finances manager

Fix tests to catch use of repositories

James Colee2d1de94b766
diff --git a/tests/Api/V1/Controllers/TransactionControllerTest.php b/tests/Api/V1/Controllers/TransactionControllerTest.php
index d196a27654..076a35bb2c 100644
--- a/tests/Api/V1/Controllers/TransactionControllerTest.php
+++ b/tests/Api/V1/Controllers/TransactionControllerTest.php
@@ -2377,9 +2377,13 @@ class TransactionControllerTest extends TestCase
*/
public function testUpdateBasicDeposit()
{
- $account = $this->user()->accounts()->where('account_type_id', 3)->first();
- $repository = $this->mock(JournalRepositoryInterface::class);
- $data = [
+ $account = $this->user()->accounts()->where('account_type_id', 3)->first();
+ $repository = $this->mock(JournalRepositoryInterface::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $accountRepos->shouldReceive('setUser');
+ $accountRepos->shouldReceive('getAccountsById')->withArgs([[$account->id]])->andReturn(new Collection([$account]));
+
+ $data = [
'description' => 'Some deposit #' . rand(1, 1000),
'date' => '2018-01-01',
'transactions' => [
@@ -2416,6 +2420,11 @@ class TransactionControllerTest extends TestCase
{
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$repository = $this->mock(JournalRepositoryInterface::class);
+
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $accountRepos->shouldReceive('setUser');
+ $accountRepos->shouldReceive('getAccountsById')->withArgs([[$account->id]])->andReturn(new Collection([$account]));
+
$data = [
'description' => 'Some transaction #' . rand(1, 1000),
'date' => '2018-01-01',
@@ -2433,6 +2442,8 @@ class TransactionControllerTest extends TestCase
$count = $withdrawal->transactions()->count();
} while ($count !== 2);
+
+
$transaction = $withdrawal->transactions()->first();
$repository->shouldReceive('setUser');
$repository->shouldReceive('update')->andReturn($withdrawal)->once();
diff --git a/tests/Unit/Services/Internal/Update/TransactionUpdateServiceTest.php b/tests/Unit/Services/Internal/Update/TransactionUpdateServiceTest.php
index 0967adc8de..602316b1eb 100644
--- a/tests/Unit/Services/Internal/Update/TransactionUpdateServiceTest.php
+++ b/tests/Unit/Services/Internal/Update/TransactionUpdateServiceTest.php
@@ -27,6 +27,7 @@ namespace Tests\Unit\Services\Internal\Update;
use FireflyIII\Factory\BudgetFactory;
use FireflyIII\Factory\CategoryFactory;
use FireflyIII\Models\Transaction;
+use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Services\Internal\Update\TransactionUpdateService;
use Tests\TestCase;
@@ -119,8 +120,7 @@ class TransactionUpdateServiceTest extends TestCase
{
/** @var Transaction $source */
$source = $this->user()->transactions()->where('amount', '>', 0)->inRandomOrder()->first();
-
- $data = [
+ $data = [
'currency_id' => 1,
'currency_code' => null,
'description' => 'Some new description',
@@ -137,6 +137,11 @@ class TransactionUpdateServiceTest extends TestCase
'foreign_currency_code' => null,
];
+ // mock repository:
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $accountRepos->shouldReceive('setUser');
+ $accountRepos->shouldReceive('findNull')->andReturn($source->account);
+
/** @var TransactionUpdateService $service */
$service = app(TransactionUpdateService::class);
$service->setUser($this->user());
@@ -154,7 +159,6 @@ class TransactionUpdateServiceTest extends TestCase
{
/** @var Transaction $source */
$source = $this->user()->transactions()->where('amount', '>', 0)->inRandomOrder()->first();
-
$data = [
'currency_id' => 1,
'currency_code' => null,
@@ -172,11 +176,18 @@ class TransactionUpdateServiceTest extends TestCase
'foreign_currency_code' => null,
];
+ // mock repository:
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $accountRepos->shouldReceive('setUser');
+ $accountRepos->shouldReceive('findNull')->andReturn($source->account);
+
/** @var TransactionUpdateService $service */
$service = app(TransactionUpdateService::class);
$service->setUser($this->user());
$result = $service->update($source, $data);
+
+
$this->assertEquals($source->id, $result->id);
$this->assertEquals($result->description, $data['description']);
$this->assertEquals($data['foreign_amount'], $result->foreign_amount);
@@ -191,7 +202,6 @@ class TransactionUpdateServiceTest extends TestCase
{
/** @var Transaction $source */
$source = $this->user()->transactions()->where('amount', '<', 0)->inRandomOrder()->first();
-
$data = [
'currency_id' => 1,
'currency_code' => null,
@@ -209,6 +219,11 @@ class TransactionUpdateServiceTest extends TestCase
'foreign_currency_code' => null,
];
+ // mock repository:
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $accountRepos->shouldReceive('setUser');
+ $accountRepos->shouldReceive('findNull')->andReturn($source->account);
+
/** @var TransactionUpdateService $service */
$service = app(TransactionUpdateService::class);
$service->setUser($this->user());