mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-18 18:40:12 +00:00
Update tests so repositories are not called. Saves on DB calls, speeds up tests.
This commit is contained in:
@@ -323,6 +323,7 @@ class IndexControllerTest extends TestCase
|
||||
$spectrePrerequisites = $this->mock(SpectrePrerequisites::class);
|
||||
$filePrerequisites = $this->mock(FilePrerequisites::class);
|
||||
$ynabPrerequisites = $this->mock(YnabPrerequisites::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// call methods:
|
||||
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false);
|
||||
@@ -357,6 +358,7 @@ class IndexControllerTest extends TestCase
|
||||
$filePrerequisites = $this->mock(FilePrerequisites::class);
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$ynabPrerequisites = $this->mock(YnabPrerequisites::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// call methods:
|
||||
$fakePrerequisites->shouldReceive('setUser')->once();
|
||||
|
@@ -26,6 +26,7 @@ namespace Tests\Feature\Controllers\Import;
|
||||
use FireflyIII\Import\JobConfiguration\FakeJobConfiguration;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
@@ -62,6 +63,9 @@ class JobConfigurationControllerTest extends TestCase
|
||||
// mock repositories and configuration handling classes:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$configurator = $this->mock(FakeJobConfiguration::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
// mock calls:
|
||||
$configurator->shouldReceive('setImportJob')->once();
|
||||
@@ -94,8 +98,10 @@ class JobConfigurationControllerTest extends TestCase
|
||||
// mock repositories and configuration handling classes:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$configurator = $this->mock(FakeJobConfiguration::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
|
||||
|
||||
// mock calls:
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.job.configuration.index', [$job->key]));
|
||||
@@ -120,6 +126,7 @@ class JobConfigurationControllerTest extends TestCase
|
||||
// mock repositories and configuration handling classes:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$configurator = $this->mock(FakeJobConfiguration::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$configurator->shouldReceive('setImportJob')->once();
|
||||
@@ -152,6 +159,7 @@ class JobConfigurationControllerTest extends TestCase
|
||||
// mock repositories and configuration handling classes:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$configurator = $this->mock(FakeJobConfiguration::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$configurator->shouldReceive('setImportJob')->once();
|
||||
@@ -186,6 +194,7 @@ class JobConfigurationControllerTest extends TestCase
|
||||
// mock repositories and configuration handling classes:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$configurator = $this->mock(FakeJobConfiguration::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// call thing.
|
||||
$this->be($this->user());
|
||||
@@ -212,6 +221,8 @@ class JobConfigurationControllerTest extends TestCase
|
||||
// mock repositories and configuration handling classes:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$configurator = $this->mock(FakeJobConfiguration::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
|
||||
// mock calls:
|
||||
$configurator->shouldReceive('setImportJob')->once();
|
||||
@@ -245,6 +256,7 @@ class JobConfigurationControllerTest extends TestCase
|
||||
// mock repositories and configuration handling classes:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$configurator = $this->mock(FakeJobConfiguration::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$configurator->shouldReceive('setImportJob')->once();
|
||||
|
@@ -29,6 +29,7 @@ use FireflyIII\Import\Storage\ImportArrayStorage;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
@@ -56,6 +57,8 @@ class JobStatusControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'Afake_job_' . random_int(1, 10000);
|
||||
@@ -64,6 +67,8 @@ class JobStatusControllerTest extends TestCase
|
||||
$job->file_type = '';
|
||||
$job->save();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
// call thing.
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.job.status.index', [$job->key]));
|
||||
@@ -76,6 +81,9 @@ class JobStatusControllerTest extends TestCase
|
||||
*/
|
||||
public function testJson(): void
|
||||
{
|
||||
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'Bfake_job_' . random_int(1, 10000);
|
||||
@@ -99,6 +107,8 @@ class JobStatusControllerTest extends TestCase
|
||||
*/
|
||||
public function testJsonWithTag(): void
|
||||
{
|
||||
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$tag = $this->user()->tags()->first();
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
@@ -124,6 +134,9 @@ class JobStatusControllerTest extends TestCase
|
||||
*/
|
||||
public function testJsonWithTagManyJournals(): void
|
||||
{
|
||||
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
/** @var Tag $tag */
|
||||
$tag = $this->user()->tags()->first();
|
||||
$journal = $this->user()->transactionJournals()->first();
|
||||
@@ -154,6 +167,9 @@ class JobStatusControllerTest extends TestCase
|
||||
*/
|
||||
public function testJsonWithTagOneJournal(): void
|
||||
{
|
||||
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
/** @var Tag $tag */
|
||||
$tag = $this->user()->tags()->first();
|
||||
$journal = $this->user()->transactionJournals()->first();
|
||||
@@ -183,6 +199,8 @@ class JobStatusControllerTest extends TestCase
|
||||
*/
|
||||
public function testStart(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'Ffake_job_' . random_int(1, 10000);
|
||||
@@ -212,6 +230,8 @@ class JobStatusControllerTest extends TestCase
|
||||
*/
|
||||
public function testStartException(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'Gfake_job_' . random_int(1, 10000);
|
||||
@@ -242,6 +262,7 @@ class JobStatusControllerTest extends TestCase
|
||||
*/
|
||||
public function testStartFireflyException(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'Hfake_job_' . random_int(1, 10000);
|
||||
@@ -272,6 +293,12 @@ class JobStatusControllerTest extends TestCase
|
||||
*/
|
||||
public function testStartInvalidState(): void
|
||||
{
|
||||
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
// mock calls:
|
||||
$importRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'error'])
|
||||
->atLeast()->once();
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'Ifake_job_' . random_int(1, 10000);
|
||||
@@ -285,7 +312,7 @@ class JobStatusControllerTest extends TestCase
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('import.job.start', [$job->key]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson(['status' => 'NOK', 'message' => 'JobStatusController::start expects status "ready_to_run" instead of "error".']);
|
||||
$response->assertExactJson(['status' => 'NOK', 'message' => 'JobStatusController::start expects status "ready_to_run" instead of "bad_state".']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -305,6 +332,7 @@ class JobStatusControllerTest extends TestCase
|
||||
// mock stuff
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$storage = $this->mock(ImportArrayStorage::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'storing_data']);
|
||||
@@ -336,6 +364,7 @@ class JobStatusControllerTest extends TestCase
|
||||
// mock stuff
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$storage = $this->mock(ImportArrayStorage::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'storing_data']);
|
||||
@@ -355,6 +384,7 @@ class JobStatusControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreInvalidState(): void
|
||||
{
|
||||
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'Kfake_job_' . random_int(1, 10000);
|
||||
|
@@ -25,6 +25,7 @@ namespace Tests\Feature\Controllers\Import;
|
||||
use FireflyIII\Import\Prerequisites\FakePrerequisites;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
use Mockery;
|
||||
@@ -53,6 +54,7 @@ class PrerequisitesControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'A_pre_job_' . random_int(1, 10000);
|
||||
@@ -66,6 +68,10 @@ class PrerequisitesControllerTest extends TestCase
|
||||
$prereq = $this->mock(FakePrerequisites::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
|
||||
|
||||
|
||||
$prereq->shouldReceive('setUser')->times(2);
|
||||
$prereq->shouldReceive('isComplete')->times(2)->andReturn(false);
|
||||
$prereq->shouldReceive('getView')->once()->andReturn('import.fake.prerequisites');
|
||||
@@ -83,6 +89,8 @@ class PrerequisitesControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndexBadState(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'B_pre_job_' . random_int(1, 10000);
|
||||
@@ -92,6 +100,10 @@ class PrerequisitesControllerTest extends TestCase
|
||||
$job->file_type = '';
|
||||
$job->save();
|
||||
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('import.prerequisites.index', ['fake', $job->key]));
|
||||
$response->assertStatus(302);
|
||||
@@ -103,6 +115,8 @@ class PrerequisitesControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndexComplete(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'C_pre_job_' . random_int(1, 10000);
|
||||
@@ -116,6 +130,8 @@ class PrerequisitesControllerTest extends TestCase
|
||||
$prereq = $this->mock(FakePrerequisites::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
|
||||
|
||||
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'has_prereq']);
|
||||
$prereq->shouldReceive('setUser')->times(2);
|
||||
$prereq->shouldReceive('isComplete')->times(2)->andReturn(true);
|
||||
@@ -134,6 +150,8 @@ class PrerequisitesControllerTest extends TestCase
|
||||
*/
|
||||
public function testPost(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'D_pre_job_' . random_int(1, 10000);
|
||||
@@ -147,6 +165,9 @@ class PrerequisitesControllerTest extends TestCase
|
||||
$prereq = $this->mock(FakePrerequisites::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
|
||||
|
||||
|
||||
$prereq->shouldReceive('setUser')->times(2);
|
||||
$prereq->shouldReceive('storePrerequisites')->once()->andReturn(new MessageBag);
|
||||
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'has_prereq']);
|
||||
@@ -165,6 +186,8 @@ class PrerequisitesControllerTest extends TestCase
|
||||
*/
|
||||
public function testPostBadState(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'D_pre_job_' . random_int(1, 10000);
|
||||
@@ -174,6 +197,8 @@ class PrerequisitesControllerTest extends TestCase
|
||||
$job->file_type = '';
|
||||
$job->save();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
|
||||
|
||||
// mock stuff
|
||||
$prereq = $this->mock(FakePrerequisites::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
@@ -195,10 +220,14 @@ class PrerequisitesControllerTest extends TestCase
|
||||
*/
|
||||
public function testPostNoJob(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// mock stuff
|
||||
$prereq = $this->mock(FakePrerequisites::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
|
||||
|
||||
$prereq->shouldReceive('setUser')->once();
|
||||
$prereq->shouldReceive('storePrerequisites')->once()->andReturn(new MessageBag);
|
||||
|
||||
@@ -218,6 +247,8 @@ class PrerequisitesControllerTest extends TestCase
|
||||
*/
|
||||
public function testPostWithMessages(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'D_pre_job_' . random_int(1, 10000);
|
||||
@@ -234,6 +265,8 @@ class PrerequisitesControllerTest extends TestCase
|
||||
$prereq = $this->mock(FakePrerequisites::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
|
||||
|
||||
$prereq->shouldReceive('setUser')->times(1);
|
||||
$prereq->shouldReceive('isComplete')->times(1)->andReturn(false);
|
||||
|
||||
|
Reference in New Issue
Block a user