mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 09:22:33 +00:00
Improve test coverage.
This commit is contained in:
@@ -28,6 +28,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Transformers\PreferenceTransformer;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -59,6 +60,13 @@ class PreferencesControllerTest extends TestCase
|
||||
$transformer = $this->mock(PreferenceTransformer::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
// mock calls to preferences facade.
|
||||
$pref = new Preference;
|
||||
$pref->data = [1, 2, 3];
|
||||
|
||||
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($pref);
|
||||
Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['frontPageAccounts', ['4', '5', '6']])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
@@ -67,10 +75,10 @@ class PreferencesControllerTest extends TestCase
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
$accountRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
/** @var Preference $preference */
|
||||
$preference = Preferences::setForUser($this->user(), 'frontPageAccounts', [1, 2, 3]);
|
||||
$data = ['data' => '4,5,6'];
|
||||
$response = $this->put(route('api.v1.preferences.update', [$preference->name]), $data, ['Accept' => 'application/json']);
|
||||
///** @var Preference $preference */
|
||||
//$preference = Preferences::setForUser($this->user(), 'frontPageAccounts', [1, 2, 3]);
|
||||
$data = ['data' => '4,5,6'];
|
||||
$response = $this->put(route('api.v1.preferences.update', ['frontPageAccounts']), $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
@@ -83,6 +91,21 @@ class PreferencesControllerTest extends TestCase
|
||||
$transformer = $this->mock(PreferenceTransformer::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
// mock calls to preferences facade.
|
||||
$pref = new Preference;
|
||||
$pref->data = false;
|
||||
$countable = new Preference;
|
||||
$countable->data = [1];
|
||||
|
||||
$saved = new Preference;
|
||||
$saved->user_id = $this->user()->id;
|
||||
$saved->name = 'twoFactorAuthEnabled';
|
||||
$saved->data = false;
|
||||
$saved->save();
|
||||
|
||||
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($countable);
|
||||
Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['twoFactorAuthEnabled', '1'])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
@@ -92,12 +115,12 @@ class PreferencesControllerTest extends TestCase
|
||||
$accountRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
/** @var Preference $preference */
|
||||
$preference = Preferences::setForUser($this->user(), 'twoFactorAuthEnabled', false);
|
||||
$data = ['data' => '1'];
|
||||
$response = $this->put(route('api.v1.preferences.update', [$preference->name]), $data, ['Accept' => 'application/json']);
|
||||
$data = ['data' => '1'];
|
||||
$response = $this->put(route('api.v1.preferences.update', ['twoFactorAuthEnabled']), $data, ['Accept' => 'application/json']);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,10 +139,23 @@ class PreferencesControllerTest extends TestCase
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
$accountRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
/** @var Preference $preference */
|
||||
$preference = Preferences::setForUser($this->user(), 'currencyPreference', false);
|
||||
// mock calls to preferences facade.
|
||||
$pref = new Preference;
|
||||
$pref->data = 'EUR';
|
||||
$countable = new Preference;
|
||||
$countable->data = [1];
|
||||
|
||||
$saved = new Preference;
|
||||
$saved->user_id = $this->user()->id;
|
||||
$saved->name = 'twoFactorEnabled';
|
||||
$saved->data = false;
|
||||
$saved->save();
|
||||
|
||||
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($countable);
|
||||
Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
$data = ['data' => 'EUR'];
|
||||
$response = $this->put(route('api.v1.preferences.update', [$preference->name]), $data, ['Accept' => 'application/json']);
|
||||
$response = $this->put(route('api.v1.preferences.update', ['currencyPreference']), $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
@@ -140,10 +176,23 @@ class PreferencesControllerTest extends TestCase
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
$accountRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
/** @var Preference $preference */
|
||||
$preference = Preferences::setForUser($this->user(), 'listPageSize', 13);
|
||||
// mock calls to preferences facade.
|
||||
$pref = new Preference;
|
||||
$pref->data = 'EUR';
|
||||
$countable = new Preference;
|
||||
$countable->data = [1];
|
||||
|
||||
$saved = new Preference;
|
||||
$saved->user_id = $this->user()->id;
|
||||
$saved->name = 'listPageSize';
|
||||
$saved->data = 200;
|
||||
$saved->save();
|
||||
|
||||
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($countable);
|
||||
Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['listPageSize', '434'])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
$data = ['data' => '434'];
|
||||
$response = $this->put(route('api.v1.preferences.update', [$preference->name]), $data, ['Accept' => 'application/json']);
|
||||
$response = $this->put(route('api.v1.preferences.update', ['listPageSize']), $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ namespace Tests\Api\V1\Controllers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
||||
@@ -37,6 +37,7 @@ use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
use Mockery;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -238,6 +239,12 @@ class RuleControllerTest extends TestCase
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock Preferences Facade:
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
|
||||
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
|
||||
$response = $this->get(route('api.v1.rules.test', [$rule->id]) . '?accounts=1,2,3');
|
||||
$response->assertStatus(200);
|
||||
|
@@ -27,6 +27,7 @@ namespace Tests\Api\V1\Controllers;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
|
||||
use FireflyIII\Jobs\Job;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
@@ -38,6 +39,8 @@ use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Queue;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -89,6 +92,8 @@ class RuleGroupControllerTest extends TestCase
|
||||
|
||||
$ruleGroupRepos->shouldReceive('store')->once()->andReturn($ruleGroup);
|
||||
|
||||
|
||||
|
||||
// test API
|
||||
$response = $this->post(route('api.v1.rule_groups.store'), $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
@@ -133,6 +138,13 @@ class RuleGroupControllerTest extends TestCase
|
||||
$matcher->shouldReceive('setAccounts')->once();
|
||||
$matcher->shouldReceive('findTransactionsByRule')->once()->andReturn([]);
|
||||
|
||||
// mock Preferences Facade:
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
|
||||
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.rule_groups.test', [$group->id]) . '?accounts=1,2,3');
|
||||
$response->assertStatus(200);
|
||||
@@ -151,6 +163,13 @@ class RuleGroupControllerTest extends TestCase
|
||||
$ruleGroupRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('getActiveRules')->once()->andReturn(new Collection);
|
||||
|
||||
|
||||
// mock Preferences Facade:
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
|
||||
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
// call API
|
||||
$group = $this->user()->ruleGroups()->first();
|
||||
$response = $this->get(route('api.v1.rule_groups.test', [$group->id]), ['Accept' => 'application/json']);
|
||||
@@ -198,6 +217,8 @@ class RuleGroupControllerTest extends TestCase
|
||||
$repository->shouldReceive('isAsset')->withArgs([1])->andReturn(true);
|
||||
$repository->shouldReceive('isAsset')->withArgs([2])->andReturn(false);
|
||||
|
||||
|
||||
|
||||
$response = $this->post(route('api.v1.rule_groups.trigger', [$group->id]) . '?accounts=1,2,3&start_date=2019-01-01&end_date=2019-01-02');
|
||||
$response->assertStatus(204);
|
||||
|
||||
|
@@ -639,6 +639,8 @@ class TransactionControllerTest extends TestCase
|
||||
try {
|
||||
$this->expectsEvents(StoredTransactionGroup::class);
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
|
||||
@@ -856,6 +858,8 @@ class TransactionControllerTest extends TestCase
|
||||
try {
|
||||
$this->expectsEvents(UpdatedTransactionGroup::class);
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user