diff --git a/tests/Feature/Controllers/Import/CallbackControllerTest.php b/tests/Feature/Controllers/Import/CallbackControllerTest.php
deleted file mode 100644
index a3efc38083..0000000000
--- a/tests/Feature/Controllers/Import/CallbackControllerTest.php
+++ /dev/null
@@ -1,111 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Feature\Controllers\Import;
-
-
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- *
- * Class CallbackControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CallbackControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\CallbackController
- */
- public function testYnabBasic(): void
- {
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $importJob = $this->getRandomImportJob();
- // config for job:
- $config = [];
- $newConfig = ['auth_code' => 'abc'];
-
- $this->mockDefaultSession();
-
- // mock calls.
- $repository->shouldReceive('findByKey')->andReturn($importJob)->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->once();
- $repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $newConfig]);
-
- $repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'ready_to_run']);
- $repository->shouldReceive('setStage')->once()->withArgs([Mockery::any(), 'get_access_token']);
-
-
- $this->be($this->user());
- $response = $this->get(route('import.callback.ynab') . '?code=abc&state=def');
- $response->assertStatus(302);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\CallbackController
- */
- public function testYnabBasicBadJob(): void
- {
- $repository = $this->mock(ImportJobRepositoryInterface::class);
-
- // mock calls.
- $repository->shouldReceive('findByKey')->andReturnNull()->once();
- $this->mockDefaultSession();
-
- $this->be($this->user());
- $response = $this->get(route('import.callback.ynab') . '?code=abc&state=def');
- $response->assertStatus(200);
- $response->assertSee('You Need A Budget did not reply with the correct state identifier. Firefly III cannot continue.');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\CallbackController
- */
- public function testYnabBasicNoCode(): void
- {
- $this->mock(ImportJobRepositoryInterface::class);
-
- $this->mockDefaultSession();
-
- // mock calls.
-
- $this->be($this->user());
- $response = $this->get(route('import.callback.ynab') . '?code=&state=def');
- $response->assertStatus(200);
- $response->assertSee('You Need A Budget did not reply with a valid authorization code. Firefly III cannot continue.');
- }
-}
diff --git a/tests/Feature/Controllers/Import/IndexControllerTest.php b/tests/Feature/Controllers/Import/IndexControllerTest.php
deleted file mode 100644
index e75d96f978..0000000000
--- a/tests/Feature/Controllers/Import/IndexControllerTest.php
+++ /dev/null
@@ -1,344 +0,0 @@
-.
- */
-declare(strict_types=1);
-
-namespace Tests\Feature\Controllers\Import;
-
-use FireflyIII\Import\Prerequisites\BunqPrerequisites;
-use FireflyIII\Import\Prerequisites\FakePrerequisites;
-use FireflyIII\Import\Prerequisites\SpectrePrerequisites;
-use FireflyIII\Import\Prerequisites\YnabPrerequisites;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class IndexControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class IndexControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\IndexController
- */
- public function testCreateBadJob(): void
- {
- $this->mockDefaultSession();
-
- // mock stuff:
- $this->mock(ImportJobRepositoryInterface::class);
- $userRepository = $this->mock(UserRepositoryInterface::class);
- $bunqPrerequisites = $this->mock(BunqPrerequisites::class);
- $spectrePrerequisites = $this->mock(SpectrePrerequisites::class);
- $ynabPrerequisites = $this->mock(YnabPrerequisites::class);
-
- // fake job:
- $importJob = new ImportJob;
- $importJob->provider = 'fake';
- $importJob->key = 'fake_job_1';
-
-
- // mock calls:
- $ynabPrerequisites->shouldReceive('setUser')->once();
- //$fakePrerequisites->shouldReceive('setUser')->once();
- $bunqPrerequisites->shouldReceive('setUser')->once();
- $spectrePrerequisites->shouldReceive('setUser')->once();
- //$fakePrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
- $bunqPrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
- $spectrePrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
- $ynabPrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
-
- $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->once();
-
- $this->be($this->user());
- $response = $this->get(route('import.create', ['bad']));
- $response->assertStatus(404);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\IndexController
- */
- public function testCreateDemoUser(): void
- {
- Log::debug(sprintf('Now in test %s', __METHOD__));
- // mock stuff:
- $this->mock(ImportJobRepositoryInterface::class);
- $userRepository = $this->mock(UserRepositoryInterface::class);
- $fakePrerequisites = $this->mock(FakePrerequisites::class);
-
- // fake job:
- $importJob = new ImportJob;
- $importJob->provider = 'spectre';
- $importJob->key = 'fake_job_1';
-
- $this->mockDefaultSession();
-
- // mock calls:
- $fakePrerequisites->shouldReceive('setUser')->atLeast()->once();
- $fakePrerequisites->shouldReceive('isComplete')->atLeast()->once()->andReturn(true);
-
- $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->atLeast()->once();
-
- $this->be($this->user());
- $response = $this->get(route('import.create', ['spectre']));
- $response->assertStatus(404);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\IndexController
- */
- public function testCreateFake(): void
- {
- // mock stuff:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $userRepository = $this->mock(UserRepositoryInterface::class);
- $fakePrerequisites = $this->mock(FakePrerequisites::class);
-
- // fake job:
- $importJob = new ImportJob;
- $importJob->provider = 'fake';
- $importJob->key = 'fake_job_1';
- $importJob->user_id = 1;
-
- $this->mockDefaultSession();
-
- // mock calls
- $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->times(3);
- $repository->shouldReceive('create')->withArgs(['fake'])->andReturn($importJob);
-
- $fakePrerequisites->shouldReceive('isComplete')->times(3)->andReturn(false);
- $fakePrerequisites->shouldReceive('setUser')->times(3);
-
-
- $this->be($this->user());
- $response = $this->get(route('import.create', ['fake']));
- $response->assertStatus(302);
- // expect a redirect to prerequisites
- $response->assertRedirect(route('import.prerequisites.index', ['fake', 'fake_job_1']));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\IndexController
- */
- public function testCreateFakeNoPrereq(): void
- {
- // mock stuff:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $userRepository = $this->mock(UserRepositoryInterface::class);
- $fakePrerequisites = $this->mock(FakePrerequisites::class);
-
- // fake job:
- $importJob = new ImportJob;
- $importJob->provider = 'fake';
- $importJob->key = 'fake_job_2';
- $importJob->user_id = 1;
-
- $this->mockDefaultSession();
-
- // mock call:
-
- $fakePrerequisites->shouldReceive('isComplete')->times(3)->andReturn(true);
- $fakePrerequisites->shouldReceive('setUser')->times(3);
-
-
-
- $repository->shouldReceive('create')->withArgs(['fake'])->andReturn($importJob);
- $repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'has_prereq'])->andReturn($importJob)->once();
-
- $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->times(3);
-
- $this->be($this->user());
- $response = $this->get(route('import.create', ['fake']));
- $response->assertStatus(302);
- // expect a redirect to prerequisites
- $response->assertRedirect(route('import.job.configuration.index', ['fake_job_2']));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\IndexController
- */
- public function testCreateFileHasNoPrereq(): void
- {
- // mock stuff:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $userRepository = $this->mock(UserRepositoryInterface::class);
- $bunqPrerequisites = $this->mock(BunqPrerequisites::class);
- $spectrePrerequisites = $this->mock(SpectrePrerequisites::class);
- $ynabPrerequisites = $this->mock(YnabPrerequisites::class);
-
- // fake job:
- $importJob = new ImportJob;
- $importJob->provider = 'file';
- $importJob->key = 'file_job_1';
- $importJob->user_id = 1;
-
- $this->mockDefaultSession();
-
- // mock calls
- //$fakePrerequisites->shouldReceive('setUser')->times(2);
- $bunqPrerequisites->shouldReceive('setUser')->times(2);
- $spectrePrerequisites->shouldReceive('setUser')->times(2);
- $ynabPrerequisites->shouldReceive('setUser')->times(2);
-
- //$fakePrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true);
- $bunqPrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true);
- $spectrePrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true);
- $ynabPrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true);
-
- $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->times(3);
- $repository->shouldReceive('create')->withArgs(['file'])->andReturn($importJob);
- $repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'has_prereq'])->andReturn($importJob)->once();
-
-
- $this->be($this->user());
- $response = $this->get(route('import.create', ['file']));
- $response->assertStatus(302);
- // expect a redirect to prerequisites
- $response->assertRedirect(route('import.job.configuration.index', ['file_job_1']));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\IndexController
- */
- public function testDownload(): void
- {
- // mock stuff:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $userRepository = $this->mock(UserRepositoryInterface::class);
- $bunqPrerequisites = $this->mock(BunqPrerequisites::class);
- $spectrePrerequisites = $this->mock(SpectrePrerequisites::class);
- $ynabPrerequisites = $this->mock(YnabPrerequisites::class);
-
- $this->mockDefaultSession();
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'dc_' . $this->randomInt();
- $job->status = 'ready_to_run';
- $job->stage = 'go-for-import';
- $job->provider = 'file';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- $fakeConfig = [
- 'hi' => 'there',
- 1 => true,
- 'column-mapping-config' => ['a', 'b', 'c'],
- ];
-
- $repository->shouldReceive('getConfiguration')->andReturn($fakeConfig)->once();
- $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
-
- //$fakePrerequisites->shouldReceive('setUser')->times(1);
- $bunqPrerequisites->shouldReceive('setUser')->times(1);
- $spectrePrerequisites->shouldReceive('setUser')->times(1);
- $ynabPrerequisites->shouldReceive('setUser')->times(1);
- //$filePrerequisites->shouldReceive('setUser')->times(1);
-
- //$fakePrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true);
- $bunqPrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true);
- $spectrePrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true);
- $ynabPrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true);
- //$filePrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true);
-
- $this->be($this->user());
- $response = $this->get(route('import.job.download', [$job->key]));
- $response->assertStatus(200);
- $response->assertExactJson(['column-mapping-config' => ['a', 'b', 'c'], 'delimiter' => ',', 'hi' => 'there', 1 => true]);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\IndexController
- */
- public function testIndex(): void
- {
- $this->be($this->user());
-
- // fake stuff:
- $userRepository = $this->mock(UserRepositoryInterface::class);
- $bunqPrerequisites = $this->mock(BunqPrerequisites::class);
- $spectrePrerequisites = $this->mock(SpectrePrerequisites::class);
- $ynabPrerequisites = $this->mock(YnabPrerequisites::class);
- $this->mock(ImportJobRepositoryInterface::class);
-
- $this->mockDefaultSession();
-
- // call methods:
- $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false);
- $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(false);
-
- //$fakePrerequisites->shouldReceive('setUser')->once();
- $bunqPrerequisites->shouldReceive('setUser')->once();
- $spectrePrerequisites->shouldReceive('setUser')->once();
- $ynabPrerequisites->shouldReceive('setUser')->once();
-
- //$fakePrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
- $bunqPrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
- $spectrePrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
- $ynabPrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
-
- $response = $this->get(route('import.index'));
- $response->assertStatus(200);
- $response->assertSee('
');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\IndexController
- */
- public function testIndexDemo(): void
- {
- $this->be($this->user());
-
- // fake stuff:
- $fakePrerequisites = $this->mock(FakePrerequisites::class);
- $userRepository = $this->mock(UserRepositoryInterface::class);
- $this->mock(ImportJobRepositoryInterface::class);
-
- $this->mockDefaultSession();
-
- // call methods:
- $fakePrerequisites->shouldReceive('setUser')->once();
- $fakePrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
-
- $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true);
- $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(false);
-
- $response = $this->get(route('import.index'));
- $response->assertStatus(200);
- $response->assertSee('');
- }
-}
diff --git a/tests/Feature/Controllers/Import/JobConfigurationControllerTest.php b/tests/Feature/Controllers/Import/JobConfigurationControllerTest.php
deleted file mode 100644
index be5fc3bf64..0000000000
--- a/tests/Feature/Controllers/Import/JobConfigurationControllerTest.php
+++ /dev/null
@@ -1,291 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-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;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class JobConfigurationControllerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class JobConfigurationControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobConfigurationController
- */
- public function testIndex(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = '1Afake_job_' . $this->randomInt();
- $job->status = 'has_prereq';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->save();
-
- $this->mockDefaultSession();
-
- // 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();
- $configurator->shouldReceive('configurationComplete')->once()->andReturn(false);
- $configurator->shouldReceive('getNextView')->once()->andReturn('import.fake.apply-rules');
- $configurator->shouldReceive('getNextData')->once()
- ->andReturn(['rulesOptions' => [1 => 'Y', 0 => 'N',],]);
-
-
- $this->be($this->user());
- $response = $this->get(route('import.job.configuration.index', [$job->key]));
- $response->assertStatus(200);
- // expect a redirect to prerequisites
- $response->assertSee('');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobConfigurationController
- */
- public function testIndexBadState(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = '2Bfake_job_' . $this->randomInt();
- $job->status = 'some_bad_state';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->save();
-
- $this->mockDefaultSession();
-
- // mock repositories and configuration handling classes:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $configurator = $this->mock(FakeJobConfiguration::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
-
- $this->be($this->user());
- $response = $this->get(route('import.job.configuration.index', [$job->key]));
- $response->assertStatus(302);
- $response->assertRedirect(route('import.index'));
- $response->assertSessionHas('error', 'To access this page, your import job cannot have status "some_bad_state".');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobConfigurationController
- */
- public function testIndexComplete(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = '3Cfake_job_' . $this->randomInt();
- $job->status = 'has_prereq';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->save();
-
- $this->mockDefaultSession();
-
- // 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();
- $configurator->shouldReceive('configurationComplete')->once()->andReturn(true);
- $repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run']);
-
- $this->be($this->user());
- $response = $this->get(route('import.job.configuration.index', [$job->key]));
- $response->assertStatus(302);
- $response->assertRedirect(route('import.job.status.index', [$job->key]));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobConfigurationController
- */
- public function testPost(): void
- {
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = '4Dfake_job_' . $this->randomInt();
- $job->status = 'has_prereq';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->save();
-
- $this->mockDefaultSession();
-
- $messages = new MessageBag;
- $messages->add('some', 'srrange message');
-
- // 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();
- $configurator->shouldReceive('configurationComplete')->once()->andReturn(false);
- $configurator->shouldReceive('configureJob')->withArgs([[]])->once()->andReturn($messages);
-
- // call thing.
- $this->be($this->user());
- $response = $this->post(route('import.job.configuration.post', [$job->key]));
- $response->assertStatus(302);
- $response->assertRedirect(route('import.job.configuration.index', [$job->key]));
- $response->assertSessionHas('warning', $messages->first());
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobConfigurationController
- */
- public function testPostBadState(): void
- {
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = '5Ffake_job_' . $this->randomInt();
- $job->status = 'some_bad_state';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->save();
-
- $this->mockDefaultSession();
-
- $messages = new MessageBag;
- $messages->add('some', 'srrange message');
-
- // 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());
- $response = $this->post(route('import.job.configuration.post', [$job->key]));
- $response->assertStatus(302);
- $response->assertRedirect(route('import.index'));
- $response->assertSessionHas('error', 'To access this page, your import job cannot have status "some_bad_state".');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobConfigurationController
- */
- public function testPostComplete(): void
- {
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = '6Efake_job_' . $this->randomInt();
- $job->status = 'has_prereq';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->save();
-
- $this->mockDefaultSession();
-
- // 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();
- $configurator->shouldReceive('configurationComplete')->once()->andReturn(true);
- $repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run']);
-
- // call thing.
- $this->be($this->user());
- $response = $this->post(route('import.job.configuration.post', [$job->key]));
- $response->assertStatus(302);
- $response->assertRedirect(route('import.job.status.index', [$job->key]));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobConfigurationController
- */
- public function testPostWithUpload(): void
- {
- $file = UploadedFile::fake()->image('avatar.jpg');
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = '7Dfake_job_' . $this->randomInt();
- $job->status = 'has_prereq';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->save();
-
- $this->mockDefaultSession();
-
- $messages = new MessageBag;
- $messages->add('some', 'srrange message');
-
- // 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();
- $configurator->shouldReceive('configurationComplete')->once()->andReturn(false);
- $configurator->shouldReceive('configureJob')->once()->andReturn($messages);
- $repository->shouldReceive('storeFileUpload')->once()->andReturn(new MessageBag);
-
- // call thing.
- $this->be($this->user());
- $response = $this->post(route('import.job.configuration.post', [$job->key]), ['import_file' => $file]);
- $response->assertStatus(302);
- $response->assertRedirect(route('import.job.configuration.index', [$job->key]));
- $response->assertSessionHas('warning', $messages->first());
- }
-
-
-}
diff --git a/tests/Feature/Controllers/Import/JobStatusControllerTest.php b/tests/Feature/Controllers/Import/JobStatusControllerTest.php
deleted file mode 100644
index a305e8b713..0000000000
--- a/tests/Feature/Controllers/Import/JobStatusControllerTest.php
+++ /dev/null
@@ -1,440 +0,0 @@
-.
- */
-declare(strict_types=1);
-
-namespace Tests\Feature\Controllers\Import;
-
-use Exception;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Import\Routine\FakeRoutine;
-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;
-
-/**
- * Class JobStatusControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class JobStatusControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobStatusController
- */
- 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_' . $this->randomInt();
- $job->status = 'ready_to_run';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->save();
-
- $this->mockDefaultSession();
-
- $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]));
- $response->assertStatus(200);
- $response->assertSee('');
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobStatusController
- */
- 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_' . $this->randomInt();
- $job->status = 'ready_to_run';
- $job->provider = 'file';
- $job->transactions = [];
- $job->file_type = '';
- $job->save();
-
- $this->mockDefaultSession();
-
- $importRepos->shouldReceive('countTransactions')->once()->andReturn(0);
-
- // call thing.
- $this->be($this->user());
- $response = $this->get(route('import.job.status.json', [$job->key]));
- $response->assertStatus(200);
- $response->assertSee(
- 'No transactions have been imported. Perhaps they were all duplicates is simply no transactions where present to be imported. Perhaps the log files can tell you what happened. If you import data regularly, this is normal.'
- );
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobStatusController
- */
- public function testJsonWithTag(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $tag = $this->getRandomTag();
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'Cfake_job_' . $this->randomInt();
- $job->status = 'ready_to_run';
- $job->provider = 'fake';
- $job->transactions = [];
- $job->file_type = '';
- $job->tag()->associate($tag);
- $job->save();
-
- $this->mockDefaultSession();
- $importRepos->shouldReceive('countTransactions')->once()->andReturn(0);
- $importRepos->shouldReceive('countByTag')->atLeast()->once()->andReturn(0);
-
- // call thing.
- $this->be($this->user());
- $response = $this->get(route('import.job.status.json', [$job->key]));
- $response->assertStatus(200);
- $response->assertSee(
- 'No transactions have been imported. Perhaps they were all duplicates is simply no transactions where present to be imported. Perhaps the log files can tell you what happened. If you import data regularly, this is normal.'
- );
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobStatusController
- */
- 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();
- $second = $this->user()->transactionJournals()->where('id', '!=', $journal->id)->first();
- $tag->transactionJournals()->sync([$journal->id, $second->id]);
-
- $this->mockDefaultSession();
-
- $importRepos->shouldReceive('countTransactions')->once()->andReturn(2);
- $importRepos->shouldReceive('countByTag')->atLeast()->once()->andReturn(2);
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'Dfake_job_' . $this->randomInt();
- $job->status = 'ready_to_run';
- $job->provider = 'fake';
- $job->transactions = [];
- $job->file_type = '';
- $job->tag()->associate($tag);
- $job->save();
-
- // call thing.
- $this->be($this->user());
- $response = $this->get(route('import.job.status.json', [$job->key]));
- $response->assertStatus(200);
- $response->assertSee(
- 'Firefly III has imported 2 transactions. They are stored under tag id
- );
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobStatusController
- */
- 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();
- $tag->transactionJournals()->sync([$journal->id]);
-
- $this->mockDefaultSession();
-
- $importRepos->shouldReceive('countTransactions')->once()->andReturn(1);
- $importRepos->shouldReceive('countByTag')->atLeast()->once()->andReturn(1);
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'Efake_job_' . $this->randomInt();
- $job->status = 'ready_to_run';
- $job->provider = 'fake';
- $job->transactions = [];
- $job->file_type = '';
- $job->tag()->associate($tag);
- $job->save();
-
- // call thing.
- $this->be($this->user());
- $response = $this->get(route('import.job.status.json', [$job->key]));
- $response->assertStatus(200);
- $response->assertSee(
- 'Exactly one transaction has been imported. It is stored under tag id
- );
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobStatusController
- */
- public function testStart(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'Ffake_job_' . $this->randomInt();
- $job->status = 'ready_to_run';
- $job->provider = 'fake';
- $job->transactions = [];
- $job->file_type = '';
- $job->save();
-
- $this->mockDefaultSession();
-
- // mock stuff
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $routine = $this->mock(FakeRoutine::class);
-
- // mock calls:
- $routine->shouldReceive('setImportJob')->once();
- $routine->shouldReceive('run')->once();
-
- // call thing.
- $this->be($this->user());
- $response = $this->post(route('import.job.start', [$job->key]));
- $response->assertStatus(200);
- $response->assertExactJson(['status' => 'OK', 'message' => 'stage_finished']);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobStatusController
- */
- public function testStartException(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'Gfake_job_' . $this->randomInt();
- $job->status = 'ready_to_run';
- $job->provider = 'fake';
- $job->transactions = [];
- $job->file_type = '';
- $job->save();
-
- $this->mockDefaultSession();
-
- // mock stuff
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $routine = $this->mock(FakeRoutine::class);
-
- // mock calls:
- $repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'error']);
- $routine->shouldReceive('setImportJob')->once();
- $routine->shouldReceive('run')->andThrow(new Exception('Unknown exception'));
-
- // call thing.
- Log::warning('The following error is part of a test.');
- $this->be($this->user());
- $response = $this->post(route('import.job.start', [$job->key]));
- $response->assertStatus(200);
- $response->assertExactJson(['status' => 'NOK', 'message' => 'The import routine crashed: Unknown exception']);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobStatusController
- */
- public function testStartFireflyException(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'Hfake_job_' . $this->randomInt();
- $job->status = 'ready_to_run';
- $job->provider = 'fake';
- $job->transactions = [];
- $job->file_type = '';
- $job->save();
-
- $this->mockDefaultSession();
-
- // mock stuff
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $routine = $this->mock(FakeRoutine::class);
-
- // mock calls:
- $repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'error']);
- $routine->shouldReceive('setImportJob')->once();
- $routine->shouldReceive('run')->andThrow(new FireflyException('Unknown exception'));
-
- // call thing.
- Log::warning('The following error is part of a test.');
- $this->be($this->user());
- $response = $this->post(route('import.job.start', [$job->key]));
- $response->assertStatus(200);
- $response->assertExactJson(['status' => 'NOK', 'message' => 'The import routine crashed: Unknown exception']);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobStatusController
- */
- 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();
-
- $this->mockDefaultSession();
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'Ifake_job_' . $this->randomInt();
- $job->status = 'bad_state';
- $job->provider = 'fake';
- $job->transactions = [];
- $job->file_type = '';
- $job->save();
-
- // call thing.
- $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 "bad_state".']);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobStatusController
- */
- public function testStore(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'Jfake_job_' . $this->randomInt();
- $job->status = 'provider_finished';
- $job->provider = 'fake';
- $job->transactions = [];
- $job->file_type = '';
- $job->save();
-
- $this->mockDefaultSession();
-
- // 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']);
- $repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'storage_finished']);
- $storage->shouldReceive('setImportJob')->once();
- $storage->shouldReceive('store')->once();
-
-
- $this->be($this->user());
- $response = $this->post(route('import.job.store', [$job->key]));
- $response->assertStatus(200);
- $response->assertExactJson(['status' => 'OK', 'message' => 'storage_finished']);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobStatusController
- */
- public function testStoreException(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'Lfake_job_' . $this->randomInt();
- $job->status = 'provider_finished';
- $job->provider = 'fake';
- $job->transactions = [];
- $job->file_type = '';
- $job->save();
-
- $this->mockDefaultSession();
-
- // 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']);
- $repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'error']);
- $storage->shouldReceive('setImportJob')->once();
- $storage->shouldReceive('store')->once()->andThrow(new FireflyException('Some storage exception.'));
-
-
- $this->be($this->user());
- $response = $this->post(route('import.job.store', [$job->key]));
- $response->assertStatus(200);
- $response->assertExactJson(['status' => 'NOK', 'message' => 'The import storage routine crashed: Some storage exception.']);
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\JobStatusController
- */
- public function testStoreInvalidState(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'Kfake_job_' . $this->randomInt();
- $job->status = 'some_bad_state';
- $job->provider = 'fake';
- $job->transactions = [];
- $job->file_type = '';
- $job->save();
-
- $this->mockDefaultSession();
-
- $this->be($this->user());
- $response = $this->post(route('import.job.store', [$job->key]));
- $response->assertStatus(200);
- $response->assertExactJson(
- ['status' => 'NOK', 'message' => 'JobStatusController::start expects status "provider_finished" instead of "' . $job->status . '".']
- );
- }
-}
diff --git a/tests/Feature/Controllers/Import/PrerequisitesControllerTest.php b/tests/Feature/Controllers/Import/PrerequisitesControllerTest.php
deleted file mode 100644
index b0c6a6a84e..0000000000
--- a/tests/Feature/Controllers/Import/PrerequisitesControllerTest.php
+++ /dev/null
@@ -1,371 +0,0 @@
-.
- */
-declare(strict_types=1);
-
-namespace Tests\Feature\Controllers\Import;
-
-use FireflyIII\Import\Prerequisites\BunqPrerequisites;
-use FireflyIII\Import\Prerequisites\FakePrerequisites;
-use FireflyIII\Import\Prerequisites\SpectrePrerequisites;
-use FireflyIII\Import\Prerequisites\YnabPrerequisites;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\MessageBag;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class AccountControllerTest
- *
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class PrerequisitesControllerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController
- */
- public function testIndex(): void
- {
- $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $prereq = $this->mock(BunqPrerequisites::class);
- $this->mock(ImportJobRepositoryInterface::class);
-
- // mock some prerequisites:
- $spectrePrereq = $this->mock(SpectrePrerequisites::class);
- $ynabPrereq = $this->mock(YnabPrerequisites::class);
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'A_pre_job_' . $this->randomInt();
- $job->status = 'new';
- $job->provider = 'fake';
- $job->transactions = [];
- $job->file_type = '';
- $job->save();
-
- $prereq->shouldReceive('setUser')->atLeast()->once();
- $spectrePrereq->shouldReceive('setUser')->atLeast()->once();
- $ynabPrereq->shouldReceive('setUser')->atLeast()->once();
-
- $prereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
- $spectrePrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
- $ynabPrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
-
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
-
-
- $prereq->shouldReceive('getView')->once()->andReturn('import.fake.prerequisites');
- $prereq->shouldReceive('getViewParameters')->once()->andReturn(['api_key' => '']);
-
-
- $this->be($this->user());
- $response = $this->get(route('import.prerequisites.index', ['bunq', $job->key]));
- $response->assertStatus(200);
-
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController
- */
- public function testIndexBadState(): void
- {
- $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mock(ImportJobRepositoryInterface::class);
-
- // mock some prerequisites:
- $bunqPrereq = $this->mock(BunqPrerequisites::class);
- $spectrePrereq = $this->mock(SpectrePrerequisites::class);
- $ynabPrereq = $this->mock(YnabPrerequisites::class);
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'B_pre_job_' . $this->randomInt();
- $job->status = 'some_Bad_state';
- $job->provider = 'fake';
- $job->transactions = [];
- $job->file_type = '';
- $job->save();
-
- // fake calls to prereq classes
- $bunqPrereq->shouldReceive('setUser')->atLeast()->once();
- $spectrePrereq->shouldReceive('setUser')->atLeast()->once();
- $ynabPrereq->shouldReceive('setUser')->atLeast()->once();
-
- $bunqPrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
- $spectrePrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
- $ynabPrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
-
-
- $this->be($this->user());
- $response = $this->get(route('import.prerequisites.index', ['bunq', $job->key]));
- $response->assertStatus(302);
- $response->assertRedirect(route('import.index'));
- }
-
- /**
- * @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController
- */
- public function testIndexComplete(): void
- {
- $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
-
- // mock some prerequisites:
- $bunqPrereq = $this->mock(BunqPrerequisites::class);
- $spectrePrereq = $this->mock(SpectrePrerequisites::class);
- $ynabPrereq = $this->mock(YnabPrerequisites::class);
-
- // fake calls to prereq classes
- $bunqPrereq->shouldReceive('setUser')->atLeast()->once();
- $spectrePrereq->shouldReceive('setUser')->atLeast()->once();
- $ynabPrereq->shouldReceive('setUser')->atLeast()->once();
-
- $bunqPrereq->shouldReceive('isComplete')->andReturn(true)->atLeast()->once();
- $spectrePrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
- $ynabPrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
-
- //Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(),'x','x'])->atLeast()->once();
-
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'C_pre_job_' . $this->randomInt();
- $job->status = 'new';
- $job->provider = 'bunq';
- $job->transactions = [];
- $job->file_type = '';
- $job->save();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
- $repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'has_prereq']);
-
- $this->be($this->user());
- $response = $this->get(route('import.prerequisites.index', ['bunq', $job->key]));
- $response->assertStatus(302);
- $response->assertRedirect(route('import.job.configuration.index', [$job->key]));
-
- }
-
- /**
- * Redirects to configuration.
- *
- * @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController
- */
- public function testPost(): void
- {
- $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
-
- // mock some prerequisites:
- $bunqPrereq = $this->mock(BunqPrerequisites::class);
- $spectrePrereq = $this->mock(SpectrePrerequisites::class);
- $ynabPrereq = $this->mock(YnabPrerequisites::class);
-
- // fake calls to prereq classes
- $bunqPrereq->shouldReceive('setUser')->atLeast()->once();
- $spectrePrereq->shouldReceive('setUser')->atLeast()->once();
- $ynabPrereq->shouldReceive('setUser')->atLeast()->once();
-
- $bunqPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
- $spectrePrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
- $ynabPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
-
- $bunqPrereq->shouldReceive('storePrerequisites')->atLeast()->once()->andReturn(new MessageBag);
-
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'D_pre_job_' . $this->randomInt();
- $job->status = 'new';
- $job->provider = 'fake';
- $job->transactions = [];
- $job->file_type = '';
- $job->save();
-
- $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']);
-
- $this->be($this->user());
- $response = $this->post(route('import.prerequisites.post', ['bunq', $job->key]));
- $response->assertStatus(302);
- $response->assertRedirect(route('import.job.configuration.index', [$job->key]));
- }
-
- /**
- * Bad state gives errors.
- *
- * @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController
- */
- public function testPostBadState(): void
- {
- $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $prereq = $this->mock(FakePrerequisites::class);
- $this->mock(ImportJobRepositoryInterface::class);
-
- // mock some prerequisites:
- $bunqPrereq = $this->mock(BunqPrerequisites::class);
- $spectrePrereq = $this->mock(SpectrePrerequisites::class);
- $ynabPrereq = $this->mock(YnabPrerequisites::class);
-
- // fake calls to prereq classes
- $bunqPrereq->shouldReceive('setUser')->atLeast()->once();
- $spectrePrereq->shouldReceive('setUser')->atLeast()->once();
- $ynabPrereq->shouldReceive('setUser')->atLeast()->once();
-
- $bunqPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
- $spectrePrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
- $ynabPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
-
-
- //Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturnNull();
- //Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'spectre_app_id', null])->andReturnNull();
- //Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturnNull();
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'D_pre_job_' . $this->randomInt();
- $job->status = 'badstate';
- $job->provider = 'bunq';
- $job->transactions = [];
- $job->file_type = '';
- $job->save();
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
- $this->be($this->user());
- $response = $this->post(route('import.prerequisites.post', ['bunq', $job->key]));
- $response->assertStatus(302);
- $response->assertRedirect(route('import.index'));
- $response->assertSessionHas('error', 'To access this page, your import job cannot have status "badstate".');
- }
-
- /**
- * Redirects to index.
- *
- * @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController
- */
- public function testPostNoJob(): void
- {
- $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $this->mock(ImportJobRepositoryInterface::class);
-
- // mock some prerequisites:
- $bunqPrereq = $this->mock(BunqPrerequisites::class);
- $spectrePrereq = $this->mock(SpectrePrerequisites::class);
- $ynabPrereq = $this->mock(YnabPrerequisites::class);
-
- // fake calls to prereq classes
- $bunqPrereq->shouldReceive('setUser')->atLeast()->once();
- $spectrePrereq->shouldReceive('setUser')->atLeast()->once();
- $ynabPrereq->shouldReceive('setUser')->atLeast()->once();
-
- $bunqPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
- $spectrePrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
- $ynabPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
-
- $bunqPrereq->shouldReceive('storePrerequisites')->atLeast()->once()->andReturn(new MessageBag);
-
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
-
- $this->be($this->user());
- $response = $this->post(route('import.prerequisites.post', ['bunq']));
- $response->assertStatus(302);
- $response->assertRedirect(route('import.index'));
- }
-
- /**
- * Error messages? Redirect back
- *
- * @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController
- */
- public function testPostWithMessages(): void
- {
- $this->mockDefaultSession();
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $prereq = $this->mock(FakePrerequisites::class);
- $this->mock(ImportJobRepositoryInterface::class);
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'D_pre_job_' . $this->randomInt();
- $job->status = 'new';
- $job->provider = 'bunq';
- $job->transactions = [];
- $job->file_type = '';
- $job->save();
-
- $messages = new MessageBag;
- $messages->add('some', 'message');
- $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
-
-
- // mock some prerequisites:
- $bunqPrereq = $this->mock(BunqPrerequisites::class);
- $spectrePrereq = $this->mock(SpectrePrerequisites::class);
- $ynabPrereq = $this->mock(YnabPrerequisites::class);
-
- // fake calls to prereq classes
- $bunqPrereq->shouldReceive('setUser')->atLeast()->once();
- $spectrePrereq->shouldReceive('setUser')->atLeast()->once();
- $ynabPrereq->shouldReceive('setUser')->atLeast()->once();
-
- $bunqPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
- $spectrePrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
- $ynabPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
-
- $bunqPrereq->shouldReceive('storePrerequisites')->atLeast()->once()->andReturn($messages);
-
-
-
-
- $this->be($this->user());
- $response = $this->post(route('import.prerequisites.post', ['bunq', $job->key]));
- $response->assertStatus(302);
- $response->assertRedirect(route('import.prerequisites.index', ['bunq', $job->key]));
- $response->assertSessionHas('error', 'message');
- }
-}
diff --git a/tests/Unit/Console/Commands/Import/CreateCSVImportTest.php b/tests/Unit/Console/Commands/Import/CreateCSVImportTest.php
deleted file mode 100644
index 4008d81744..0000000000
--- a/tests/Unit/Console/Commands/Import/CreateCSVImportTest.php
+++ /dev/null
@@ -1,439 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Console\Commands\Import;
-
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Import\Routine\FileRoutine;
-use FireflyIII\Import\Storage\ImportArrayStorage;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Repositories\User\UserRepositoryInterface;
-use Illuminate\Support\MessageBag;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class CreateCSVImportTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CreateCSVImportTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Covers a default run with perfect arguments.
- *
- * @covers \FireflyIII\Console\Commands\Import\CreateCSVImport
- */
- public function testHandle(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $jobRepos = $this->mock(ImportJobRepositoryInterface::class);
- $fileRoutine = $this->mock(FileRoutine::class);
- $storage = $this->mock(ImportArrayStorage::class);
- $user = $this->user();
- $token = new Preference;
- $importJob = $this->user()->importJobs()->first();
- $file = storage_path('build/test-upload.csv');
- $config = storage_path('build/configuration.json');
-
- // set preferences:
- $token->data = 'token';
-
- // mock calls to repository:
- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($user);
- $jobRepos->shouldReceive('setUser')->atLeast()->once();
- $jobRepos->shouldReceive('create')->atLeast()->once()->andReturn($importJob);
- $jobRepos->shouldReceive('storeCLIupload')->atLeast()->once()->andReturn(new MessageBag);
- $jobRepos->shouldReceive('setConfiguration')->atLeast()->once();
-
- // job is ready to run.
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run'])->atLeast()->once();
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->atLeast()->once();
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'storing_data'])->atLeast()->once();
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'storage_finished'])->atLeast()->once();
-
- // file routine gets called.
- $fileRoutine->shouldReceive('setImportJob')->atLeast()->once();
- $fileRoutine->shouldReceive('run')->atLeast()->once();
-
- // store data thing gets called.
- $storage->shouldReceive('setImportJob')->atLeast()->once();
- $storage->shouldReceive('store')->atLeast()->once();
-
- // mock Preferences.
- Preferences::shouldReceive('setForUser')->atLeast()->once()->withArgs([Mockery::any(), 'lastActivity', Mockery::any()]);
- Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'access_token', null])->andReturn($token);
-
-
- $parameters = [
- $file,
- $config,
- '--user=1',
- '--token=token',
- ];
-
- $this->artisan('firefly-iii:csv-import ' . implode(' ', $parameters))
- ->expectsOutput(sprintf('Import file : %s', $file))
- ->expectsOutput(sprintf('Configuration file : %s', $config))
- ->expectsOutput('User : #1 (james@firefly-iii.org)')
- ->expectsOutput(sprintf('Job : %s', $importJob->key))
- ->assertExitCode(0);
-
- // this method imports nothing so there is nothing to verify.
-
- }
-
- /**
- * Covers a default run with perfect arguments, but no import tag
- *
- * @covers \FireflyIII\Console\Commands\Import\CreateCSVImport
- */
- public function testHandleNoTag(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $jobRepos = $this->mock(ImportJobRepositoryInterface::class);
- $fileRoutine = $this->mock(FileRoutine::class);
- $storage = $this->mock(ImportArrayStorage::class);
- $user = $this->user();
- $token = new Preference;
-
- $importJob = ImportJob::create(
- [
- 'key' => 'key-' . $this->randomInt(),
- 'user_id' => 1,
- 'file_type' => 'csv',
- 'status' => 'new',
- 'errors' => [],
- ]
- );
-
- $file = storage_path('build/test-upload.csv');
- $config = storage_path('build/configuration.json');
-
- // set preferences:
- $token->data = 'token';
-
- // mock calls to repository:
- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($user);
- $jobRepos->shouldReceive('setUser')->atLeast()->once();
- $jobRepos->shouldReceive('create')->atLeast()->once()->andReturn($importJob);
- $jobRepos->shouldReceive('storeCLIupload')->atLeast()->once()->andReturn(new MessageBag);
- $jobRepos->shouldReceive('setConfiguration')->atLeast()->once();
-
- // job is ready to run.
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run'])->atLeast()->once();
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->atLeast()->once();
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'storing_data'])->atLeast()->once();
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'storage_finished'])->atLeast()->once();
-
- // file routine gets called.
- $fileRoutine->shouldReceive('setImportJob')->atLeast()->once();
- $fileRoutine->shouldReceive('run')->atLeast()->once();
-
- // store data thing gets called.
- $storage->shouldReceive('setImportJob')->atLeast()->once();
- $storage->shouldReceive('store')->atLeast()->once();
-
- // mock Preferences.
- Preferences::shouldReceive('setForUser')->atLeast()->once()->withArgs([Mockery::any(), 'lastActivity', Mockery::any()]);
- Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'access_token', null])->andReturn($token);
-
-
- $parameters = [
- $file,
- $config,
- '--user=1',
- '--token=token',
- ];
-
- $this->artisan('firefly-iii:csv-import ' . implode(' ', $parameters))
- ->expectsOutput(sprintf('Import file : %s', $file))
- ->expectsOutput(sprintf('Configuration file : %s', $config))
- ->expectsOutput('User : #1 (james@firefly-iii.org)')
- ->expectsOutput(sprintf('Job : %s', $importJob->key))
- ->expectsOutput('No transactions have been imported :(.')
- ->assertExitCode(0);
-
- // this method imports nothing so there is nothing to verify.
- }
-
- /**
- * Covers a default run with perfect arguments, but errors after importing.
- *
- * @covers \FireflyIII\Console\Commands\Import\CreateCSVImport
- */
- public function testHandleErrors(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $jobRepos = $this->mock(ImportJobRepositoryInterface::class);
- $fileRoutine = $this->mock(FileRoutine::class);
- $storage = $this->mock(ImportArrayStorage::class);
- $user = $this->user();
- $token = new Preference;
-
- $importJob = ImportJob::create(
- [
- 'key' => 'key-' . $this->randomInt(),
- 'user_id' => 1,
- 'file_type' => 'csv',
- 'status' => 'new',
- 'errors' => ['I am an error'],
- ]
- );
-
- $file = storage_path('build/test-upload.csv');
- $config = storage_path('build/configuration.json');
-
- // set preferences:
- $token->data = 'token';
-
- // mock calls to repository:
- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($user);
- $jobRepos->shouldReceive('setUser')->atLeast()->once();
- $jobRepos->shouldReceive('create')->atLeast()->once()->andReturn($importJob);
- $jobRepos->shouldReceive('storeCLIupload')->atLeast()->once()->andReturn(new MessageBag);
- $jobRepos->shouldReceive('setConfiguration')->atLeast()->once();
-
- // job is ready to run.
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run'])->atLeast()->once();
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->atLeast()->once();
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'storing_data'])->atLeast()->once();
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'storage_finished'])->atLeast()->once();
-
- // file routine gets called.
- $fileRoutine->shouldReceive('setImportJob')->atLeast()->once();
- $fileRoutine->shouldReceive('run')->atLeast()->once();
-
- // store data thing gets called.
- $storage->shouldReceive('setImportJob')->atLeast()->once();
- $storage->shouldReceive('store')->atLeast()->once();
-
- // mock Preferences.
- Preferences::shouldReceive('setForUser')->atLeast()->once()->withArgs([Mockery::any(), 'lastActivity', Mockery::any()]);
- Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'access_token', null])->andReturn($token);
-
-
- $parameters = [
- $file,
- $config,
- '--user=1',
- '--token=token',
- ];
-
- $this->artisan('firefly-iii:csv-import ' . implode(' ', $parameters))
- ->expectsOutput(sprintf('Import file : %s', $file))
- ->expectsOutput(sprintf('Configuration file : %s', $config))
- ->expectsOutput('User : #1 (james@firefly-iii.org)')
- ->expectsOutput(sprintf('Job : %s', $importJob->key))
- ->expectsOutput('- I am an error')
- ->assertExitCode(0);
-
- // this method imports nothing so there is nothing to verify.
- }
-
- /**
- * Crash while storing data.
- *
- * @covers \FireflyIII\Console\Commands\Import\CreateCSVImport
- */
- public function testHandleCrashStorage(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $jobRepos = $this->mock(ImportJobRepositoryInterface::class);
- $fileRoutine = $this->mock(FileRoutine::class);
- $storage = $this->mock(ImportArrayStorage::class);
- $user = $this->user();
- $token = new Preference;
- $importJob = $this->user()->importJobs()->first();
- $file = storage_path('build/test-upload.csv');
- $config = storage_path('build/configuration.json');
-
- // set preferences:
- $token->data = 'token';
-
- // mock calls to repository:
- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($user);
- $jobRepos->shouldReceive('setUser')->atLeast()->once();
- $jobRepos->shouldReceive('create')->atLeast()->once()->andReturn($importJob);
- $jobRepos->shouldReceive('storeCLIupload')->atLeast()->once()->andReturn(new MessageBag);
- $jobRepos->shouldReceive('setConfiguration')->atLeast()->once();
-
- // job is ready to run.
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run'])->atLeast()->once();
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->atLeast()->once();
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'storing_data'])->atLeast()->once();
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'error'])->atLeast()->once();
-
- // file routine gets called.
- $fileRoutine->shouldReceive('setImportJob')->atLeast()->once();
- $fileRoutine->shouldReceive('run')->atLeast()->once();
-
- // store data thing gets called.
- $storage->shouldReceive('setImportJob')->atLeast()->once();
- $storage->shouldReceive('store')->atLeast()->once()->andThrow(new FireflyException('I am storage error.'));
-
- // mock Preferences.
- Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'access_token', null])->andReturn($token);
-
-
- $parameters = [
- $file,
- $config,
- '--user=1',
- '--token=token',
- ];
- Log::warning('The following error is part of a test.');
- $this->artisan('firefly-iii:csv-import ' . implode(' ', $parameters))
- ->expectsOutput(sprintf('Import file : %s', $file))
- ->expectsOutput(sprintf('Configuration file : %s', $config))
- ->expectsOutput('User : #1 (james@firefly-iii.org)')
- ->expectsOutput(sprintf('Job : %s', $importJob->key))
- ->expectsOutput('The import routine crashed: I am storage error.')
- ->assertExitCode(1);
-
- // this method imports nothing so there is nothing to verify.
-
- }
-
- /**
- * The file processor crashes for some reason.
- *
- * @covers \FireflyIII\Console\Commands\Import\CreateCSVImport
- */
- public function testHandleCrashProcess(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $jobRepos = $this->mock(ImportJobRepositoryInterface::class);
- $fileRoutine = $this->mock(FileRoutine::class);
- $storage = $this->mock(ImportArrayStorage::class);
- $user = $this->user();
- $token = new Preference;
- $importJob = $this->user()->importJobs()->first();
- $file = storage_path('build/test-upload.csv');
- $config = storage_path('build/configuration.json');
-
- // set preferences:
- $token->data = 'token';
-
- // mock calls to repository:
- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($user);
- $jobRepos->shouldReceive('setUser')->atLeast()->once();
- $jobRepos->shouldReceive('create')->atLeast()->once()->andReturn($importJob);
- $jobRepos->shouldReceive('storeCLIupload')->atLeast()->once()->andReturn(new MessageBag);
- $jobRepos->shouldReceive('setConfiguration')->atLeast()->once();
-
- // job is ready to run.
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run'])->atLeast()->once();
- $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'error'])->atLeast()->once();
-
- // file routine gets called.
- $fileRoutine->shouldReceive('setImportJob')->atLeast()->once();
- $fileRoutine->shouldReceive('run')->atLeast()->once()->andThrows(new FireflyException('I am big bad exception.'));
-
- // mock Preferences.
- Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'access_token', null])->andReturn($token);
-
- $parameters = [
- $file,
- $config,
- '--user=1',
- '--token=token',
- ];
- Log::warning('The following error is part of a test.');
- $this->artisan('firefly-iii:csv-import ' . implode(' ', $parameters))
- ->expectsOutput(sprintf('Import file : %s', $file))
- ->expectsOutput(sprintf('Configuration file : %s', $config))
- ->expectsOutput('User : #1 (james@firefly-iii.org)')
- ->expectsOutput(sprintf('Job : %s', $importJob->key))
- ->expectsOutput('The import routine crashed: I am big bad exception.')
- ->assertExitCode(1);
-
- // this method imports nothing so there is nothing to verify.
-
- }
-
- /**
- * Throw error when storing data.
- *
- * @covers \FireflyIII\Console\Commands\Import\CreateCSVImport
- */
- public function testHandleFileStoreError(): void
- {
- $userRepos = $this->mock(UserRepositoryInterface::class);
- $jobRepos = $this->mock(ImportJobRepositoryInterface::class);
- $this->mock(FileRoutine::class);
- $this->mock(ImportArrayStorage::class);
- $user = $this->user();
- $token = new Preference;
- $importJob = $this->user()->importJobs()->first();
- $file = storage_path('build/test-upload.csv');
- $config = storage_path('build/configuration.json');
- $messages = new MessageBag;
- $messages->add('file', 'Some file error.');
-
- // set preferences:
- $token->data = 'token';
-
- // mock calls to repository:
- $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($user);
- $jobRepos->shouldReceive('setUser')->atLeast()->once();
- $jobRepos->shouldReceive('create')->atLeast()->once()->andReturn($importJob);
- $jobRepos->shouldReceive('storeCLIupload')->atLeast()->once()->andReturn($messages);
-
- // mock Preferences.
- Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'access_token', null])->andReturn($token);
-
-
- $parameters = [
- $file,
- $config,
- '--user=1',
- '--token=token',
- ];
- Log::warning('The following error is part of a test.');
- $this->artisan('firefly-iii:csv-import ' . implode(' ', $parameters))
- ->expectsOutput(sprintf('Import file : %s', $file))
- ->expectsOutput(sprintf('Configuration file : %s', $config))
- ->expectsOutput('User : #1 (james@firefly-iii.org)')
- ->expectsOutput(sprintf('Job : %s', $importJob->key))
- ->expectsOutput('Some file error.')
- ->assertExitCode(1);
-
- // this method imports nothing so there is nothing to verify.
- }
-}
diff --git a/tests/Unit/Support/FinTS/MetadataParserTest.php b/tests/Unit/Support/FinTS/MetadataParserTest.php
deleted file mode 100644
index 70b7eb1257..0000000000
--- a/tests/Unit/Support/FinTS/MetadataParserTest.php
+++ /dev/null
@@ -1,92 +0,0 @@
-.
- */
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\FinTS;
-
-use Fhp\Model\StatementOfAccount\Transaction as FinTSTransaction;
-use FireflyIII\Support\FinTS\MetadataParser;
-use Illuminate\Support\Facades\Log;
-use Tests\TestCase;
-
-/**
- *
- * Class MetadataParserTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class MetadataParserTest extends TestCase
-{
-
- /** @var MetadataParser */
- private $metadataParser;
-
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- $this->metadataParser = new MetadataParser();
- }
-
- /**
- * @covers \FireflyIII\Support\FinTS\MetadataParser
- */
- public function testDescriptionIsCorrectlyExtractedFromBeginning(): void
- {
- $transaction = $this->createTransactionWithDescription1('SVWZ+DescriptionABWA+xxx');
- $this->assertEquals('Description', $this->metadataParser->getDescription($transaction));
- }
-
- /**
- * @covers \FireflyIII\Support\FinTS\MetadataParser
- */
- public function testDescriptionIsCorrectlyExtractedFromEnd(): void
- {
- $transaction = $this->createTransactionWithDescription1('EREF+AbcCRED+DE123SVWZ+Description');
- $this->assertEquals('Description', $this->metadataParser->getDescription($transaction));
- }
-
- /**
- * @covers \FireflyIII\Support\FinTS\MetadataParser
- */
- public function testDescriptionIsCorrectlyExtractedFromMiddle(): void
- {
- $transaction = $this->createTransactionWithDescription1('EREF+AbcCRED+DE123SVWZ+DescriptionABWA+Ghi');
- $this->assertEquals('Description', $this->metadataParser->getDescription($transaction));
- }
-
- /**
- * @param string $description1
- *
- * @return FinTSTransaction
- */
- private function createTransactionWithDescription1(string $description1): FinTSTransaction
- {
- $transaction = $this->mock(FinTSTransaction::class);
- $transaction->shouldReceive('getDescription1')->atLeast()->once()->andReturn($description1);
-
- return $transaction;
- }
-}
diff --git a/tests/Unit/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandlerTest.php
deleted file mode 100644
index 15dfe7294f..0000000000
--- a/tests/Unit/Support/Import/JobConfiguration/Bunq/ChooseAccountsHandlerTest.php
+++ /dev/null
@@ -1,462 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\JobConfiguration\Bunq;
-
-
-use Amount;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Models\Account;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Support\Import\JobConfiguration\Bunq\ChooseAccountsHandler;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class ChooseAccountsHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ChooseAccountsHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Bunq\ChooseAccountsHandler
- */
- public function testCCFalse(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'caha' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'bunq';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // mock stuff
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- // mock calls
- $repository->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
-
- $repository->shouldReceive('getConfiguration')->andReturn([])->once();
-
- $handler = new ChooseAccountsHandler;
- $handler->setImportJob($job);
- $this->assertFalse($handler->configurationComplete());
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Bunq\ChooseAccountsHandler
- */
- public function testCCTrue(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'cahb' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'bunq';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // mock stuff
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- // mock calls
- $repository->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
-
- $repository->shouldReceive('getConfiguration')->andReturn(['mapping' => [0 => 1, 1 => 2]])->once();
- $repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'go-for-import'])->once();
-
- $handler = new ChooseAccountsHandler;
- $handler->setImportJob($job);
- $this->assertTrue($handler->configurationComplete());
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Bunq\ChooseAccountsHandler
- */
- public function testConfigureJob(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'cahc' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'bunq';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // data:
- $data = [
- 'account_mapping' => [
- '1234' => '456',
- ],
- 'apply_rules' => true,
- ];
-
- $config = [
- 'accounts' => [
- 0 => ['id' => 1234, 'name' => 'bunq'],
- ],
- 'apply-rules' => true,
- ];
- $expected = $config;
- $expected['mapping'][1234] = 456;
- $expected['bunq-iban'] = [];
-
- // mock stuff
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- // mock calls
- $repository->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->times(3);
- $repository->shouldReceive('setConfiguration')->withArgs([Mockery::any(), $expected])->once();
- $accountRepos->shouldReceive('findNull')->withArgs([456])->andReturn(new Account)->once();
-
- $handler = new ChooseAccountsHandler;
- $handler->setImportJob($job);
- try {
- $this->assertCount(0, $handler->configureJob($data));
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Bunq\ChooseAccountsHandler
- */
- public function testConfigureJobInvalidBunq(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'cahd' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'bunq';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // data:
- $data = [
- 'account_mapping' => [
- '1234' => '456',
- ],
- 'apply_rules' => true,
- ];
-
- $config = [
- 'accounts' => [
- 0 => ['id' => 1235, 'name' => 'bunq'],
- ],
- 'apply-rules' => true,
- ];
- $expected = $config;
- $expected['mapping'][0] = 456;
- $expected['bunq-iban'] = [];
-
- // mock stuff
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- // mock calls
- $repository->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->times(3);
- $repository->shouldReceive('setConfiguration')->withArgs([Mockery::any(), $expected])->once();
- $accountRepos->shouldReceive('findNull')->withArgs([456])->andReturn(new Account)->once();
-
- $handler = new ChooseAccountsHandler;
- $handler->setImportJob($job);
- try {
- $this->assertCount(0, $handler->configureJob($data));
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Bunq\ChooseAccountsHandler
- */
- public function testConfigureJobInvalidLocal(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'cahe' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'bunq';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // data:
- $data = [
- 'account_mapping' => [
- '1234' => '456',
- ],
- 'apply_rules' => true,
- ];
-
- $config = [
- 'accounts' => [
- 0 => ['id' => 1234, 'name' => 'bunq'],
- ],
- 'apply-rules' => true,
- ];
- $expected = $config;
- $expected['mapping'][1234] = 0;
- $expected['bunq-iban'] = [];
-
- // mock stuff
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- // mock calls
- $repository->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->times(3);
- $repository->shouldReceive('setConfiguration')->withArgs([Mockery::any(), $expected])->once();
- $accountRepos->shouldReceive('findNull')->withArgs([456])->andReturnNull()->once();
-
- $handler = new ChooseAccountsHandler;
- $handler->setImportJob($job);
- try {
- $this->assertCount(0, $handler->configureJob($data));
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Bunq\ChooseAccountsHandler
- */
- public function testConfigureJobNoMapping(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'cahf' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'bunq';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // data:
- $data = ['account_mapping' => [], 'apply_rules' => true,];
- $config = [
- 'accounts' => [
- 0 => ['id' => 1234, 'name' => 'bunq'],
- ],
- 'apply-rules' => true,
- ];
-
- // mock stuff
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- // mock calls
- $repository->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->times(1);
-
- $handler = new ChooseAccountsHandler;
- $handler->setImportJob($job);
- try {
- $messages = $handler->configureJob($data);
- $this->assertCount(1, $messages);
- $this->assertEquals('It seems you have not selected any accounts.', $messages->first());
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Bunq\ChooseAccountsHandler
- */
- public function testGetNextData(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'cahg' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'bunq';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // data:
- $config = [
- 'accounts' => [
- 0 => ['id' => 1234, 'name' => 'bunq'],
- ],
- ];
-
- $collection = new Collection;
- $account = $this->user()->accounts()->first();
- $euro = $this->getEuro();
- $collection->push($account);
-
-
- // mock stuff
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- // mock calls
- $repository->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->times(1);
- $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn($collection)->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($euro)->once();
-
- $expected = [
- 'accounts' => $config['accounts'],
- 'local_accounts' => [
- $account->id => [
- 'name' => $account->name,
- 'iban' => $account->iban,
- 'code' => $euro->code,
- ],
- ],
- ];
-
- $handler = new ChooseAccountsHandler;
- $handler->setImportJob($job);
- try {
- $data = $handler->getNextData();
- $this->assertEquals($expected, $data);
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Bunq\ChooseAccountsHandler
- */
- public function testGetNextDataNull(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'cahg' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'bunq';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // data:
- $config = [
- 'accounts' => [
- 0 => ['id' => 1234, 'name' => 'bunq'],
- ],
- ];
-
- $collection = new Collection;
- $account = $this->user()->accounts()->first();
- $euro = $this->getEuro();
- $collection->push($account);
-
-
- // mock stuff
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
-
- // mock calls
- $repository->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->times(1);
- $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn($collection)->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
- $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(null)->once();
- Amount::shouldReceive('getDefaultCurrencyByUser')->once()->andReturn($euro);
-
- $expected = [
- 'accounts' => $config['accounts'],
- 'local_accounts' => [
- $account->id => [
- 'name' => $account->name,
- 'iban' => $account->iban,
- 'code' => $euro->code,
- ],
- ],
- ];
-
- $handler = new ChooseAccountsHandler;
- $handler->setImportJob($job);
- try {
- $data = $handler->getNextData();
- $this->assertEquals($expected, $data);
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
-
-}
diff --git a/tests/Unit/Support/Import/JobConfiguration/Bunq/NewBunqJobHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/Bunq/NewBunqJobHandlerTest.php
deleted file mode 100644
index b7a75e98f7..0000000000
--- a/tests/Unit/Support/Import/JobConfiguration/Bunq/NewBunqJobHandlerTest.php
+++ /dev/null
@@ -1,78 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\JobConfiguration\Bunq;
-
-
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Support\Import\JobConfiguration\Bunq\NewBunqJobHandler;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class NewBunqJobHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class NewBunqJobHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Bunq\NewBunqJobHandler
- */
- public function testCC(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'cXha' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'bunq';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // expected config:
- //$expected = [];
-
- // mock stuff
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- // mock calls
- $repository->shouldReceive('setUser')->once();
-
- $handler = new NewBunqJobHandler();
- $handler->setImportJob($job);
- $this->assertTrue($handler->configurationComplete());
- }
-
-}
diff --git a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureMappingHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/File/ConfigureMappingHandlerTest.php
deleted file mode 100644
index d884e11371..0000000000
--- a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureMappingHandlerTest.php
+++ /dev/null
@@ -1,525 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\JobConfiguration\File;
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
-use FireflyIII\Import\Mapper\Budgets;
-use FireflyIII\Import\MapperPreProcess\TagsSpace;
-use FireflyIII\Import\Specifics\IngDescription;
-use FireflyIII\Models\Attachment;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler;
-use Illuminate\Support\Collection;
-use League\Csv\Exception;
-use League\Csv\Reader;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class ConfigureMappingHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- *
- */
-class ConfigureMappingHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
- */
- public function testApplySpecifics(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
-
- $importRepos->shouldReceive('setUser')->once();
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'mapG' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- $expected = ['a' => 'ING'];
-
- // mock ING description (see below)
- $ingDescr = $this->mock(IngDescription::class);
- $ingDescr->shouldReceive('run')->once()->andReturn($expected);
-
- $config = [
- 'specifics' => [
- 'IngDescription' => 1,
- 'bad-specific' => 1,
- ],
- ];
-
- $handler = new ConfigureMappingHandler;
- $handler->setImportJob($job);
- $result = $handler->applySpecifics($config, []);
- $this->assertEquals($expected, $result);
-
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
- */
- public function testConfigureJob(): void
- {
-
- // create fake input for class method:
- $input = [
- 'mapping' => [
-
- 0 => [// column
- 'fake-iban' => 1,
- 'other-fake-value' => '2', // string
- ],
- 1 => [
- 3 => 2, // fake number
- 'final-fake-value' => 3,
- 'mapped-to-zero' => 0,
- ],
-
- ],
- ];
- $expectedResult = [
- 'column-mapping-config' =>
- [
- 0 => [
- 'fake-iban' => 1,
- 'other-fake-value' => 2,
- ],
- 1 => [
- '3' => 2,
- 'final-fake-value' => 3,
- ],
- ],
-
- ];
-
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'mapA' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
-
- // run configure mapping handler.
- // expect specific results:
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('setStage')->once()->withArgs([Mockery::any(), 'ready_to_run']);
- $repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $expectedResult]);
-
-
- $handler = new ConfigureMappingHandler;
- $handler->setImportJob($job);
- $handler->configureJob($input);
-
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
- */
- public function testDoColumnConfig(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
- $importRepos->shouldReceive('setUser')->once();
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'mapE' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- $fakeBudgets = [
- 0 => 'dont map',
- 1 => 'Fake budget A',
- 4 => 'Other fake budget',
- ];
-
- // fake budget mapper (see below)
- $budgetMapper = $this->mock(Budgets::class);
- $budgetMapper->shouldReceive('getMap')->once()->andReturn($fakeBudgets);
-
- // input array:
- $input = [
- 'column-roles' => [
- 0 => 'description', // cannot be mapped
- 1 => 'sepa-ct-id', // cannot be mapped
- 2 => 'tags-space', // cannot be mapped, has a pre-processor.
- 3 => 'account-id', // can be mapped
- 4 => 'budget-id' // can be mapped.
- ],
- 'column-do-mapping' => [
- 0 => false, // don't try to map description
- 1 => true, // try to map sepa (cannot)
- 2 => true, // try to map tags (cannot)
- 3 => false, // dont map mappable
- 4 => true, // want to map, AND can map.
- ],
- ];
-
- $expected = [
- 4 => [
- 'name' => 'budget-id',
- 'options' => $fakeBudgets,
- 'preProcessMap' => '',
- 'values' => [],
- ],
- ];
-
- $handler = new ConfigureMappingHandler;
- $handler->setImportJob($job);
- try {
- $result = $handler->doColumnConfig($input);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- $this->assertEquals($expected, $result);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
- */
- public function testDoMapOfColumn(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
-
- $importRepos->shouldReceive('setUser')->once();
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'mapC' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- $combinations = [
- ['role' => 'description', 'expected' => false, 'requested' => false], // description cannot be mapped. Will always return false.
- ['role' => 'description', 'expected' => false, 'requested' => true], // description cannot be mapped. Will always return false.
- ['role' => 'currency-id', 'expected' => false, 'requested' => false], // if not requested, return false.
- ['role' => 'currency-id', 'expected' => true, 'requested' => true], // if requested, return true.
- ];
-
- $handler = new ConfigureMappingHandler;
- $handler->setImportJob($job);
- foreach ($combinations as $info) {
- $this->assertEquals($info['expected'], $handler->doMapOfColumn($info['role'], $info['requested']));
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
- */
- public function testGetNextData(): void
- {
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'mapH' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [
- 'column-roles' => [
- 0 => 'description', // cannot be mapped
- 1 => 'sepa-ct-id', // cannot be mapped
- 2 => 'tags-space', // cannot be mapped, has a pre-processor.
- 3 => 'account-id', // can be mapped
- 4 => 'budget-id' // can be mapped.
- ],
- 'column-do-mapping' => [
- 0 => false, // don't try to map description
- 1 => true, // try to map sepa (cannot)
- 2 => true, // try to map tags (cannot)
- 3 => false, // dont map mappable
- 4 => true, // want to map, AND can map.
- ],
- 'delimiter' => ',',
- ];
- $job->save();
-
- // make one attachment.
- $att = new Attachment;
- $att->filename = 'import_file';
- $att->user_id = $this->user()->id;
- $att->attachable_id = $job->id;
- $att->attachable_type = ImportJob::class;
- $att->md5 = md5('hello');
- $att->mime = 'fake';
- $att->size = 3;
- $att->save();
-
- // fake some data.
- $fileContent = "column1,column2,column3,column4,column5\nvalue1,value2,value3,value4,value5";
- $fakeBudgets = [
- 0 => 'dont map',
- 1 => 'Fake budget A',
- 4 => 'Other fake budget',
- ];
- // mock some helpers:
- $attachments = $this->mock(AttachmentHelperInterface::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('getConfiguration')->once()->withArgs([Mockery::any()])->andReturn($job->configuration);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('getAttachments')->once()->withArgs([Mockery::any()])->andReturn(new Collection([$att]));
- $attachments->shouldReceive('getAttachmentContent')->withArgs([Mockery::any()])->andReturn($fileContent);
- $budgetMapper = $this->mock(Budgets::class);
- $budgetMapper->shouldReceive('getMap')->once()->andReturn($fakeBudgets);
-
-
- $handler = new ConfigureMappingHandler;
- $handler->setImportJob($job);
- try {
- $result = $handler->getNextData();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $expected = [
- 4 => [ // is the one with the budget id, remember?
- 'name' => 'budget-id',
- 'options' => $fakeBudgets,
- 'preProcessMap' => '',
- 'values' => ['column5', 'value5'], // see $fileContent
- ],
- ];
-
- $this->assertEquals($expected, $result);
-
-
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
- */
- public function testGetPreProcessorName(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
-
- $importRepos->shouldReceive('setUser')->once();
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'mapD' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- $combinations = [
- ['role' => 'tags-space', 'expected' => TagsSpace::class], // tags- space has a pre-processor. Return it.
- ['role' => 'description', 'expected' => ''], // description has not.
- ['role' => 'no-such-role', 'expected' => ''], // not existing role has not.
- ];
-
- $handler = new ConfigureMappingHandler;
- $handler->setImportJob($job);
- foreach ($combinations as $info) {
- $this->assertEquals($info['expected'], $handler->getPreProcessorName($info['role']));
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
- */
- public function testGetReader(): void
- {
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'mapF' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // make one attachment.
- $att = new Attachment;
- $att->filename = 'import_file';
- $att->user_id = $this->user()->id;
- $att->attachable_id = $job->id;
- $att->attachable_type = ImportJob::class;
- $att->md5 = md5('hello');
- $att->mime = 'fake';
- $att->size = 3;
- $att->save();
- $config = [
- 'delimiter' => ',',
- ];
-
- $fileContent = "column1,column2,column3\nvalue1,value2,value3";
-
- // mock some helpers:
- $attachments = $this->mock(AttachmentHelperInterface::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('getConfiguration')->once()->withArgs([Mockery::any()])->andReturn($config);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('getAttachments')->once()->withArgs([Mockery::any()])->andReturn(new Collection([$att]));
- $attachments->shouldReceive('getAttachmentContent')->withArgs([Mockery::any()])->andReturn($fileContent);
-
- $handler = new ConfigureMappingHandler;
- $handler->setImportJob($job);
- try {
- $reader = $handler->getReader();
- } catch (Exception $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
- */
- public function testGetValuesForMapping(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
-
- $importRepos->shouldReceive('setUser')->once();
- // create a reader to use in method.
- // 5 columns, of which #4 (index 3) is budget-id
- // 5 columns, of which #5 (index 4) is tags-space
- $file = "value1,value2,value3,1,some tags here\nvalue4,value5,value6,2,more tags there\nvalueX,valueY,valueZ\nA,B,C,,\nd,e,f,1,xxx";
- $reader = Reader::createFromString($file);
-
- // make config for use in method.
- $config = [
- 'has-headers' => false,
- ];
-
- // make column config
- $columnConfig = [
- 3 => [
- 'name' => 'budget-id',
- 'options' => [
- 0 => 'dont map',
- 1 => 'Fake budget A',
- 4 => 'Other fake budget',
- ],
- 'preProcessMap' => '',
- 'values' => [],
- ],
- ];
-
- // expected result
- $expected = [
- 3 => [
- 'name' => 'budget-id',
- 'options' => [
- 0 => 'dont map',
- 1 => 'Fake budget A',
- 4 => 'Other fake budget',
- ],
- 'preProcessMap' => '',
- 'values' => ['1', '2'] // all values from column 3 of "CSV" file, minus double values
- ],
- ];
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'mapB' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- $handler = new ConfigureMappingHandler;
- $handler->setImportJob($job);
- $result = [];
- try {
- $result = $handler->getValuesForMapping($reader, $config, $columnConfig);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals($expected, $result);
-
-
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
- */
- public function testSanitizeColumnName(): void
- {
- $helper = $this->mock(AttachmentHelperInterface::class);
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $importRepos->shouldReceive('setUser')->once();
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'mapB' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- $handler = new ConfigureMappingHandler;
- $handler->setImportJob($job);
- $keys = array_keys(config('csv.import_roles'));
- foreach ($keys as $key) {
- $this->assertEquals($key, $handler->sanitizeColumnName($key));
- }
- $this->assertEquals('_ignore', $handler->sanitizeColumnName('some-bad-name'));
- }
-
-}
diff --git a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureRolesHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/File/ConfigureRolesHandlerTest.php
deleted file mode 100644
index 8a4569338f..0000000000
--- a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureRolesHandlerTest.php
+++ /dev/null
@@ -1,580 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\JobConfiguration\File;
-
-
-use Exception;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
-use FireflyIII\Import\Specifics\IngDescription;
-use FireflyIII\Models\Attachment;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler;
-use Illuminate\Support\Collection;
-use League\Csv\Reader;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class ConfigureRolesHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ConfigureRolesHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
- */
- public function testConfigurationCompleteBasic(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
-
- $config = [
- 'column-count' => 5,
- 'column-roles' => [
- 0 => 'amount',
- 1 => 'description',
- 2 => 'note',
- 3 => 'foreign-currency-code',
- 4 => 'amount_foreign',
- ],
- ];
- $handler = new ConfigureRolesHandler();
- $result = $handler->configurationComplete($config);
- $this->assertCount(0, $result);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
- */
- public function testConfigurationCompleteForeign(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
-
- $config = [
- 'column-count' => 5,
- 'column-roles' => [
- 0 => 'amount',
- 1 => 'description',
- 2 => 'note',
- 3 => 'amount_foreign',
- 4 => 'sepa-cc',
- ],
- ];
- $handler = new ConfigureRolesHandler();
- $result = $handler->configurationComplete($config);
- $this->assertCount(1, $result);
- $this->assertEquals(
- 'If you mark a column as containing an amount in a foreign currency, you must also set the column that contains which currency it is.',
- $result->get('error')[0]
- );
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
- */
- public function testConfigurationCompleteNoAmount(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
- $config = [
- 'column-count' => 5,
- 'column-roles' => [
- 0 => 'sepa-cc',
- 1 => 'description',
- 2 => 'note',
- 3 => 'foreign-currency-code',
- 4 => 'amount_foreign',
- ],
- ];
- $handler = new ConfigureRolesHandler();
- $result = $handler->configurationComplete($config);
- $this->assertCount(1, $result);
- $this->assertEquals(
- 'At the very least, mark one column as the amount-column. It is advisable to also select a column for the description, date and the opposing account.',
- $result->get('error')[0]
- );
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
- */
- public function testConfigureJob(): void
- {
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'role-B' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [
- 'column-count' => 5,
- ];
- $job->save();
-
- $data = [
- 'role' => [
- 0 => 'description',
- 1 => 'budget-id',
- 2 => 'sepa-cc',
- 4 => 'amount', // no column 3.
- ],
- 'map' => [
- 0 => '1', // map column 0 (which cannot be mapped anyway)
- 1 => '1', // map column 1 (which CAN be mapped)
- ],
- ];
-
- $expected = [
- 'column-count' => 5,
- 'column-roles' => [
- 0 => 'description',
- 1 => 'budget-id',
- 2 => 'sepa-cc',
- 3 => '_ignore', // added column 3
- 4 => 'amount',
- ],
- 'column-do-mapping' => [false, true, false, false, false],
- ];
-
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('setStage')->once()->withArgs([Mockery::any(), 'ready_to_run']);
- $repository->shouldReceive('setStage')->once()->withArgs([Mockery::any(), 'map']);
- $repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $expected]);
-
- $handler = new ConfigureRolesHandler();
- $handler->setImportJob($job);
- $handler->configureJob($data);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
- */
- public function testGetExampleFromLine(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
- $lines = [
- ['one', 'two', '', 'three'],
- ['four', 'five', '', 'six'],
- ];
-
- $handler = new ConfigureRolesHandler;
- foreach ($lines as $line) {
- $handler->getExampleFromLine($line);
- }
- $expected = [
- 0 => ['one', 'four'],
- 1 => ['two', 'five'],
- 3 => ['three', 'six'],
- ];
- $this->assertEquals($expected, $handler->getExamples());
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
- */
- public function testGetExamplesFromFile(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
- $importRepos->shouldReceive('setUser')->once();
- $importRepos->shouldReceive('setConfiguration')->once()
- ->withAnyArgs();
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'role-x' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [
- 'specifics' => [],
- 'has-headers' => false,
- ];
- $job->save();
-
- $file = "one,two,,three\nfour,five,,six\none,three,X,three";
- $reader = Reader::createFromString($file);
- $handler = new ConfigureRolesHandler;
- $handler->setImportJob($job);
- try {
- $handler->getExamplesFromFile($reader, $job->configuration);
- } catch (Exception $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- $expected = [
- 0 => ['one', 'four'],
- 1 => ['two', 'five', 'three'],
- 2 => ['X'],
- 3 => ['three', 'six'],
- ];
- $this->assertEquals($expected, $handler->getExamples());
-
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
- */
- public function testGetHeadersHas(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
- //$importRepos->shouldReceive('setUser')->once();
- // create a reader to use in method.
- // 5 columns, of which #4 (index 3) is budget-id
- // 5 columns, of which #5 (index 4) is tags-space
- $file = "header1,header2,header3,header4,header5\nvalue4,value5,value6,2,more tags there\nvalueX,valueY,valueZ\nA,B,C,,\nd,e,f,1,xxx";
- $reader = Reader::createFromString($file);
- $config = ['has-headers' => true];
-
- $handler = new ConfigureRolesHandler;
- try {
- $headers = $handler->getHeaders($reader, $config);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals(['header1', 'header2', 'header3', 'header4', 'header5'], $headers);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
- */
- public function testGetHeadersNone(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
-
- // create a reader to use in method.
- // 5 columns, of which #4 (index 3) is budget-id
- // 5 columns, of which #5 (index 4) is tags-space
- $file = "header1,header2,header3,header4,header5\nvalue4,value5,value6,2,more tags there\nvalueX,valueY,valueZ\nA,B,C,,\nd,e,f,1,xxx";
- $reader = Reader::createFromString($file);
- $config = ['has-headers' => false];
-
- $handler = new ConfigureRolesHandler;
- try {
- $headers = $handler->getHeaders($reader, $config);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals([], $headers);
- }
-
- public function testGetNextData(): void
- {
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'role-x' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [
- 'delimiter' => ',',
- 'has-headers' => true,
- ];
- $job->save();
-
- // make one attachment.
- $att = new Attachment;
- $att->filename = 'import_file';
- $att->user_id = $this->user()->id;
- $att->attachable_id = $job->id;
- $att->attachable_type = ImportJob::class;
- $att->md5 = md5('hello');
- $att->mime = 'fake';
- $att->size = 3;
- $att->save();
-
- $fileContent = "column1,column2,column3\nvalue1,value2,value3";
- // mock some helpers:
- $attachments = $this->mock(AttachmentHelperInterface::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('getConfiguration')->once()->withArgs([Mockery::any()])->andReturn($job->configuration);
- $repository->shouldReceive('setConfiguration')->once()->withArgs(
- [Mockery::any(),
- [
- 'delimiter' => ',',
- 'has-headers' => true,
- 'column-count' => 3,
- ],
- ]
- );
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('getAttachments')->once()->withArgs([Mockery::any()])->andReturn(new Collection([$att]));
- $attachments->shouldReceive('getAttachmentContent')->withArgs([Mockery::any()])->andReturn($fileContent);
-
- $expected = [
- 'examples' => [
- 0 => ['value1'],
- 1 => ['value2'],
- 2 => ['value3'],
- ],
- 'total' => 3,
- 'headers' => ['column1', 'column2', 'column3'],
- ];
-
- $handler = new ConfigureRolesHandler();
- $handler->setImportJob($job);
- try {
- $result = $handler->getNextData();
- } catch (Exception $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals($expected['examples'], $result['examples']);
- $this->assertEquals($expected['total'], $result['total']);
- $this->assertEquals($expected['headers'], $result['headers']);
-
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
- */
- public function testGetReader(): void
- {
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'role-x' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // make one attachment.
- $att = new Attachment;
- $att->filename = 'import_file';
- $att->user_id = $this->user()->id;
- $att->attachable_id = $job->id;
- $att->attachable_type = ImportJob::class;
- $att->md5 = md5('hello');
- $att->mime = 'fake';
- $att->size = 3;
- $att->save();
- $config = [
- 'delimiter' => ',',
- ];
-
- $fileContent = "column1,column2,column3\nvalue1,value2,value3";
-
- // mock some helpers:
- $attachments = $this->mock(AttachmentHelperInterface::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('getConfiguration')->once()->withArgs([Mockery::any()])->andReturn($config);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('getAttachments')->once()->withArgs([Mockery::any()])->andReturn(new Collection([$att]));
- $attachments->shouldReceive('getAttachmentContent')->withArgs([Mockery::any()])->andReturn($fileContent);
-
- $handler = new ConfigureRolesHandler();
- $handler->setImportJob($job);
- try {
- $reader = $handler->getReader();
- } catch (Exception $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
- */
- public function testIgnoreUnmappableColumns(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
- $config = [
- 'column-count' => 5,
- 'column-roles' => [
- 'description', // cannot be mapped.
- 'budget-id',
- 'sepa-cc', // cannot be mapped.
- 'category-id',
- 'tags-comma', // cannot be mapped.
- ],
- 'column-do-mapping' => [
- 0 => true,
- 1 => true,
- 2 => true,
- 3 => true,
- 4 => true,
- ],
- ];
- $expected = [
- 'column-count' => 5,
- 'column-roles' => [
- 'description', // cannot be mapped.
- 'budget-id',
- 'sepa-cc', // cannot be mapped.
- 'category-id',
- 'tags-comma', // cannot be mapped.
- ],
- 'column-do-mapping' => [
- 0 => false,
- 1 => true,
- 2 => false,
- 3 => true,
- 4 => false,
- ],
- ];
- $handler = new ConfigureRolesHandler;
- $this->assertEquals($expected, $handler->ignoreUnmappableColumns($config));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
- */
- public function testIsMappingNecessaryNo(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
-
- $config = [
- 'column-do-mapping' => [false, false, false],
- ];
- $handler = new ConfigureRolesHandler();
- $result = $handler->isMappingNecessary($config);
- $this->assertFalse($result);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
- */
- public function testIsMappingNecessaryYes(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
-
- $config = [
- 'column-do-mapping' => [false, true, false, false],
- ];
- $handler = new ConfigureRolesHandler();
- $result = $handler->isMappingNecessary($config);
- $this->assertTrue($result);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
- */
- public function testMakeExamplesUnique(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
-
- $lines = [
- ['one', 'two', '', 'three'],
- ['four', 'five', '', 'six'],
- ['one', 'three', 'X', 'three'],
- ];
-
- $handler = new ConfigureRolesHandler;
- foreach ($lines as $line) {
- $handler->getExampleFromLine($line);
- }
- $handler->makeExamplesUnique();
-
- $expected = [
- 0 => ['one', 'four'],
- 1 => ['two', 'five', 'three'],
- 2 => ['X'],
- 3 => ['three', 'six'],
- ];
- $this->assertEquals($expected, $handler->getExamples());
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
- */
- public function testProcessSpecifics(): void
- {
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
-
- $line = [];
- $config = [
- 'specifics' => [
- 'IngDescription' => true,
- 'some-bad-specific' => true,
- ],
- ];
-
- $ingDescription = $this->mock(IngDescription::class);
- $ingDescription->shouldReceive('run')->once()->withArgs([[]])->andReturn(['a' => 'b']);
-
- $handler = new ConfigureRolesHandler;
- $this->assertEquals(['a' => 'b'], $handler->processSpecifics($config, []));
-
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
- */
- public function testSaveColumCount(): void
- {
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'role-A' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $helper = $this->mock(AttachmentHelperInterface::class);
-
- $repository->shouldReceive('setUser');
- $repository->shouldReceive('setConfiguration')->once()
- ->withArgs([Mockery::any(), ['column-count' => 0]]);
-
- $handler = new ConfigureRolesHandler();
- $handler->setImportJob($job);
- $handler->saveColumCount();
- }
-
-}
diff --git a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureUploadHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/File/ConfigureUploadHandlerTest.php
deleted file mode 100644
index d8503747d2..0000000000
--- a/tests/Unit/Support/Import/JobConfiguration/File/ConfigureUploadHandlerTest.php
+++ /dev/null
@@ -1,202 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\JobConfiguration\File;
-
-
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Support\Import\JobConfiguration\File\ConfigureUploadHandler;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class ConfigureUploadHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ConfigureUploadHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureUploadHandler
- */
- public function testConfigureJobAccount(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'upload-B' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
-
- $data = [
- 'csv_import_account' => '1',
- 'csv_delimiter' => ',',
- 'has_headers' => '1',
- 'date_format' => 'Y-m-d',
- 'apply_rules' => '1',
- 'specifics' => ['IngDescription'],
- ];
- $expectedConfig = [
- 'has-headers' => true,
- 'date-format' => 'Y-m-d',
- 'delimiter' => ',',
- 'apply-rules' => true,
- 'specifics' => [
- 'IngDescription' => 1,
- ],
- 'import-account' => 1,
- ];
-
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('findNull')->once()->withArgs([1])->andReturn($this->user()->accounts()->first());
- $repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $expectedConfig]);
- $repository->shouldReceive('setStage')->once()->withArgs([Mockery::any(), 'roles']);
-
- $handler = new ConfigureUploadHandler;
- $handler->setImportJob($job);
- $result = $handler->configureJob($data);
- $this->assertCount(0, $result);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureUploadHandler
- */
- public function testConfigureJobNoAccount(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'upload-B' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
-
- $data = [
- 'csv_import_account' => '1',
- 'csv_delimiter' => ',',
- 'has_headers' => '1',
- 'date_format' => 'Y-m-d',
- 'apply_rules' => '1',
- 'specifics' => ['IngDescription'],
- ];
- $expectedConfig = [
- 'has-headers' => true,
- 'date-format' => 'Y-m-d',
- 'delimiter' => ',',
- 'apply-rules' => true,
- 'specifics' => [
- 'IngDescription' => 1,
- ],
- ];
-
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('findNull')->once()->withArgs([1])->andReturn(null);
- $repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $expectedConfig]);
-
- $handler = new ConfigureUploadHandler;
- $handler->setImportJob($job);
- $result = $handler->configureJob($data);
- $this->assertCount(1, $result);
- $this->assertEquals('You have selected an invalid account to import into.', $result->get('account')[0]);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureUploadHandler
- */
- public function testGetNextData(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'upload-A' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser');
- $accountRepos->shouldReceive('setUser');
- $repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), ['date-format' => 'Ymd']]);
-
- $handler = new ConfigureUploadHandler;
- $handler->setImportJob($job);
- $result = $handler->getNextData();
- $expected = [
- 'accounts' => [],
- 'delimiters' => [],
- ];
- // not much to compare, really.
- $this->assertEquals($expected['accounts'], $result['accounts']);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureUploadHandler
- */
- public function testGetSpecifics(): void
- {
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $array = [
- 'specifics' => [
- 'IngDescription', 'BadFakeNewsThing',
- ],
- ];
- $expected = [
- 'IngDescription' => 1,
- ];
-
- $handler = new ConfigureUploadHandler;
- $result = $handler->getSpecifics($array);
- $this->assertEquals($expected, $result);
- }
-
-}
diff --git a/tests/Unit/Support/Import/JobConfiguration/File/NewFileJobHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/File/NewFileJobHandlerTest.php
deleted file mode 100644
index 9fa5673146..0000000000
--- a/tests/Unit/Support/Import/JobConfiguration/File/NewFileJobHandlerTest.php
+++ /dev/null
@@ -1,318 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\JobConfiguration\File;
-
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
-use FireflyIII\Models\Attachment;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Support\Import\JobConfiguration\File\NewFileJobHandler;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class NewFileJobHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class NewFileJobHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\NewFileJobHandler
- */
- public function testConfigureJob(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'newfile-A' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [
- 'delimiter' => ',',
- 'has-headers' => true,
- ];
- $job->save();
-
- // make one attachment.
- $att = new Attachment;
- $att->filename = 'configuration_file';
- $att->user_id = $this->user()->id;
- $att->attachable_id = $job->id;
- $att->attachable_type = ImportJob::class;
- $att->md5 = md5('hello');
- $att->mime = 'fake';
- $att->size = 3;
- $att->save();
-
- // mock stuff
- $attachments = $this->mock(AttachmentHelperInterface::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('getConfiguration')->andReturn([])->once();
- $repository->shouldReceive('getAttachments')->twice()->andReturn(new Collection([$att]));
- $attachments->shouldReceive('getAttachmentContent')->times(3)->andReturn('{"a": "b"}');
- $repository->shouldReceive('setConfiguration')->withArgs([Mockery::any(), ['file-type' => 'csv']])->once();
- $repository->shouldReceive('setConfiguration')->withArgs([Mockery::any(), ['a' => 'b']])->twice();
- $repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'configure-upload'])->once();
-
- // data for configure job:
- $data = [
- 'import_file_type' => 'csv',
- ];
-
- $handler = new NewFileJobHandler;
- $handler->setImportJob($job);
- try {
- $messages = $handler->configureJob($data);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $messages);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\NewFileJobHandler
- */
- public function testConfigureJobBadData(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'newfile-A' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [
- 'delimiter' => ',',
- 'has-headers' => true,
- ];
- $job->save();
-
- // make one attachment.
- $att = new Attachment;
- $att->filename = 'configuration_file';
- $att->user_id = $this->user()->id;
- $att->attachable_id = $job->id;
- $att->attachable_type = ImportJob::class;
- $att->md5 = md5('hello');
- $att->mime = 'fake';
- $att->size = 3;
- $att->save();
-
- // get file:
- $content = file_get_contents(storage_path('build') . '/ebcdic.txt');
-
- // mock stuff
- $attachments = $this->mock(AttachmentHelperInterface::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('getAttachments')->once()->andReturn(new Collection([$att]));
- $attachments->shouldReceive('getAttachmentContent')->once()->andReturn($content);
-
- // data for configure job:
- $data = [
- 'import_file_type' => 'csv',
- ];
-
- $handler = new NewFileJobHandler;
- $handler->setImportJob($job);
- try {
- $messages = $handler->configureJob($data);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(1, $messages);
- $this->assertEquals(
- 'The file you have uploaded is not encoded as UTF-8 or ASCII. Firefly III cannot handle such files. Please use Notepad++ or Sublime to convert your file to UTF-8.',
- $messages->first()
- );
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\NewFileJobHandler
- */
- public function testStoreConfiguration(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'newfile-A' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [
- 'delimiter' => ',',
- 'has-headers' => true,
- ];
- $job->save();
-
- // make one attachment.
- $att = new Attachment;
- $att->filename = 'configuration_file';
- $att->user_id = $this->user()->id;
- $att->attachable_id = $job->id;
- $att->attachable_type = ImportJob::class;
- $att->md5 = md5('hello');
- $att->mime = 'fake';
- $att->size = 3;
- $att->save();
-
- // mock stuff
- $attachments = $this->mock(AttachmentHelperInterface::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('getAttachments')->once()->andReturn(new Collection([$att]));
- $attachments->shouldReceive('getAttachmentContent')->once()->andReturn('{"a": "b"}');
- $repository->shouldReceive('setConfiguration')->withArgs([Mockery::any(), ['a' => 'b']])->once();
-
- $handler = new NewFileJobHandler;
- $handler->setImportJob($job);
-
- try {
- $handler->storeConfiguration();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\NewFileJobHandler
- */
- public function testValidateAttachments(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'newfile-x' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [
- 'delimiter' => ',',
- 'has-headers' => true,
- ];
- $job->save();
-
- // make one attachment.
- $att = new Attachment;
- $att->filename = 'import_file';
- $att->user_id = $this->user()->id;
- $att->attachable_id = $job->id;
- $att->attachable_type = ImportJob::class;
- $att->md5 = md5('hello');
- $att->mime = 'fake';
- $att->size = 3;
- $att->save();
-
- // mock stuff
- $attachments = $this->mock(AttachmentHelperInterface::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('getAttachments')->andReturn(new Collection([$att]));
- $attachments->shouldReceive('getAttachmentContent')->once()->andReturn('Hello!');
-
-
- $handler = new NewFileJobHandler;
- $handler->setImportJob($job);
-
- try {
- $result = $handler->validateAttachments();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(0, $result);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\File\NewFileJobHandler
- */
- public function testValidateNotUTF(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'newfile-x' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [
- 'delimiter' => ',',
- 'has-headers' => true,
- ];
- $job->save();
-
- // make one attachment.
- $att = new Attachment;
- $att->filename = 'import_file';
- $att->user_id = $this->user()->id;
- $att->attachable_id = $job->id;
- $att->attachable_type = ImportJob::class;
- $att->md5 = md5('hello');
- $att->mime = 'fake';
- $att->size = 3;
- $att->save();
-
- // get file:
- $content = file_get_contents(storage_path('build') . '/ebcdic.txt');
-
- // mock stuff
- $attachments = $this->mock(AttachmentHelperInterface::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('getAttachments')->andReturn(new Collection([$att]));
- $attachments->shouldReceive('getAttachmentContent')->once()->andReturn($content);
-
-
- $handler = new NewFileJobHandler;
- $handler->setImportJob($job);
-
- try {
- $result = $handler->validateAttachments();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(1, $result);
- $this->assertEquals(
- 'The file you have uploaded is not encoded as UTF-8 or ASCII. Firefly III cannot handle such files. Please use Notepad++ or Sublime to convert your file to UTF-8.',
- $result->first()
- );
- }
-
-}
diff --git a/tests/Unit/Support/Import/JobConfiguration/Spectre/ChooseAccountsHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/Spectre/ChooseAccountsHandlerTest.php
deleted file mode 100644
index ed614e27ec..0000000000
--- a/tests/Unit/Support/Import/JobConfiguration/Spectre/ChooseAccountsHandlerTest.php
+++ /dev/null
@@ -1,672 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\JobConfiguration\Spectre;
-
-
-use Amount;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Services\Spectre\Object\Account as SpectreAccount;
-use FireflyIII\Services\Spectre\Object\Attempt;
-use FireflyIII\Services\Spectre\Object\Holder;
-use FireflyIII\Services\Spectre\Object\Login;
-use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccountsHandler;
-use Illuminate\Support\Collection;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class ChooseAccountsHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ChooseAccountsHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccountsHandler
- */
- public function testCCFalse(): void
- {
- // fake job:
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sca-A' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [
- 'account_mapping' => [],
- ];
- $job->save();
-
- // mock repositories:
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
-
- // mock calls:
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
- $importRepos->shouldReceive('setUser')->once();
-
- // call handler:
- $handler = new ChooseAccountsHandler();
- $handler->setImportJob($job);
- $this->assertFalse($handler->configurationComplete());
-
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccountsHandler
- */
- public function testCCTrue(): void
- {
- // fake job:
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sca-B' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [
- 'account_mapping' => [
- 4 => 6,
- ],
- ];
- $job->save();
-
- // mock repositories:
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
-
- // mock calls:
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
- $importRepos->shouldReceive('setUser')->once();
- $importRepos->shouldReceive('setStage')->withArgs([Mockery::any(), 'go-for-import'])->once();
-
- // call handler:
- $handler = new ChooseAccountsHandler();
- $handler->setImportJob($job);
- $this->assertTrue($handler->configurationComplete());
- }
-
- /**
- * Case: Local account is valid. Spectre account is valid.
- *
- * @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccountsHandler
- */
- public function testConfigureJob(): void
- {
- // fake job:
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sca-c' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [
- 'accounts' => [
- 0 => [
- 'id' => 3131,
- 'name' => 'Some fake account',
- ],
- ],
- ];
- $job->save();
-
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- // data to submit:
- $data = [
- 'account_mapping' => [3131 => 872,],
- 'apply_rules' => true,
- ];
- // expected configuration:
- $config = [
- 'accounts' => [0 => ['id' => 3131, 'name' => 'Some fake account',],],
- 'account_mapping' => [3131 => 872,],
- 'apply-rules' => true,
- ];
-
-
- // mock repositories:
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
-
- // mock calls:
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
- $importRepos->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('findNull')->once()->withArgs([872])->andReturn($account);
- $importRepos->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $config]);
-
-
- // call handler:
- $handler = new ChooseAccountsHandler();
- $handler->setImportJob($job);
- $this->assertCount(0, $handler->configureJob($data));
- }
-
- /**
- * Case: Local account is invalid. Spectre account is invalid.
- *
- * @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccountsHandler
- */
- public function testConfigureJobInvalidBoth(): void
- {
- // fake job:
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sca-E' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [
- 'accounts' => [
- 0 => [
- 'id' => 3134,
- 'name' => 'Some fake account',
- ],
- ],
- ];
- $job->save();
-
- // data to submit:
- $data = [
- 'account_mapping' => [3131 => 872,],
- 'apply_rules' => true,
- ];
- // expected configuration:
- $config = [
- 'accounts' => [0 => ['id' => 3134, 'name' => 'Some fake account',],],
- 'account_mapping' => [0 => 0,],
- 'apply-rules' => true,
- ];
-
-
- // mock repositories:
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
-
- // mock calls:
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
- $importRepos->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('findNull')->once()->withArgs([872])->andReturn(null);
- $importRepos->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $config]);
-
-
- // call handler:
- $handler = new ChooseAccountsHandler();
- $handler->setImportJob($job);
- $result = $handler->configureJob($data);
- $this->assertCount(1, $result);
- $this->assertEquals('It seems you have not selected any accounts to import from.', $result->first());
- }
-
- /**
- * Case: Local account is invalid. Spectre account is valid.
- *
- * @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccountsHandler
- */
- public function testConfigureJobInvalidLocal(): void
- {
- // fake job:
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sca-D' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [
- 'accounts' => [
- 0 => [
- 'id' => 3131,
- 'name' => 'Some fake account',
- ],
- ],
- ];
- $job->save();
-
- // data to submit:
- $data = [
- 'account_mapping' => [3131 => 872,],
- 'apply_rules' => true,
- ];
- // expected configuration:
- $config = [
- 'accounts' => [0 => ['id' => 3131, 'name' => 'Some fake account',],],
- 'account_mapping' => [3131 => 0,],
- 'apply-rules' => true,
- ];
-
-
- // mock repositories:
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
-
- // mock calls:
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
- $importRepos->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('findNull')->once()->withArgs([872])->andReturn(null);
- $importRepos->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $config]);
-
-
- // call handler:
- $handler = new ChooseAccountsHandler();
- $handler->setImportJob($job);
- $this->assertCount(0, $handler->configureJob($data));
- }
-
- /**
- * Case: Local account is valid. Spectre account is invalid.
- *
- * @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccountsHandler
- */
- public function testConfigureJobInvalidSpectre(): void
- {
- // fake job:
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sca-E' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [
- 'accounts' => [
- 0 => [
- 'id' => 3134,
- 'name' => 'Some fake account',
- ],
- ],
- ];
- $job->save();
-
- $account = $this->user()->accounts()->inRandomOrder()->first();
-
- // data to submit:
- $data = [
- 'account_mapping' => [3131 => 872,],
- 'apply_rules' => true,
- ];
- // expected configuration:
- $config = [
- 'accounts' => [0 => ['id' => 3134, 'name' => 'Some fake account',],],
- 'account_mapping' => [0 => 872,],
- 'apply-rules' => true,
- ];
-
-
- // mock repositories:
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
-
- // mock calls:
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
- $importRepos->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('findNull')->once()->withArgs([872])->andReturn($account);
- $importRepos->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $config]);
-
-
- // call handler:
- $handler = new ChooseAccountsHandler();
- $handler->setImportJob($job);
- $this->assertCount(0, $handler->configureJob($data));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccountsHandler
- */
- public function testGetNextData(): void
- {
- // needs to be a full spectre account this time.
- $spectreAccount = [
- 'id' => 1234,
- 'login_id' => 5678,
- 'currency_code' => 'EUR',
- 'balance' => 1000,
- 'name' => 'Fake Spectre Account',
- 'nature' => 'account',
- 'created_at' => '2018-01-01 12:12:12',
- 'updated_at' => '2018-01-01 12:12:12',
- 'extra' => [],
- ];
-
-
- // need to be a full spectre login this time.
- $holder = new Holder([]);
- $attempt = new Attempt(
- [
- 'api_mode' => 'x',
- 'api_version' => 4,
- 'automatic_fetch' => true,
- 'categorize' => true,
- 'created_at' => '2018-05-21 12:00:00',
- 'consent_given_at' => '2018-05-21 12:00:00',
- 'consent_types' => ['transactions'],
- 'custom_fields' => [],
- 'daily_refresh' => true,
- 'device_type' => 'mobile',
- 'user_agent' => 'Mozilla/x',
- 'remote_ip' => '127.0.0.1',
- 'exclude_accounts' => [],
- 'fail_at' => '2018-05-21 12:00:00',
- 'fail_error_class' => 'err',
- 'fail_message' => 'message',
- 'fetch_scopes' => [],
- 'finished' => true,
- 'finished_recent' => true,
- 'from_date' => '2018-05-21 12:00:00',
- 'id' => 1,
- 'interactive' => true,
- 'locale' => 'en',
- 'partial' => true,
- 'show_consent_confirmation' => true,
- 'stages' => [],
- 'store_credentials' => true,
- 'success_at' => '2018-05-21 12:00:00',
- 'to_date' => '2018-05-21 12:00:00',
- 'updated_at' => '2018-05-21 12:00:00',
- ]
- );
- $spectreLogin = new Login(
- [
- 'consent_given_at' => '2018-05-21 12:00:00',
- 'consent_types' => ['transactions'],
- 'country_code' => 'NL',
- 'created_at' => '2018-05-21 12:00:00',
- 'updated_at' => '2018-05-21 12:00:00',
- 'customer_id' => '1',
- 'daily_refresh' => true,
- 'holder_info' => $holder->toArray(),
- 'id' => 1234,
- 'last_attempt' => $attempt->toArray(),
- 'last_success_at' => '2018-05-21 12:00:00',
- 'next_refresh_possible_at' => '2018-05-21 12:00:00',
- 'provider_code' => 'XF',
- 'provider_id' => '123',
- 'provider_name' => 'Fake',
- 'show_consent_confirmation' => true,
- 'status' => 'active',
- 'store_credentials' => true,
- ]
- );
-
- // fake job:
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sca-F' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [
- 'accounts' => [
- 0 => $spectreAccount,
- ],
- 'all-logins' => [
- 0 => $spectreLogin->toArray(),
- ],
- 'selected-login' => 1234,
- ];
- $job->save();
-
- // mock repositories:
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
-
- // mock calls:
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
- $importRepos->shouldReceive('setUser')->once();
-
- $euro = $this->getEuro();
- $usd = $this->getDollar();
- $first = $this->user()->accounts()->where('account_type_id', 3)->first();
- $second = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $first->id)->first();
- $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE]])
- ->once()->andReturn(new Collection([$first, $second]));
- $accountRepos->shouldReceive('getMetaValue')->twice()->withArgs([Mockery::any(), 'currency_id'])
- ->andReturn(1, 2);
- $currencyRepos->shouldReceive('findNull')->once()->withArgs([1])->andReturn($euro);
- $currencyRepos->shouldReceive('findNull')->once()->withArgs([2])->andReturn(null);
- Amount::shouldReceive('getDefaultCurrencyByUser')->withArgs([Mockery::any()])->once()->andReturn($usd);
-
- // call handler:
- $handler = new ChooseAccountsHandler();
- $handler->setImportJob($job);
- $result = [];
- try {
- $result = $handler->getNextData();
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
-
- $expected = [
- 'accounts' => [
- 0 => new SpectreAccount($spectreAccount),
- ],
- 'ff_accounts' => [
- $first->id => [
- 'name' => $first->name,
- 'iban' => $first->iban,
- 'code' => $euro->code,
- ],
- $second->id => [
- 'name' => $second->name,
- 'iban' => $second->iban,
- 'code' => $usd->code,
- ],
- ],
- 'login' => $spectreLogin,
- ];
-
- $this->assertEquals($expected, $result);
- }
-
- /**
- * Select first login.
- *
- * @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccountsHandler
- */
- public function testGetNextDataZero(): void
- {
- // needs to be a full spectre account this time.
- $spectreAccount = [
- 'id' => 1234,
- 'login_id' => 5678,
- 'currency_code' => 'EUR',
- 'balance' => 1000,
- 'name' => 'Fake Spectre Account',
- 'nature' => 'account',
- 'created_at' => '2018-01-01 12:12:12',
- 'updated_at' => '2018-01-01 12:12:12',
- 'extra' => [],
- ];
-
-
- // need to be a full spectre login this time.
- $holder = new Holder([]);
- $attempt = new Attempt(
- [
- 'api_mode' => 'x',
- 'api_version' => 4,
- 'automatic_fetch' => true,
- 'categorize' => true,
- 'created_at' => '2018-05-21 12:00:00',
- 'consent_given_at' => '2018-05-21 12:00:00',
- 'consent_types' => ['transactions'],
- 'custom_fields' => [],
- 'daily_refresh' => true,
- 'device_type' => 'mobile',
- 'user_agent' => 'Mozilla/x',
- 'remote_ip' => '127.0.0.1',
- 'exclude_accounts' => [],
- 'fail_at' => '2018-05-21 12:00:00',
- 'fail_error_class' => 'err',
- 'fail_message' => 'message',
- 'fetch_scopes' => [],
- 'finished' => true,
- 'finished_recent' => true,
- 'from_date' => '2018-05-21 12:00:00',
- 'id' => 1,
- 'interactive' => true,
- 'locale' => 'en',
- 'partial' => true,
- 'show_consent_confirmation' => true,
- 'stages' => [],
- 'store_credentials' => true,
- 'success_at' => '2018-05-21 12:00:00',
- 'to_date' => '2018-05-21 12:00:00',
- 'updated_at' => '2018-05-21 12:00:00',
- ]
- );
- $spectreLogin = new Login(
- [
- 'consent_given_at' => '2018-05-21 12:00:00',
- 'consent_types' => ['transactions'],
- 'country_code' => 'NL',
- 'created_at' => '2018-05-21 12:00:00',
- 'updated_at' => '2018-05-21 12:00:00',
- 'customer_id' => '1',
- 'daily_refresh' => true,
- 'holder_info' => $holder->toArray(),
- 'id' => 1234,
- 'last_attempt' => $attempt->toArray(),
- 'last_success_at' => '2018-05-21 12:00:00',
- 'next_refresh_possible_at' => '2018-05-21 12:00:00',
- 'provider_code' => 'XF',
- 'provider_id' => '123',
- 'provider_name' => 'Fake',
- 'show_consent_confirmation' => true,
- 'status' => 'active',
- 'store_credentials' => true,
- ]
- );
-
- // fake job:
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sca-F' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [
- 'accounts' => [
- 0 => $spectreAccount,
- ],
- 'all-logins' => [
- 0 => $spectreLogin->toArray(),
- ],
- 'selected-login' => 0,
- ];
- $job->save();
-
- // mock repositories:
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
-
- // mock calls:
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
- $importRepos->shouldReceive('setUser')->once();
-
- $euro = $this->getEuro();
- $usd = $this->getDollar();
- $first = $this->user()->accounts()->where('account_type_id', 3)->first();
- $second = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $first->id)->first();
- $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE]])
- ->once()->andReturn(new Collection([$first, $second]));
- $accountRepos->shouldReceive('getMetaValue')->twice()->withArgs([Mockery::any(), 'currency_id'])
- ->andReturn(1, 2);
- $currencyRepos->shouldReceive('findNull')->once()->withArgs([1])->andReturn($euro);
- $currencyRepos->shouldReceive('findNull')->once()->withArgs([2])->andReturn(null);
- Amount::shouldReceive('getDefaultCurrencyByUser')->withArgs([Mockery::any()])->once()->andReturn($usd);
-
- // call handler:
- $handler = new ChooseAccountsHandler();
- $handler->setImportJob($job);
- $result = [];
- try {
- $result = $handler->getNextData();
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
-
- $expected = [
- 'accounts' => [
- 0 => new SpectreAccount($spectreAccount),
- ],
- 'ff_accounts' => [
- $first->id => [
- 'name' => $first->name,
- 'iban' => $first->iban,
- 'code' => $euro->code,
- ],
- $second->id => [
- 'name' => $second->name,
- 'iban' => $second->iban,
- 'code' => $usd->code,
- ],
- ],
- 'login' => $spectreLogin,
- ];
-
- $this->assertEquals($expected, $result);
- }
-
-}
diff --git a/tests/Unit/Support/Import/JobConfiguration/Spectre/ChooseLoginHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/Spectre/ChooseLoginHandlerTest.php
deleted file mode 100644
index 9e3fa57db4..0000000000
--- a/tests/Unit/Support/Import/JobConfiguration/Spectre/ChooseLoginHandlerTest.php
+++ /dev/null
@@ -1,290 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\JobConfiguration\Spectre;
-
-
-use Carbon\Carbon;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Services\Spectre\Object\Attempt;
-use FireflyIII\Services\Spectre\Object\Holder;
-use FireflyIII\Services\Spectre\Object\Login;
-use FireflyIII\Services\Spectre\Object\Token;
-use FireflyIII\Services\Spectre\Request\CreateTokenRequest;
-use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseLoginHandler;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class ChooseLoginHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ChooseLoginHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseLoginHandler
- */
- public function testCCFalse(): void
- {
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'slh-A' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
-
- $handler = new ChooseLoginHandler;
- $handler->setImportJob($job);
- $this->assertFalse($handler->configurationComplete());
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseLoginHandler
- */
- public function testCCTrue(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'slh-B' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = ['selected-login' => 1,];
- $job->save();
-
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
-
- $handler = new ChooseLoginHandler;
- $handler->setImportJob($job);
- $this->assertTrue($handler->configurationComplete());
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseLoginHandler
- */
- public function testConfigureJob(): void
- {
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'slh-C' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
- $data = [
- 'spectre_login_id' => 12,
- ];
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('setConfiguration')->withArgs([Mockery::any(), ['selected-login' => 12],])->once();
- $repository->shouldReceive('setStage')->once()->withArgs([Mockery::any(), 'authenticated']);
-
- $handler = new ChooseLoginHandler;
- $handler->setImportJob($job);
- try {
- $this->assertCount(0, $handler->configureJob($data));
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseLoginHandler
- */
- public function testConfigureJobCustomer(): void
- {
- // fake Spectre customer:
- $fakePref = new Preference;
- $fakePref->name = 'spectre_customer';
- $fakePref->data = [
- 'id' => 1,
- 'identifier' => 'fake',
- 'secret' => 'Dumbledore dies',
- ];
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'slh-C' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
- $data = [
- 'spectre_login_id' => 0,
- ];
- $carbon = new Carbon();
- $token = new Token(['token' => 'x', 'expires_at' => $carbon->toW3cString(), 'connect_url' => 'https://']);
-
- // should try to grab customer from preferences:
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'spectre_customer', null])
- ->andReturn($fakePref)->once();
-
- // mock stuff
- $ctRequest = $this->mock(CreateTokenRequest::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
-
- // mock calls
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), ['selected-login' => 0,]]);
- $repository->shouldReceive('setStage')->once()->withArgs([Mockery::any(), 'do-authenticate']);
- $repository->shouldReceive('setConfiguration')->once()->withArgs(
- [Mockery::any(),
- [
- 'selected-login' => 0,
- 'customer' => ['id' => 1, 'identifier' => 'fake', 'secret' => 'Dumbledore dies',],
- 'token' => ['token' => 'x', 'expires_at' => $carbon->toW3cString(), 'connect_url' => 'https://'],
- ]]
- );
-
- // should try to grab token from Spectre:
- $ctRequest->shouldReceive('setUser')->once();
- $ctRequest->shouldReceive('setCustomer')->once();
- $ctRequest->shouldReceive('setUri')->once()->withArgs([route('import.job.status.index', [$job->key])]);
- $ctRequest->shouldReceive('call')->once();
- $ctRequest->shouldReceive('getToken')->once()->andReturn($token);
-
-
- $handler = new ChooseLoginHandler;
- $handler->setImportJob($job);
- try {
- $this->assertCount(0, $handler->configureJob($data));
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
-
- }
-
- /**
- * @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseLoginHandler
- */
- public function testGetNextData(): void
- {
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- // fake login:
- $holder = new Holder([]);
- $attempt = new Attempt(
- [
- 'api_mode' => 'x',
- 'api_version' => 4,
- 'automatic_fetch' => true,
- 'categorize' => true,
- 'created_at' => '2018-05-21 12:00:00',
- 'consent_given_at' => '2018-05-21 12:00:00',
- 'consent_types' => ['transactions'],
- 'custom_fields' => [],
- 'daily_refresh' => true,
- 'device_type' => 'mobile',
- 'user_agent' => 'Mozilla/x',
- 'remote_ip' => '127.0.0.1',
- 'exclude_accounts' => [],
- 'fail_at' => '2018-05-21 12:00:00',
- 'fail_error_class' => 'err',
- 'fail_message' => 'message',
- 'fetch_scopes' => [],
- 'finished' => true,
- 'finished_recent' => true,
- 'from_date' => '2018-05-21 12:00:00',
- 'id' => 1,
- 'interactive' => true,
- 'locale' => 'en',
- 'partial' => true,
- 'show_consent_confirmation' => true,
- 'stages' => [],
- 'store_credentials' => true,
- 'success_at' => '2018-05-21 12:00:00',
- 'to_date' => '2018-05-21 12:00:00',
- 'updated_at' => '2018-05-21 12:00:00',
- ]
- );
- $login = new Login(
- [
- 'consent_given_at' => '2018-05-21 12:00:00',
- 'consent_types' => ['transactions'],
- 'country_code' => 'NL',
- 'created_at' => '2018-05-21 12:00:00',
- 'updated_at' => '2018-05-21 12:00:00',
- 'customer_id' => '1',
- 'daily_refresh' => true,
- 'holder_info' => $holder->toArray(),
- 'id' => 123,
- 'last_attempt' => $attempt->toArray(),
- 'last_success_at' => '2018-05-21 12:00:00',
- 'next_refresh_possible_at' => '2018-05-21 12:00:00',
- 'provider_code' => 'XF',
- 'provider_id' => '123',
- 'provider_name' => 'Fake',
- 'show_consent_confirmation' => true,
- 'status' => 'active',
- 'store_credentials' => true,
- ]
- );
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'slh-C' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [
- 'all-logins' => [$login->toArray()],
- ];
- $job->save();
-
- $handler = new ChooseLoginHandler;
- $handler->setImportJob($job);
- $this->assertEquals(['logins' => [$login]], $handler->getNextData());
- }
-
-}
diff --git a/tests/Unit/Support/Import/JobConfiguration/Spectre/DoAuthenticateHandlerTest.php b/tests/Unit/Support/Import/JobConfiguration/Spectre/DoAuthenticateHandlerTest.php
deleted file mode 100644
index a7ab2dc172..0000000000
--- a/tests/Unit/Support/Import/JobConfiguration/Spectre/DoAuthenticateHandlerTest.php
+++ /dev/null
@@ -1,120 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\JobConfiguration\Spectre;
-
-
-use Carbon\Carbon;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Services\Spectre\Object\Token;
-use FireflyIII\Services\Spectre\Request\CreateTokenRequest;
-use FireflyIII\Support\Import\JobConfiguration\Spectre\DoAuthenticateHandler;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class DoAuthenticateHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class DoAuthenticateHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * No token in config, but grab it from users preferences.
- *
- * @covers \FireflyIII\Support\Import\Information\GetSpectreTokenTrait
- * @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\DoAuthenticateHandler
- */
- public function testGetNextDataNoToken(): void
- {
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sda-A' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // mock stuff:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'ready_to_run']);
- $repository->shouldReceive('setStage')->once()->withArgs([Mockery::any(), 'authenticated']);
-
- // mock request for a new Token:
- $ctRequest = $this->mock(CreateTokenRequest::class);
-
- // fake token:
- $carbon = new Carbon();
- $token = new Token(['token' => 'x', 'expires_at' => $carbon->toW3cString(), 'connect_url' => 'https://']);
-
- // fake Spectre customer:
- $fakeCustomerPreference = new Preference;
- $fakeCustomerPreference->name = 'spectre_customer';
- $fakeCustomerPreference->data = [
- 'id' => 1,
- 'identifier' => 'fake',
- 'secret' => 'Dumbledore dies',
- ];
-
- // should try to grab customer from preferences:
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'spectre_customer', null])
- ->andReturn($fakeCustomerPreference)->once();
-
- // should try to grab token from Spectre:
- $ctRequest->shouldReceive('setUser')->once();
- $ctRequest->shouldReceive('setCustomer')->once();
- $ctRequest->shouldReceive('setUri')->once()->withArgs([route('import.job.status.index', [$job->key])]);
- $ctRequest->shouldReceive('call')->once();
- $ctRequest->shouldReceive('getToken')->once()->andReturn($token);
-
- $handler = new DoAuthenticateHandler;
- $handler->setImportJob($job);
- $result = [];
- try {
- $result = $handler->getNextData();
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- $this->assertEquals(['token-url' => $token->getConnectUrl()], $result);
- }
-
-}
diff --git a/tests/Unit/Support/Import/Placeholder/ImportTransactionTest.php b/tests/Unit/Support/Import/Placeholder/ImportTransactionTest.php
deleted file mode 100644
index 1c29040488..0000000000
--- a/tests/Unit/Support/Import/Placeholder/ImportTransactionTest.php
+++ /dev/null
@@ -1,796 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\Placeholder;
-
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Support\Import\Placeholder\ColumnValue;
-use FireflyIII\Support\Import\Placeholder\ImportTransaction;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class ImportTransactionTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- * @SuppressWarnings(PHPMD.TooManyMethods)
- * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
- */
-class ImportTransactionTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Test what happens when you set the account-id using a ColumnValue.
- * Since this field can be mapped. Test with both the mapped and unmapped variant.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testACVAccountIdMapped(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('account-id');
- $columnValue->setOriginalRole('account-name');
- $columnValue->setValue('Checking Account');
- $columnValue->setMappedValue(1);
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals(0, $importTransaction->accountId);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals($columnValue->getMappedValue(), $importTransaction->accountId);
- }
-
- /**
- * Test what happens when you set the account-id using a ColumnValue.
- * Since this field can be mapped. Test with both the mapped and unmapped variant.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testACVAccountIdUnmapped(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('account-id');
- $columnValue->setValue('1');
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals(0, $importTransaction->accountId);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals((int)$columnValue->getValue(), $importTransaction->accountId);
- }
-
- /**
- * Test what happens when you set the bill-id using a ColumnValue.
- * Since this field can be mapped. Test with both the mapped and unmapped variant.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testACVBillIdMapped(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('bill-id');
- $columnValue->setOriginalRole('bill-name');
- $columnValue->setValue('Some Bill');
- $columnValue->setMappedValue(2);
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals(0, $importTransaction->billId);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals($columnValue->getMappedValue(), $importTransaction->billId);
- }
-
- /**
- * Test what happens when you set the bill-id using a ColumnValue.
- * Since this field can be mapped. Test with both the mapped and unmapped variant.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testACVBillIdUnmapped(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('bill-id');
- $columnValue->setValue('2');
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals(0, $importTransaction->billId);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals((int)$columnValue->getValue(), $importTransaction->billId);
- }
-
- /**
- * Test what happens when you set the budget-id using a ColumnValue.
- * Since this field can be mapped. Test with both the mapped and unmapped variant.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testACVBudgetIdMapped(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('budget-id');
- $columnValue->setOriginalRole('budget-name');
- $columnValue->setValue('Some Budget');
- $columnValue->setMappedValue(3);
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals(0, $importTransaction->budgetId);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals($columnValue->getMappedValue(), $importTransaction->budgetId);
- }
-
- /**
- * Test what happens when you set the budget-id using a ColumnValue.
- * Since this field can be mapped. Test with both the mapped and unmapped variant.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testACVBudgetIdUnmapped(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('budget-id');
- $columnValue->setValue('3');
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals(0, $importTransaction->budgetId);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals((int)$columnValue->getValue(), $importTransaction->budgetId);
- }
-
- /**
- * Test what happens when you set the category-id using a ColumnValue.
- * Since this field can be mapped. Test with both the mapped and unmapped variant.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testACVCategoryIdMapped(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('category-id');
- $columnValue->setOriginalRole('category-name');
- $columnValue->setValue('Some category');
- $columnValue->setMappedValue(5);
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals(0, $importTransaction->categoryId);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals($columnValue->getMappedValue(), $importTransaction->categoryId);
- }
-
- /**
- * Test what happens when you set the category-id using a ColumnValue.
- * Since this field can be mapped. Test with both the mapped and unmapped variant.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testACVCategoryIdUnmapped(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('category-id');
- $columnValue->setValue('5');
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals(0, $importTransaction->categoryId);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals((int)$columnValue->getValue(), $importTransaction->categoryId);
- }
-
- /**
- * Test what happens when you set the currency-id using a ColumnValue.
- * Since this field can be mapped. Test with both the mapped and unmapped variant.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testACVCurrencyIdMapped(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('currency-id');
- $columnValue->setOriginalRole('currency-code');
- $columnValue->setValue('EUR');
- $columnValue->setMappedValue(4);
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals(0, $importTransaction->currencyId);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals($columnValue->getMappedValue(), $importTransaction->currencyId);
- }
-
- /**
- * Test what happens when you set the currency-id using a ColumnValue.
- * Since this field can be mapped. Test with both the mapped and unmapped variant.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testACVCurrencyIdUnmapped(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('currency-id');
- $columnValue->setValue('4');
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals(0, $importTransaction->currencyId);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals((int)$columnValue->getValue(), $importTransaction->currencyId);
- }
-
- /**
- * Test what happens when you set the foreign-currency-id using a ColumnValue.
- * Since this field can be mapped. Test with both the mapped and unmapped variant.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testACVForeignCurrencyIdMapped(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('foreign-currency-id');
- $columnValue->setOriginalRole('foreign-currency-code');
- $columnValue->setValue('USD');
- $columnValue->setMappedValue(6);
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals(0, $importTransaction->foreignCurrencyId);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals($columnValue->getMappedValue(), $importTransaction->foreignCurrencyId);
- }
-
- /**
- * Test what happens when you set the category-id using a ColumnValue.
- * Since this field can be mapped. Test with both the mapped and unmapped variant.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testACVForeignCurrencyIdUnmapped(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('foreign-currency-id');
- $columnValue->setValue('6');
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals(0, $importTransaction->foreignCurrencyId);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals((int)$columnValue->getValue(), $importTransaction->foreignCurrencyId);
- }
-
-
- /**
- * Test what happens when you set the opposing-id using a ColumnValue.
- * Since this field can be mapped. Test with both the mapped and unmapped variant.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testACVOpposingIdMapped(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('opposing-id');
- $columnValue->setOriginalRole('opposing-name');
- $columnValue->setValue('Some Opposing');
- $columnValue->setMappedValue(7);
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals(0, $importTransaction->opposingId);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals($columnValue->getMappedValue(), $importTransaction->opposingId);
- }
-
- /**
- * Test what happens when you set the opposing-id using a ColumnValue.
- * Since this field can be mapped. Test with both the mapped and unmapped variant.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testACVOpposingIdUnmapped(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('opposing-id');
- $columnValue->setValue('7');
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals(0, $importTransaction->opposingId);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals((int)$columnValue->getValue(), $importTransaction->opposingId);
- }
-
- /**
- * Test various unmapped fields, and the result that the ImportTransaction should display.
- *
- * Put into one big test to save time.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testACVOtherValues(): void
- {
- $tests = [
- 'account-iban' => 'accountIban',
- 'account-name' => 'accountName',
- 'account-bic' => 'accountBic',
- 'account-number' => 'accountNumber',
- 'amount_debit' => 'amountDebit',
- 'amount_credit' => 'amountCredit',
- 'amount_negated' => 'amountNegated',
- 'amount' => 'amount',
- 'amount_foreign' => 'foreignAmount',
- 'bill-name' => 'billName',
- 'budget-name' => 'budgetName',
- 'category-name' => 'categoryName',
- 'currency-code' => 'currencyCode',
- 'currency-name' => 'currencyName',
- 'currency-symbol' => 'currencySymbol',
- 'external-id' => 'externalId',
- 'foreign-currency-code' => 'foreignCurrencyCode',
- 'date-transaction' => 'date',
- 'opposing-iban' => 'opposingIban',
- 'opposing-name' => 'opposingName',
- 'opposing-bic' => 'opposingBic',
- 'opposing-number' => 'opposingNumber',
- ];
- foreach ($tests as $role => $field) {
- // generate random value
- $value = bin2hex(random_bytes(16));
-
- // put into column value:
- $columnValue = new ColumnValue;
- $columnValue->setRole($role);
- $columnValue->setValue($value);
-
- // first test should always return NULL
- $importTransaction = new ImportTransaction;
- $this->assertNull($importTransaction->$field);
-
-
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
-
- // after setting, should return value.
- $this->assertEquals($value, $importTransaction->$field);
-
- }
-
-
- }
-
- /**
- * Basic amount info. Should return something like '1.0'.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testCalculateAmountBasic(): void
- {
- $importTransaction = new ImportTransaction;
- $importTransaction->amount = '1.23';
- try {
- $this->assertEquals('1.23', $importTransaction->calculateAmount());
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * Basic amount info. Should return something like '1.0'.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testCalculateAmountCredit(): void
- {
- $importTransaction = new ImportTransaction;
- $importTransaction->amountCredit = '1.56';
- try {
- $this->assertEquals('1.56', $importTransaction->calculateAmount());
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * Basic amount info. Should return something like '1.0'.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testCalculateAmountDebit(): void
- {
- $importTransaction = new ImportTransaction;
- $importTransaction->amountDebit = '1.01';
- try {
- $this->assertEquals('-1.010000000000', $importTransaction->calculateAmount());
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * With no amount data, object should return ''
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testCalculateAmountEmpty(): void
- {
- $importTransaction = new ImportTransaction;
- try {
- $this->assertEquals('', $importTransaction->calculateAmount());
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * Basic amount info with negative modifier (Rabobank D)
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testCalculateAmountNeg(): void
- {
- $importTransaction = new ImportTransaction;
- $importTransaction->amount = '2.99';
- $importTransaction->modifiers['generic-debit-credit'] = 'D';
- try {
- $this->assertEquals('-2.990000000000', $importTransaction->calculateAmount());
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * Basic amount info. Should return something like '1.0'.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testCalculateAmountNegatedNegative(): void
- {
- $importTransaction = new ImportTransaction;
- $importTransaction->amountNegated = '-1.56';
- try {
- $this->assertEquals('1.560000000000', $importTransaction->calculateAmount());
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * Basic amount info. Should return something like '1.0'.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testCalculateAmountNegatedPositive(): void
- {
- $importTransaction = new ImportTransaction;
- $importTransaction->amountNegated = '1.56';
- try {
- $this->assertEquals('-1.560000000000', $importTransaction->calculateAmount());
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * Basic amount info with positive modifier (Rabobank C)
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testCalculateAmountPos(): void
- {
- $importTransaction = new ImportTransaction;
- $importTransaction->amount = '-2.17';
- $importTransaction->modifiers['rabo-debit-credit'] = 'C';
- try {
- $this->assertEquals('2.170000000000', $importTransaction->calculateAmount());
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * Debit Credit indicator is special.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testDebitCredit(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('generic-debit-credit');
- $columnValue->setValue('Af');
-
- $importTransaction = new ImportTransaction;
- $this->assertCount(0, $importTransaction->modifiers);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(1, $importTransaction->modifiers);
- $this->assertEquals('Af', $importTransaction->modifiers['generic-debit-credit']);
- }
-
- /**
- * Description should be appended.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testDescription(): void
- {
- $one = new ColumnValue;
- $one->setRole('description');
- $one->setValue('A');
-
- $two = new ColumnValue;
- $two->setRole('description');
- $two->setValue('B');
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals('', $importTransaction->description);
- try {
- $importTransaction->addColumnValue($one);
- $importTransaction->addColumnValue($two);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals('A B', $importTransaction->description);
- }
-
- /**
- * Basic foreign amount info. Should return something like '1.0'.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testForeignAmountBasic(): void
- {
- $importTransaction = new ImportTransaction;
- $importTransaction->foreignAmount = '1.23';
- $this->assertEquals('1.23', $importTransaction->calculateForeignAmount());
- }
-
- /**
- * Basic foreign amount info. Should return something like '1.0'.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testForeignAmountEmpty(): void
- {
- $importTransaction = new ImportTransaction;
- $this->assertEquals('', $importTransaction->calculateForeignAmount());
- }
-
- /**
- * Foreign amount with modifier that should make it negative again.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testForeignAmountModNeg(): void
- {
- $importTransaction = new ImportTransaction;
- $importTransaction->foreignAmount = '6.77';
- $importTransaction->modifiers['generic-debit-credit'] = 'D';
- $this->assertEquals('-6.770000000000', $importTransaction->calculateForeignAmount());
- }
-
- /**
- * Foreign amount with modifier that should make it positive again.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testForeignAmountModPos(): void
- {
- $importTransaction = new ImportTransaction;
- $importTransaction->foreignAmount = '-5.77';
- $importTransaction->modifiers['generic-debit-credit'] = 'C';
- $this->assertEquals('5.770000000000', $importTransaction->calculateForeignAmount());
- }
-
- /**
- * Basic foreign amount info. Should return something like '1.0'.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testForeignAmountNeg(): void
- {
- $importTransaction = new ImportTransaction;
- $importTransaction->foreignAmount = '-4.56';
- $this->assertEquals('-4.56', $importTransaction->calculateForeignAmount());
- }
-
- /**
- * Ignore field must be ignored.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testIgnore(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('_ignore');
- $columnValue->setValue('Bla bla bla');
-
- $importTransaction = new ImportTransaction;
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertTrue(true);
- }
-
- /**
- * Set a meta value, see what happens. Any will do.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testMetaValue(): void
- {
- $columnValue = new ColumnValue;
- $columnValue->setRole('date_process');
- $columnValue->setValue('2018-01-01');
-
- $importTransaction = new ImportTransaction;
- $this->assertCount(0, $importTransaction->meta);
- try {
- $importTransaction->addColumnValue($columnValue);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(1, $importTransaction->meta);
- $this->assertEquals($columnValue->getValue(), $importTransaction->meta['date_process']);
- }
-
- /**
- * Description should be appended.
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testNote(): void
- {
- $one = new ColumnValue;
- $one->setRole('note');
- $one->setValue('A');
-
- $two = new ColumnValue;
- $two->setRole('note');
- $two->setValue('B');
-
- $importTransaction = new ImportTransaction;
- $this->assertEquals('', $importTransaction->note);
- try {
- $importTransaction->addColumnValue($one);
- $importTransaction->addColumnValue($two);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals('A B', $importTransaction->note);
- }
-
- /**
- * Test tags with a comma separator
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testTagsComma(): void
- {
- $one = new ColumnValue;
- $one->setRole('tags-comma');
- $one->setValue('a,b,c');
-
- $two = new ColumnValue;
- $two->setRole('tags-comma');
- $two->setValue('d,e,c');
-
- $importTransaction = new ImportTransaction;
- $this->assertCount(0, $importTransaction->tags);
- try {
- $importTransaction->addColumnValue($one);
- $importTransaction->addColumnValue($two);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(5, $importTransaction->tags);
- $this->assertEquals('a', $importTransaction->tags[0]);
- }
-
- /**
- * Test tags with a space separator
- *
- * @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
- */
- public function testTagsSpace(): void
- {
- $one = new ColumnValue;
- $one->setRole('tags-space');
- $one->setValue('a b c');
-
- $two = new ColumnValue;
- $two->setRole('tags-space');
- $two->setValue('d e c');
-
- $importTransaction = new ImportTransaction;
- $this->assertCount(0, $importTransaction->tags);
- try {
- $importTransaction->addColumnValue($one);
- $importTransaction->addColumnValue($two);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertCount(5, $importTransaction->tags);
- $this->assertEquals('a', $importTransaction->tags[0]);
- }
-
-}
diff --git a/tests/Unit/Support/Import/Routine/Bunq/StageImportDataHandlerTest.php b/tests/Unit/Support/Import/Routine/Bunq/StageImportDataHandlerTest.php
deleted file mode 100644
index 39090d6521..0000000000
--- a/tests/Unit/Support/Import/Routine/Bunq/StageImportDataHandlerTest.php
+++ /dev/null
@@ -1,572 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\Routine\Bunq;
-
-
-use bunq\Model\Generated\Endpoint\BunqResponsePaymentList;
-use bunq\Model\Generated\Endpoint\Payment as BunqPayment;
-use bunq\Model\Generated\Object\Amount;
-use bunq\Model\Generated\Object\LabelMonetaryAccount;
-use bunq\Model\Generated\Object\LabelUser;
-use bunq\Model\Generated\Object\Pointer;
-use Carbon\Carbon;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Factory\AccountFactory;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Services\Bunq\ApiContext;
-use FireflyIII\Services\Bunq\Payment;
-use FireflyIII\Support\Import\Routine\Bunq\PaymentConverter;
-use FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class StageImportDataHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class StageImportDataHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler
- */
- public function testRunBasic(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sidh_bbunq_' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'bunq';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // fake objects:
- $deposit = $this->user()->accounts()->where('account_type_id', 5)->first();
- $account = $this->user()->accounts()->where('account_type_id', 3)->first();
- $contextPreference = new Preference;
- $contextPreference->name = 'Some name';
- $contextPreference->data = '{"a":"b"}';
- $config = [
- 'accounts' => [
- ['id' => 1234], // bunq account
- ],
- 'mapping' => [
- 1234 => 5678, // Firefly III mapping.
- ],
- ];
- $amount = new Amount('150', 'EUR');
- $pointer = new Pointer('iban', 'ES2364265841767173822054', 'Test Site');
- $expectedAccount = [
- 'user_id' => 1,
- 'iban' => null,
- 'name' => 'James',
- 'account_type_id' => null,
- 'accountType' => 'Revenue account',
- 'virtualBalance' => null,
- 'active' => true,
- ];
- $today = new Carbon;
-
- // ignore the deprecated fields:
- $amount->setValue('150');
- $amount->setCurrency('EUR');
- $pointer->setType('iban');
- $pointer->setValue('ES2364265841767173822054');
- $pointer->setName('Test Site');
- $labelMonetaryAccount = new LabelMonetaryAccount();
- $labelMonetaryAccount->setDisplayName('James');
- $labelUser = new LabelUser('x', 'James', 'NL');
- $labelUser->setDisplayName('James');
- $labelMonetaryAccount->setLabelUser($labelUser);
-
- $payment = new BunqPayment($amount, $pointer, 'Some descr', null, null);
- $payment->setAmount($amount);
- $payment->setCounterpartyAlias($labelMonetaryAccount);
- $payment->setDescription('Random description #' . $this->randomInt());
- $value = [$payment];
- $list = new BunqResponsePaymentList($value, [], null);
-
- $expectedTransaction = [
- 'user' => 1,
- 'type' => 'Deposit',
- 'date' => $today->format('Y-m-d'),
- 'timestamp' => $today->toAtomString(),
- 'description' => $payment->getDescription(),
- 'piggy_bank_id' => null,
- 'piggy_bank_name' => null,
- 'bill_id' => null,
- 'bill_name' => null,
- 'tags' => [null, null],
- 'internal_reference' => null,
- 'external_id' => null,
- 'notes' => null,
- 'bunq_payment_id' => null,
- 'transactions' => [
- [
- 'description' => null,
- 'amount' => '150',
- 'currency_id' => null,
- 'currency_code' => 'EUR',
- 'foreign_amount' => null,
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => null,
- 'budget_id' => null,
- 'budget_name' => null,
- 'category_id' => null,
- 'category_name' => null,
- 'source_id' => $deposit->id,
- 'source_name' => null,
- 'destination_id' => $account->id,
- 'destination_name' => null,
- 'reconciled' => false,
- 'identifier' => 0,
- ],
- ],
- 'original-source' => 'bunq-v' . config('firefly.version'),
- ];
-
- $expectedTransactions = [$expectedTransaction];
-
-
- // mock used objects:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $accountRepository = $this->mock(AccountRepositoryInterface::class);
- $accountFactory = $this->mock(AccountFactory::class);
- $context = $this->mock(ApiContext::class);
- $payment = $this->mock(Payment::class);
- $converter = $this->mock(PaymentConverter::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $accountRepository->shouldReceive('setUser')->once();
- $accountFactory->shouldReceive('setUser')->once();
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference);
- $context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once();
- $converter->shouldReceive('setImportJob')->atLeast()->once();
- $repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once();
- $accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once();
- $payment->shouldReceive('listing')->once()->andReturn($list);
-
- // set new last transaction ID:
- $lastPref = new Preference;
- $lastPref->data = 0;
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-oldest-transaction-1234', 0])->andReturn($lastPref)->times(2);
- //
- $lastPref = new Preference;
- $lastPref->data = 0;
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-newest-transaction-1234', 0])->andReturn($lastPref)->once();
-
- // converter should convert:
- $converter->shouldReceive('convert')->atLeast()->once()->andReturn($expectedTransaction);
-
- // todo: improve test thing:
- Preferences::shouldReceive('setForUser');
-
- $handler = new StageImportDataHandler;
- $handler->setImportJob($job);
- try {
- $handler->run();
-
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- $transactions = $handler->getTransactions();
- $this->assertEquals($expectedTransactions, $transactions);
- }
-
- // /**
- // * @covers \FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler
- // */
- // public function testRunEmpty(): void
- // {
- // $job = new ImportJob;
- // $job->user_id = $this->user()->id;
- // $job->key = 'sidA_bbunq_' . $this->randomInt();
- // $job->status = 'new';
- // $job->stage = 'new';
- // $job->provider = 'bunq';
- // $job->file_type = '';
- // $job->configuration = [];
- // $job->save();
- //
- // // fake objects:
- // $account = $this->user()->accounts()->where('account_type_id', 3)->first();
- // $contextPreference = new Preference;
- // $contextPreference->name = 'Some name';
- // $contextPreference->data = '{"a":"b"}';
- // $config = [
- // 'accounts' => [
- // ['id' => 1234], // bunq account
- // ],
- // 'mapping' => [
- // 1234 => 5678, // Firefly III mapping.
- // ],
- // ];
- // $expectedTransactions = [];
- // $value = [];
- // $list = new BunqResponsePaymentList($value, [], null);
- //
- // // mock used objects:
- // $repository = $this->mock(ImportJobRepositoryInterface::class);
- // $accountRepository = $this->mock(AccountRepositoryInterface::class);
- // $accountFactory = $this->mock(AccountFactory::class);
- // $context = $this->mock(ApiContext::class);
- // $payment = $this->mock(Payment::class);
- //
- // // mock calls:
- // $repository->shouldReceive('setUser')->once();
- // $accountRepository->shouldReceive('setUser')->once();
- // $accountFactory->shouldReceive('setUser')->once();
- // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference);
- // $context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once();
- // $repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once();
- // $accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once();
- // $payment->shouldReceive('listing')->once()->andReturn($list);
- //
- // // set new last transaction ID:
- // $lastPref = new Preference;
- // $lastPref->data = 0;
- // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-oldest-transaction-1234', 0])->andReturn($lastPref)->times(2);
- //
- // $lastPref = new Preference;
- // $lastPref->data = 0;
- // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-newest-transaction-1234', 0])->andReturn($lastPref)->once();
- //
- // // todo: improve test thing:
- // Preferences::shouldReceive('setForUser');
- //
- // $handler = new StageImportDataHandler;
- // $handler->setImportJob($job);
- // try {
- // $handler->run();
- //
- // } catch (FireflyException $e) {
- // $this->assertFalse(true, $e->getMessage());
- // }
- // $transactions = $handler->getTransactions();
- // $this->assertEquals($expectedTransactions, $transactions);
- //
- // }
- //
- // /**
- // * @covers \FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler
- // */
- // public function testRunIban(): void
- // {
- // $job = new ImportJob;
- // $job->user_id = $this->user()->id;
- // $job->key = 'sidh_bbunq_' . $this->randomInt();
- // $job->status = 'new';
- // $job->stage = 'new';
- // $job->provider = 'bunq';
- // $job->file_type = '';
- // $job->configuration = [];
- // $job->save();
- //
- // // fake objects:
- // $deposit = $this->user()->accounts()->where('account_type_id', 5)->first();
- // $account = $this->user()->accounts()->where('account_type_id', 3)->first();
- // $contextPreference = new Preference;
- // $contextPreference->name = 'Some name';
- // $contextPreference->data = '{"a":"b"}';
- // $config = [
- // 'accounts' => [
- // ['id' => 1234], // bunq account
- // ],
- // 'mapping' => [
- // 1234 => 5678, // Firefly III mapping.
- // ],
- // ];
- // $today = new Carbon;
- // $amount = new Amount('150', 'EUR');
- // $pointer = new Pointer('iban', 'ES2364265841767173822054', 'Test Site');
- //
- // // set new last transaction ID:
- // $lastPref = new Preference;
- // $lastPref->data = 0;
- // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-oldest-transaction-1234', 0])->andReturn($lastPref)->times(2);
- //
- // $lastPref = new Preference;
- // $lastPref->data = 0;
- // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-newest-transaction-1234', 0])->andReturn($lastPref)->once();
- //
- // // todo: improve test thing:
- // Preferences::shouldReceive('setForUser');
- //
- // // ignore the deprecated fields:
- // $amount->setValue('150');
- // $amount->setCurrency('EUR');
- // $pointer->setType('iban');
- // $pointer->setValue('ES2364265841767173822054');
- // $pointer->setName('Test Site');
- // $labelMonetaryAccount = new LabelMonetaryAccount();
- // $labelMonetaryAccount->setDisplayName('James');
- // $labelUser = new LabelUser('x', 'James', 'NL');
- // $labelUser->setDisplayName('James');
- // $labelMonetaryAccount->setLabelUser($labelUser);
- // $labelMonetaryAccount->setIban('RS88844660406878687897');
- //
- // $payment = new BunqPayment($amount, $pointer, 'Some descr', null, null);
- // $payment->setAmount($amount);
- // $payment->setDescription('Some random thing #' . $this->randomInt());
- // $payment->setCounterpartyAlias($labelMonetaryAccount);
- // $value = [$payment];
- // $list = new BunqResponsePaymentList($value, [], null);
- //
- // $expectedTransactions = [
- // [
- // 'user' => 1,
- // 'type' => 'Deposit',
- // 'date' => $today->format('Y-m-d'),
- // 'description' => $payment->getDescription(),
- // 'piggy_bank_id' => null,
- // 'piggy_bank_name' => null,
- // 'bill_id' => null,
- // 'bill_name' => null,
- // 'tags' => [null, null],
- // 'internal_reference' => null,
- // 'external_id' => null,
- // 'notes' => null,
- // 'bunq_payment_id' => null,
- // 'transactions' => [
- // [
- // 'description' => null,
- // 'amount' => '150',
- // 'currency_id' => null,
- // 'currency_code' => 'EUR',
- // 'foreign_amount' => null,
- // 'foreign_currency_id' => null,
- // 'foreign_currency_code' => null,
- // 'budget_id' => null,
- // 'budget_name' => null,
- // 'category_id' => null,
- // 'category_name' => null,
- // 'source_id' => $deposit->id,
- // 'source_name' => null,
- // 'destination_id' => $account->id,
- // 'destination_name' => null,
- // 'reconciled' => false,
- // 'identifier' => 0,
- // ],
- // ],
- // 'original-source' => 'bunq-v' . config('firefly.version'),
- // ],
- // ];
- //
- // // mock used objects:
- // $repository = $this->mock(ImportJobRepositoryInterface::class);
- // $accountRepository = $this->mock(AccountRepositoryInterface::class);
- // $accountFactory = $this->mock(AccountFactory::class);
- // $context = $this->mock(ApiContext::class);
- // $payment = $this->mock(Payment::class);
- //
- // // mock calls:
- // $repository->shouldReceive('setUser')->once();
- // $accountRepository->shouldReceive('setUser')->once();
- // $accountFactory->shouldReceive('setUser')->once();
- // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference);
- // $context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once();
- // $repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once();
- // $accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once();
- // $payment->shouldReceive('listing')->once()->andReturn($list);
- // $accountRepository->shouldReceive('findByIbanNull')->withArgs(['RS88844660406878687897', [AccountType::REVENUE]])->once()->andReturn($deposit);
- //
- // $handler = new StageImportDataHandler;
- // $handler->setImportJob($job);
- // try {
- // $handler->run();
- //
- // } catch (FireflyException $e) {
- // $this->assertFalse(true, $e->getMessage());
- // }
- // $transactions = $handler->getTransactions();
- // $this->assertEquals($expectedTransactions, $transactions);
- // }
- //
- // /**
- // * @covers \FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler
- // */
- // public function testRunIbanAsset(): void
- // {
- // $job = new ImportJob;
- // $job->user_id = $this->user()->id;
- // $job->key = 'sidh_bbunq_' . $this->randomInt();
- // $job->status = 'new';
- // $job->stage = 'new';
- // $job->provider = 'bunq';
- // $job->file_type = '';
- // $job->configuration = [];
- // $job->save();
- //
- // // fake objects:
- // $account = $this->user()->accounts()->where('account_type_id', 3)->first();
- // $asset = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $account->id)->first();
- // $contextPreference = new Preference;
- // $contextPreference->name = 'Some name';
- // $contextPreference->data = '{"a":"b"}';
- // $config = [
- // 'accounts' => [
- // ['id' => 1234], // bunq account
- // ],
- // 'mapping' => [
- // 1234 => 5678, // Firefly III mapping.
- // ],
- // ];
- // $amount = new Amount('150', 'EUR');
- // $pointer = new Pointer('iban', 'ES2364265841767173822054', 'Test Site');
- // $expectedAccount = [
- // 'user_id' => 1,
- // 'iban' => null,
- // 'name' => 'James',
- // 'account_type_id' => null,
- // 'accountType' => 'Revenue account',
- // 'virtualBalance' => null,
- // 'active' => true,
- // ];
- //
- // // ignore the deprecated fields:
- // $amount->setValue('150');
- // $amount->setCurrency('EUR');
- // $pointer->setType('iban');
- // $pointer->setValue('ES2364265841767173822054');
- // $pointer->setName('Test Site');
- // $labelMonetaryAccount = new LabelMonetaryAccount();
- // $labelMonetaryAccount->setDisplayName('James');
- // $labelUser = new LabelUser('x', 'James', 'NL');
- // $labelUser->setDisplayName('James');
- // $labelMonetaryAccount->setLabelUser($labelUser);
- // $labelMonetaryAccount->setIban('RS88844660406878687897');
- // $today = new Carbon;
- // $payment = new BunqPayment($amount, $pointer, 'Some descr', null, null);
- // $payment->setAmount($amount);
- // $payment->setCounterpartyAlias($labelMonetaryAccount);
- // $payment->setDescription('Random transfer #' . $this->randomInt());
- // $value = [$payment];
- // $list = new BunqResponsePaymentList($value, [], null);
- //
- // // set new last transaction ID:
- // $lastPref = new Preference;
- // $lastPref->data = 0;
- // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-oldest-transaction-1234', 0])->andReturn($lastPref)->once();
- //
- // $expectedTransactions = [
- // [
- // 'user' => 1,
- // 'type' => 'Transfer',
- // 'date' => $today->format('Y-m-d'),
- // 'description' => $payment->getDescription(),
- // 'piggy_bank_id' => null,
- // 'piggy_bank_name' => null,
- // 'bill_id' => null,
- // 'bill_name' => null,
- // 'tags' => [null, null],
- // 'internal_reference' => null,
- // 'external_id' => null,
- // 'notes' => null,
- // 'bunq_payment_id' => null,
- // 'transactions' => [
- // [
- // 'description' => null,
- // 'amount' => '150',
- // 'currency_id' => null,
- // 'currency_code' => 'EUR',
- // 'foreign_amount' => null,
- // 'foreign_currency_id' => null,
- // 'foreign_currency_code' => null,
- // 'budget_id' => null,
- // 'budget_name' => null,
- // 'category_id' => null,
- // 'category_name' => null,
- // 'source_id' => $asset->id,
- // 'source_name' => null,
- // 'destination_id' => $account->id,
- // 'destination_name' => null,
- // 'reconciled' => false,
- // 'identifier' => 0,
- // ],
- // ],
- // ],
- // ];
- //
- // // mock used objects:
- // $repository = $this->mock(ImportJobRepositoryInterface::class);
- // $accountRepository = $this->mock(AccountRepositoryInterface::class);
- // $accountFactory = $this->mock(AccountFactory::class);
- // $context = $this->mock(ApiContext::class);
- // $payment = $this->mock(Payment::class);
- //
- // // mock calls:
- // $repository->shouldReceive('setUser')->once();
- // $accountRepository->shouldReceive('setUser')->once();
- // $accountFactory->shouldReceive('setUser')->once();
- // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->andReturn($contextPreference);
- // $context->shouldReceive('fromJson')->withArgs(['{"a":"b"}'])->once();
- // $repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->andReturn($config)->once();
- // $accountRepository->shouldReceive('findNull')->withArgs([5678])->andReturn($account)->once();
- // $payment->shouldReceive('listing')->once()->andReturn($list);
- // $accountRepository->shouldReceive('findByIbanNull')->withArgs(['RS88844660406878687897', [AccountType::REVENUE]])->once()->andReturnNull();
- // $accountRepository->shouldReceive('findByIbanNull')->withArgs(['RS88844660406878687897', [AccountType::ASSET]])->once()->andReturn($asset);
- //
- // // set new last transaction ID:
- // $lastPref = new Preference;
- // $lastPref->data = 0;
- // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-oldest-transaction-1234', 0])->andReturn($lastPref)->times(1);
- //
- // $lastPref = new Preference;
- // $lastPref->data = 0;
- // Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq-newest-transaction-1234', 0])->andReturn($lastPref)->once();
- //
- // // todo: improve test thing:
- // Preferences::shouldReceive('setForUser');
- //
- // $handler = new StageImportDataHandler;
- // $handler->setImportJob($job);
- // try {
- // $handler->run();
- //
- // } catch (FireflyException $e) {
- // $this->assertFalse(true, $e->getMessage());
- // }
- // $transactions = $handler->getTransactions();
- // //$this->assertEquals($expectedTransactions, $transactions);
- // }
-
-}
diff --git a/tests/Unit/Support/Import/Routine/Bunq/StageNewHandlerTest.php b/tests/Unit/Support/Import/Routine/Bunq/StageNewHandlerTest.php
deleted file mode 100644
index 148e61e483..0000000000
--- a/tests/Unit/Support/Import/Routine/Bunq/StageNewHandlerTest.php
+++ /dev/null
@@ -1,334 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\Routine\Bunq;
-
-
-use bunq\Model\Generated\Endpoint\BunqResponseMonetaryAccountList;
-use bunq\Model\Generated\Endpoint\MonetaryAccount as BunqMonetaryAccount;
-use bunq\Model\Generated\Endpoint\MonetaryAccountBank as BunqMonetaryAccountBank;
-use bunq\Model\Generated\Endpoint\MonetaryAccountJoint;
-use bunq\Model\Generated\Endpoint\MonetaryAccountLight;
-use bunq\Model\Generated\Object\CoOwner;
-use bunq\Model\Generated\Object\LabelUser;
-use bunq\Model\Generated\Object\MonetaryAccountSetting;
-use bunq\Model\Generated\Object\Pointer;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Services\Bunq\ApiContext;
-use FireflyIII\Services\Bunq\MonetaryAccount;
-use FireflyIII\Support\Import\Routine\Bunq\StageNewHandler;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\Object\FakeApiContext;
-use Tests\TestCase;
-
-/**
- * Class StageNewHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class StageNewHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\Bunq\StageNewHandler
- */
- public function testRun(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'snh_bunq_' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'bunq';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- $pref = new Preference;
- $pref->name = 'some-name';
- $pref->data = '{"a": "b"}';
-
- // create fake bunq object:
- $setting = new MonetaryAccountSetting(null, null, null);
- $mab = new BunqMonetaryAccountBank('EUR', 'Some descr', null, null, null, null, null, null, null, null);
- $monAcc = new BunqMonetaryAccount;
- $alias = new Pointer('a', 'b', null);
-
-
- // dont care about deprecation.
- $alias->setType('IBAN');
- $alias->setName('Somebody');
- $alias->setValue('SM72C9584723533916792029340');
- $setting->setColor('FFFFFF');
- $mab->setSetting($setting);
- $mab->setAlias([$alias]);
- $monAcc->setMonetaryAccountBank($mab);
-
- // response list.
- $list = new BunqResponseMonetaryAccountList([$monAcc], []);
-
- $expectedConfig = [
- 'accounts' => [
- 0 => [
- 'id' => null,
- 'currency_code' => null,
- 'description' => null,
- 'balance' => null,
- 'status' => null,
- 'type' => 'MonetaryAccountBank',
- 'iban' => 'SM72C9584723533916792029340',
- 'aliases' => [
- [
- 'name' => $alias->getName(),
- 'type' => $alias->getType(),
- 'value' => $alias->getValue(),
- ],
- ],
- 'settings' => [
- 'color' => $setting->getColor(),
- 'default_avatar_status' => null,
- 'restriction_chat' => null,
- ],
- ],
- ],
- ];
-
- // mock classes
- $apiContext = $this->mock(ApiContext::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $mAccount = $this->mock(MonetaryAccount::class);
-
- // mock calls
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->once()->andReturn($pref);
- $apiContext->shouldReceive('fromJson')->withArgs(['{"a": "b"}'])->once()->andReturn(new FakeApiContext);
- $repository->shouldReceive('setUser')->once();
- $mAccount->shouldReceive('listing')->andReturn($list)->once();
- $repository->shouldReceive('getConfiguration')->once()->andReturn([]);
-
- $repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $expectedConfig]);
-
- $handler = new StageNewHandler;
- $handler->setImportJob($job);
- try {
- $handler->run();
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\Bunq\StageNewHandler
- */
- public function testRunMaj(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'snha_bunq_' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'bunq';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- $pref = new Preference;
- $pref->name = 'some-name';
- $pref->data = '{"a": "b"}';
-
- // create fake bunq object:
- $setting = new MonetaryAccountSetting(null, null, null);
- $maj = new MonetaryAccountJoint('EUR', [], 'Some descr', null, null, null, null, null, null, null, null);
- $monAcc = new BunqMonetaryAccount;
- $alias = new Pointer('a', 'b', null);
- $labelUser = new LabelUser('x', 'James', 'NL');
- $coOwner = new CoOwner($alias);
-
- // dont care about deprecation.
- $alias->setType('IBAN');
- $alias->setName('Somebody');
- $alias->setValue('SM72C9584723533916792029340');
- $labelUser->setDisplayName('James');
- $setting->setColor('FFFFFF');
- $maj->setSetting($setting);
- $maj->setAlias([$alias]);
- $maj->setAllCoOwner([$coOwner]);
- $monAcc->setMonetaryAccountJoint($maj);
- $coOwner->setAlias($labelUser);
-
- // response list.
- $list = new BunqResponseMonetaryAccountList([$monAcc], []);
-
- $expectedConfig = [
- 'accounts' => [
- 0 => [
- 'id' => null,
- 'currency_code' => null,
- 'description' => null,
- 'balance' => null,
- 'status' => null,
- 'type' => 'MonetaryAccountJoint',
- 'co-owners' => ['James'],
- 'aliases' => [
- [
- 'name' => $alias->getName(),
- 'type' => $alias->getType(),
- 'value' => $alias->getValue(),
- ],
- ],
- 'settings' => [
- 'color' => $setting->getColor(),
- 'default_avatar_status' => null,
- 'restriction_chat' => null,
- ],
- 'iban' => 'SM72C9584723533916792029340',
- ],
- ],
- ];
-
- // mock classes
- $apiContext = $this->mock(ApiContext::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $mAccount = $this->mock(MonetaryAccount::class);
-
- // mock calls
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->once()->andReturn($pref);
- $apiContext->shouldReceive('fromJson')->withArgs(['{"a": "b"}'])->once()->andReturn(new FakeApiContext);
- $repository->shouldReceive('setUser')->once();
- $mAccount->shouldReceive('listing')->andReturn($list)->once();
- $repository->shouldReceive('getConfiguration')->once()->andReturn([]);
- $repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $expectedConfig]);
-
-
- $handler = new StageNewHandler;
- $handler->setImportJob($job);
- try {
- $handler->run();
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\Bunq\StageNewHandler
- */
- public function testRunMal(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'snh_bbunq_' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'bunq';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- $pref = new Preference;
- $pref->name = 'some-name';
- $pref->data = '{"a": "b"}';
-
- // create fake bunq object:
- $setting = new MonetaryAccountSetting(null, null, null);
- $mal = new MonetaryAccountLight('EUR', 'Some descr', null, null, null, null, null, null, null, null);
- $monAcc = new BunqMonetaryAccount;
- $alias = new Pointer('a', 'b', null);
-
-
- // dont care about deprecation.
- $alias->setType('IBAN');
- $alias->setName('Somebody');
- $alias->setValue('SM72C9584723533916792029340');
- $setting->setColor('FFFFFF');
- $mal->setSetting($setting);
- $mal->setAlias([$alias]);
- $monAcc->setMonetaryAccountLight($mal);
-
- // response list.
- $list = new BunqResponseMonetaryAccountList([$monAcc], []);
-
- $expectedConfig = [
- 'accounts' => [
- 0 => [
- 'id' => null,
- 'currency_code' => null,
- 'description' => null,
- 'balance' => null,
- 'status' => null,
- 'type' => 'MonetaryAccountLight',
- 'aliases' => [
- [
- 'name' => $alias->getName(),
- 'type' => $alias->getType(),
- 'value' => $alias->getValue(),
- ],
- ],
- 'settings' => [
- 'color' => $setting->getColor(),
- 'default_avatar_status' => null,
- 'restriction_chat' => null,
- ],
- 'iban' => 'SM72C9584723533916792029340',
- ],
-
- ],
- ];
-
- // mock classes
- $apiContext = $this->mock(ApiContext::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $mAccount = $this->mock(MonetaryAccount::class);
-
- // mock calls
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'bunq_api_context', null])->once()->andReturn($pref);
- $apiContext->shouldReceive('fromJson')->withArgs(['{"a": "b"}'])->once()->andReturn(new FakeApiContext);
- $repository->shouldReceive('setUser')->once();
- $mAccount->shouldReceive('listing')->andReturn($list)->once();
- $repository->shouldReceive('getConfiguration')->once()->andReturn([]);
- $repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $expectedConfig]);
-
-
- $handler = new StageNewHandler;
- $handler->setImportJob($job);
- try {
- $handler->run();
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
-
-}
diff --git a/tests/Unit/Support/Import/Routine/File/AssetAccountMapperTest.php b/tests/Unit/Support/Import/Routine/File/AssetAccountMapperTest.php
deleted file mode 100644
index 5fed70a7e0..0000000000
--- a/tests/Unit/Support/Import/Routine/File/AssetAccountMapperTest.php
+++ /dev/null
@@ -1,201 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\Routine\File;
-
-
-use FireflyIII\Models\AccountType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Support\Import\Routine\File\AssetAccountMapper;
-use Illuminate\Support\Collection;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class AssetAccountMapperTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class AssetAccountMapperTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Should return with the given $default account and not the $bad one.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\AssetAccountMapper
- */
- public function testBadAsset(): void
- {
- $bad = $this->user()->accounts()->where('account_type_id', 4)->inRandomOrder()->first();
- $default = $this->user()->accounts()->where('account_type_id', 3)->inRandomOrder()->first();
- // mock repository:
- $repository = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findNull')->once()->withArgs([$bad->id])->andReturn($bad);
- $repository->shouldReceive('findNull')->once()->withArgs([$default->id])->andReturn($default);
-
- $mapper = new AssetAccountMapper;
- $mapper->setUser($this->user());
- $mapper->setDefaultAccount($default->id);
- $result = $mapper->map($bad->id, []);
- $this->assertEquals($default->id, $result->id);
- }
-
- /**
- * Should return with the given $expected account.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\AssetAccountMapper
- */
- public function testCorrectAsset(): void
- {
- $expected = $this->user()->accounts()->where('account_type_id', 3)->inRandomOrder()->first();
-
- // mock repository:
- $repository = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findNull')->once()->withArgs([$expected->id])->andReturn($expected);
-
- $mapper = new AssetAccountMapper;
- $mapper->setUser($this->user());
- $result = $mapper->map($expected->id, []);
- $this->assertEquals($expected->id, $result->id);
- }
-
- /**
- * Should return with the $default account.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\AssetAccountMapper
- */
- public function testEmpty(): void
- {
- $default = $this->user()->accounts()->where('account_type_id', 3)->inRandomOrder()->first();
-
- // mock repository:
- $repository = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findNull')->once()->withArgs([$default->id])->andReturn($default);
-
- $mapper = new AssetAccountMapper;
- $mapper->setUser($this->user());
- $mapper->setDefaultAccount($default->id);
- $result = $mapper->map(null, []);
- $this->assertEquals($default->id, $result->id);
-
- }
-
- /**
- * Should return with the $default account.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\AssetAccountMapper
- */
- public function testEmptyNoDefault(): void
- {
- $fallback = $this->user()->accounts()->where('account_type_id', 3)->first();
-
- // mock repository:
- $repository = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::ASSET]])->andReturn(
- new Collection([$fallback])
- );
-
- $mapper = new AssetAccountMapper;
- $mapper->setUser($this->user());
- $result = $mapper->map(null, []);
- $this->assertEquals($fallback->id, $result->id);
-
- }
-
- /**
- * Should search for the given IBAN and return $expected.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\AssetAccountMapper
- */
- public function testFindByIban(): void
- {
- $searchValue = 'IamIban';
- $expected = $this->user()->accounts()->where('account_type_id', 3)->inRandomOrder()->first();
- // mock repository:
- $repository = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findByIbanNull')->once()
- ->withArgs([$searchValue, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->andReturn($expected);
-
- $mapper = new AssetAccountMapper;
- $mapper->setUser($this->user());
- $result = $mapper->map(0, ['iban' => $searchValue]);
- $this->assertEquals($expected->id, $result->id);
- }
-
- /**
- * Should search for the given name and return $expected.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\AssetAccountMapper
- */
- public function testFindByName(): void
- {
- $searchValue = 'AccountName';
- $expected = $this->user()->accounts()->where('account_type_id', 3)->inRandomOrder()->first();
- // mock repository:
- $repository = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findByName')->once()
- ->withArgs([$searchValue, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->andReturn($expected);
-
- $mapper = new AssetAccountMapper;
- $mapper->setUser($this->user());
- $result = $mapper->map(0, ['name' => $searchValue]);
- $this->assertEquals($expected->id, $result->id);
- }
-
- /**
- * Should search for the given number and return $expected.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\AssetAccountMapper
- */
- public function testFindByNumber(): void
- {
- $searchValue = '123456';
- $expected = $this->user()->accounts()->where('account_type_id', 3)->inRandomOrder()->first();
- // mock repository:
- $repository = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findByAccountNumber')->once()
- ->withArgs([$searchValue, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->andReturn($expected);
-
- $mapper = new AssetAccountMapper;
- $mapper->setUser($this->user());
- $result = $mapper->map(0, ['number' => $searchValue]);
- $this->assertEquals($expected->id, $result->id);
- }
-
-}
diff --git a/tests/Unit/Support/Import/Routine/File/CSVProcessorTest.php b/tests/Unit/Support/Import/Routine/File/CSVProcessorTest.php
deleted file mode 100644
index e2aeccbad0..0000000000
--- a/tests/Unit/Support/Import/Routine/File/CSVProcessorTest.php
+++ /dev/null
@@ -1,98 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\Routine\File;
-
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Support\Import\Routine\File\CSVProcessor;
-use FireflyIII\Support\Import\Routine\File\ImportableConverter;
-use FireflyIII\Support\Import\Routine\File\ImportableCreator;
-use FireflyIII\Support\Import\Routine\File\LineReader;
-use FireflyIII\Support\Import\Routine\File\MappedValuesValidator;
-use FireflyIII\Support\Import\Routine\File\MappingConverger;
-use Log;
-use Tests\TestCase;
-
-/**
- * Do some end to end testing here, perhaps?
- *
- * Class CSVProcessorTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CSVProcessorTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\File\CSVProcessor
- */
- public function testBasic(): void
- {
-
- // mock all classes:
- $lineReader = $this->mock(LineReader::class);
- $lineReader->shouldReceive('setImportJob')->once();
- $lineReader->shouldReceive('getLines')->once()->andReturn([]);
-
- $mappingConverger = $this->mock(MappingConverger::class);
- $mappingConverger->shouldReceive('setImportJob')->once();
- $mappingConverger->shouldReceive('converge')->withArgs([[]])->andReturn([])->once();
- $mappingConverger->shouldReceive('getMappedValues')->andReturn([])->once();
-
-
- $validator = $this->mock(MappedValuesValidator::class);
- $validator->shouldReceive('setImportJob')->once();
- $validator->shouldReceive('validate')->andReturn([]);
-
- $creator = $this->mock(ImportableCreator::class);
- $creator->shouldReceive('convertSets')->withArgs([[]])->andReturn([])->once();
-
- $converter = $this->mock(ImportableConverter::class);
- $converter->shouldReceive('setImportJob')->once();
- $converter->shouldReceive('setMappedValues')->once()->withArgs([[]])->andReturn([]);
- $converter->shouldReceive('convert')->withArgs([[]])->once()->andReturn([]);
-
-
- /** @var ImportJob $job */
- $job = $this->user()->importJobs()->first();
- $processor = new CSVProcessor;
- $processor->setImportJob($job);
- try {
- $result = $processor->run();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals([], $result);
- }
-}
diff --git a/tests/Unit/Support/Import/Routine/File/CurrencyMapperTest.php b/tests/Unit/Support/Import/Routine/File/CurrencyMapperTest.php
deleted file mode 100644
index d83a50eed6..0000000000
--- a/tests/Unit/Support/Import/Routine/File/CurrencyMapperTest.php
+++ /dev/null
@@ -1,184 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\Routine\File;
-
-
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Support\Import\Routine\File\CurrencyMapper;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class CurrencyMapperTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class CurrencyMapperTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\File\CurrencyMapper
- */
- public function testBasic(): void
- {
- $currency = TransactionCurrency::inRandomOrder()->first();
- // mock data
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findNull')->once()->withArgs([$currency->id])->andReturn($currency);
- $mapper = new CurrencyMapper();
- $mapper->setUser($this->user());
-
- $result = $mapper->map($currency->id, []);
- $this->assertEquals($currency->id, $result->id);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\File\CurrencyMapper
- */
- public function testBasicNotFound(): void
- {
- $currency = TransactionCurrency::inRandomOrder()->first();
- // mock data
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findNull')->once()->withArgs([$currency->id])->andReturn(null);
-
- $mapper = new CurrencyMapper();
- $mapper->setUser($this->user());
-
- $result = $mapper->map($currency->id, []);
- $this->assertNull($result);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\File\CurrencyMapper
- */
- public function testEmpty(): void
- {
-
- // mock data
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
-
- $mapper = new CurrencyMapper();
- $mapper->setUser($this->user());
-
- $result = $mapper->map(null, []);
- $this->assertNull($result);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\File\CurrencyMapper
- */
- public function testFindAndCreate(): void
- {
- $currency = TransactionCurrency::inRandomOrder()->first();
- // mock data
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findBySymbolNull')->withArgs([$currency->symbol])->andReturn(null)->once();
- $repository->shouldReceive('findByCodeNull')->withArgs([$currency->code])->andReturn(null)->once();
- $repository->shouldReceive('findByNameNull')->withArgs([$currency->name])->andReturn(null)->once();
-
- // nothing found, mapper will try to create it.
- $repository->shouldReceive('store')
- ->withArgs([['code' => $currency->code, 'name' => $currency->name, 'symbol' => $currency->symbol, 'enabled' => true, 'decimal_places' => 2]])
- ->once()->andReturn($currency);
-
- $mapper = new CurrencyMapper();
- $mapper->setUser($this->user());
-
- $result = $mapper->map(null, ['name' => $currency->name, 'code' => $currency->code, 'enabled' => true, 'symbol' => $currency->symbol]);
- $this->assertEquals($currency->id, $result->id);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\File\CurrencyMapper
- */
- public function testFindByCode(): void
- {
- $currency = TransactionCurrency::inRandomOrder()->first();
- // mock data
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findByCodeNull')->withArgs([$currency->code])
- ->andReturn($currency)->once();
-
- $mapper = new CurrencyMapper();
- $mapper->setUser($this->user());
-
- $result = $mapper->map(null, ['code' => $currency->code]);
- $this->assertEquals($currency->id, $result->id);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\File\CurrencyMapper
- */
- public function testFindByName(): void
- {
- $currency = TransactionCurrency::inRandomOrder()->first();
- // mock data
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findByNameNull')->withArgs([$currency->name])
- ->andReturn($currency)->once();
-
- $mapper = new CurrencyMapper();
- $mapper->setUser($this->user());
-
- $result = $mapper->map(null, ['name' => $currency->name]);
- $this->assertEquals($currency->id, $result->id);
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\File\CurrencyMapper
- */
- public function testFindBySymbol(): void
- {
- $currency = TransactionCurrency::inRandomOrder()->first();
- // mock data
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findBySymbolNull')->withArgs([$currency->symbol])
- ->andReturn($currency)->once();
-
- $mapper = new CurrencyMapper();
- $mapper->setUser($this->user());
-
- $result = $mapper->map(null, ['symbol' => $currency->symbol]);
- $this->assertEquals($currency->id, $result->id);
- }
-
-}
diff --git a/tests/Unit/Support/Import/Routine/File/ImportableConverterTest.php b/tests/Unit/Support/Import/Routine/File/ImportableConverterTest.php
deleted file mode 100644
index 380b243d25..0000000000
--- a/tests/Unit/Support/Import/Routine/File/ImportableConverterTest.php
+++ /dev/null
@@ -1,576 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\Routine\File;
-
-
-use Amount;
-use Carbon\Carbon;
-use FireflyIII\Models\TransactionCurrency;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Support\Import\Placeholder\ImportTransaction;
-use FireflyIII\Support\Import\Routine\File\AssetAccountMapper;
-use FireflyIII\Support\Import\Routine\File\CurrencyMapper;
-use FireflyIII\Support\Import\Routine\File\ImportableConverter;
-use FireflyIII\Support\Import\Routine\File\OpposingAccountMapper;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * todo test foreign currency
- * todo test budget (known and unknown)
- * todo test category (known and unknown)
- * todo test foreign currency
- *
- * Class ImportableConverterTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ImportableConverterTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Basic test. Should match a withdrawal. Amount is negative.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
- */
- public function testBasic(): void
- {
- $nullAccount = ['name' => null, 'iban' => null, 'number' => null, 'bic' => null];
- $importable = new ImportTransaction;
- $importable->amount = '-45.67';
- $importable->date = '20180917';
- $importable->tags = ['a', 'b', 'c'];
- $importables = [$importable];
-
- $job = $this->user()->importJobs()->first();
- $job->configuration = [
- 'date-format' => 'Ymd',
- ];
- $job->save();
-
- // mock used classes:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $assetMapper = $this->mock(AssetAccountMapper::class);
- $opposingMapper = $this->mock(OpposingAccountMapper::class);
- $currencyMapper = $this->mock(CurrencyMapper::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
-
- $accountRepos->shouldReceive('setUser')->once();
-
- // get default currency
- $euro = $this->getEuro();
- $usd = $this->getDollar();
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
-
- // set user and config:
- $repository->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setUser')->once();
- $opposingMapper->shouldReceive('setUser')->once();
- $currencyMapper->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
-
- // respond to mapping call:
- $asset = $this->user()->accounts()->where('account_type_id', 3)->first();
- $expense = $this->user()->accounts()->where('account_type_id', 4)->first();
-
- $assetMapper->shouldReceive('map')->once()->withArgs([null, $nullAccount])->andReturn($asset);
- $opposingMapper->shouldReceive('map')->once()->withArgs([null, '-45.67', $nullAccount])->andReturn($expense);
- $currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn($usd);
- $currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
-
-
- $converter = new ImportableConverter;
- $converter->setImportJob($job);
- $result = $converter->convert($importables);
-
- // verify content of $result
- $this->assertEquals('withdrawal', $result[0]['transactions'][0]['type']);
- $this->assertEquals('2018-09-17 00:00:00', $result[0]['transactions'][0]['date']);
- $this->assertEquals($importable->tags, $result[0]['transactions'][0]['tags']);
- $this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
- }
-
- /**
- * Two asset accounts mean its a transfer.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
- */
- public function testBasicDefaultCurrency(): void
- {
- $nullAccount = ['name' => null, 'iban' => null, 'number' => null, 'bic' => null];
- $importable = new ImportTransaction;
- $importable->amount = '45.67';
- $importables = [$importable];
-
- $job = $this->user()->importJobs()->first();
- $job->configuration = [
- 'date-format' => 'Ymd',
- ];
- $job->save();
-
- // mock used classes:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $assetMapper = $this->mock(AssetAccountMapper::class);
- $opposingMapper = $this->mock(OpposingAccountMapper::class);
- $currencyMapper = $this->mock(CurrencyMapper::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $accountRepos->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->atLeast()->once()->andReturn('1');
-
- // get default currency
- $euro = TransactionCurrency::whereCode('EUR')->first();
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
-
- // set user and config:
- $repository->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setUser')->once();
- $opposingMapper->shouldReceive('setUser')->once();
- $currencyMapper->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
-
- // respond to mapping call:
- $asset = $this->user()->accounts()->where('account_type_id', 3)->first();
- $other = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $asset->id)->first();
-
- $assetMapper->shouldReceive('map')->atLeast()->once()->withArgs([null, $nullAccount])->andReturn($asset);
- $opposingMapper->shouldReceive('map')->atLeast()->once()->withArgs([null, '45.67', $nullAccount])->andReturn($other);
-
- $currencyMapper->shouldReceive('map')->atLeast()->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn(null);
- $currencyMapper->shouldReceive('map')->atLeast()->once()->withArgs([null, ['code' => null]])->andReturn(null);
- $currencyMapper->shouldReceive('map')->atLeast()->once()->withArgs([$euro->id, []])->andReturn($euro);
-
-
- $converter = new ImportableConverter;
- $converter->setImportJob($job);
- $result = $converter->convert($importables);
-
- // verify content of $result
- $today = new Carbon();
- $this->assertEquals('transfer', $result[0]['transactions'][0]['type']);
- $this->assertEquals($today->format('Y-m-d H:i:s'), $result[0]['transactions'][0]['date']);
- $this->assertEquals([], $result[0]['transactions'][0]['tags']);
- $this->assertEquals($euro->id, $result[0]['transactions'][0]['currency_id']);
- }
-
- /**
- * Positive amount, so transaction is a deposit.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
- */
- public function testBasicDeposit(): void
- {
- $nullAccount = ['name' => null, 'iban' => null, 'number' => null, 'bic' => null];
- $importable = new ImportTransaction;
- $importable->amount = '45.67';
- $importable->date = '20180917';
- $importable->meta['date-book'] = '20180102';
- $importables = [$importable];
-
- $job = $this->user()->importJobs()->first();
- $job->configuration = [
- 'date-format' => 'Ymd',
- ];
- $job->save();
-
- // mock used classes:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $assetMapper = $this->mock(AssetAccountMapper::class);
- $opposingMapper = $this->mock(OpposingAccountMapper::class);
- $currencyMapper = $this->mock(CurrencyMapper::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $accountRepos->shouldReceive('setUser')->once();
-
- // get default currency
- $euro = TransactionCurrency::whereCode('EUR')->first();
- $usd = TransactionCurrency::whereCode('USD')->first();
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
-
- // set user and config:
- $repository->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setUser')->once();
- $opposingMapper->shouldReceive('setUser')->once();
- $currencyMapper->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
-
- // respond to mapping call:
- $asset = $this->user()->accounts()->where('account_type_id', 3)->first();
- $revenue = $this->user()->accounts()->where('account_type_id', 5)->first();
-
- $assetMapper->shouldReceive('map')->atLeast()->once()->withArgs([null, $nullAccount])->andReturn($asset);
- $opposingMapper->shouldReceive('map')->atLeast()->once()->withArgs([null, '45.67', $nullAccount])->andReturn($revenue);
- $currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn($usd);
- $currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
-
-
- $converter = new ImportableConverter;
- $converter->setImportJob($job);
- $result = $converter->convert($importables);
-
- // verify content of $result
- $this->assertEquals('deposit', $result[0]['transactions'][0]['type']);
- $this->assertEquals('2018-09-17 00:00:00', $result[0]['transactions'][0]['date']);
- $this->assertEquals([], $result[0]['transactions'][0]['tags']);
- $this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
- $this->assertEquals($revenue->id, $result[0]['transactions'][0]['source_id']);
- $this->assertEquals($asset->id, $result[0]['transactions'][0]['destination_id']);
- $this->assertEquals('2018-01-02 00:00:00', $result[0]['transactions'][0]['book_date']);
-
- }
-
- /**
- * Source and destination are the same. Should result in error message.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
- */
- public function testBasicSameAssets(): void
- {
- $nullAccount = ['name' => null, 'iban' => null, 'number' => null, 'bic' => null];
- $importable = new ImportTransaction;
- $importable->amount = '-45.67';
- $importable->date = '20180917';
- $importables = [$importable];
-
- $job = $this->user()->importJobs()->first();
- $job->configuration = [
- 'date-format' => 'Ymd',
- ];
- $job->save();
-
- // mock used classes:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $assetMapper = $this->mock(AssetAccountMapper::class);
- $opposingMapper = $this->mock(OpposingAccountMapper::class);
- $currencyMapper = $this->mock(CurrencyMapper::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $accountRepos->shouldReceive('setUser')->once();
-
- // get default currency
- $euro = TransactionCurrency::whereCode('EUR')->first();
- $usd = TransactionCurrency::whereCode('USD')->first();
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
-
- // set user and config:
- $repository->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setUser')->once();
- $opposingMapper->shouldReceive('setUser')->once();
- $currencyMapper->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
-
- // respond to mapping call:
- $asset = $this->user()->accounts()->where('account_type_id', 3)->first();
-
- $assetMapper->shouldReceive('map')->atLeast()->once()->withArgs([null, $nullAccount])->andReturn($asset);
- $opposingMapper->shouldReceive('map')->atLeast()->once()->withArgs([null, '-45.67', $nullAccount])->andReturn($asset);
- $currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn($usd);
- $currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
- $repository->shouldReceive('addErrorMessage')->withArgs(
- [Mockery::any(),
- 'Row #1: Source ("' . $asset->name . '", #' . $asset->id . ') and destination ("' . $asset->name . '", #' . $asset->id . ') are the same account.']
- )->once();
-
- $converter = new ImportableConverter;
- $converter->setImportJob($job);
- $result = $converter->convert($importables);
- $this->assertEquals([], $result);
- }
-
- /**
- * Two asset accounts mean its a transfer. This has a positive amount.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
- */
- public function testBasicTransfer(): void
- {
- $nullAccount = ['name' => null, 'iban' => null, 'number' => null, 'bic' => null];
- $importable = new ImportTransaction;
- $importable->amount = '45.67';
- $importable->date = '20180917';
- $importable->billId = 2; // will NOT be ignored despite it's not valid.
- $importable->billName = 'Some Bill'; // will always be included even when bill ID is not valid.
- $importables = [$importable];
-
- $job = $this->user()->importJobs()->first();
- $job->configuration = [
- 'date-format' => 'Ymd',
- ];
- $job->save();
-
- // mock used classes:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $assetMapper = $this->mock(AssetAccountMapper::class);
- $opposingMapper = $this->mock(OpposingAccountMapper::class);
- $currencyMapper = $this->mock(CurrencyMapper::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $accountRepos->shouldReceive('setUser')->once();
-
- // get default currency
- $euro = TransactionCurrency::whereCode('EUR')->first();
- $usd = TransactionCurrency::whereCode('USD')->first();
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
-
- // set user and config:
- $repository->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setUser')->once();
- $opposingMapper->shouldReceive('setUser')->once();
- $currencyMapper->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
-
- // respond to mapping call:
- $asset = $this->user()->accounts()->where('account_type_id', 3)->first();
- $other = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $asset->id)->first();
-
- $assetMapper->shouldReceive('map')->atLeast()->once()->withArgs([null, $nullAccount])->andReturn($asset);
- $opposingMapper->shouldReceive('map')->atLeast()->once()->withArgs([null, '45.67', $nullAccount])->andReturn($other);
-
- $currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn($usd);
- $currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
-
-
- $converter = new ImportableConverter;
- $converter->setImportJob($job);
- $result = $converter->convert($importables);
-
- // verify content of $result
- $this->assertEquals('transfer', $result[0]['transactions'][0]['type']);
- $this->assertEquals('2018-09-17 00:00:00', $result[0]['transactions'][0]['date']);
- $this->assertEquals([], $result[0]['transactions'][0]['tags']);
- $this->assertEquals(2, $result[0]['transactions'][0]['bill_id']); // will NOT be ignored.
- $this->assertEquals($importable->billName, $result[0]['transactions'][0]['bill_name']);
- $this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
-
- // since amount is positive, $asset recieves the money
- $this->assertEquals($other->id, $result[0]['transactions'][0]['source_id']);
- $this->assertEquals($asset->id, $result[0]['transactions'][0]['destination_id']);
- }
-
- /**
- * Transfer with negative amount flows the other direction. See source_id and destination_id
- *
- * @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
- */
- public function testBasicTransferNegative(): void
- {
- $nullAccount = ['name' => null, 'iban' => null, 'number' => null, 'bic' => null];
- $importable = new ImportTransaction;
- $importable->amount = '-45.67';
- $importable->date = '20180917';
- $importable->billId = 3; // is added to array of valid values, see below.
- $importable->billName = 'Some bill'; // will be added even when ID is valid.
- $importables = [$importable];
-
- $validMappings = [
- 'bill-id' => [3],
- ];
-
- $job = $this->user()->importJobs()->first();
- $job->configuration = [
- 'date-format' => 'Ymd',
- ];
- $job->save();
-
- // mock used classes:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $assetMapper = $this->mock(AssetAccountMapper::class);
- $opposingMapper = $this->mock(OpposingAccountMapper::class);
- $currencyMapper = $this->mock(CurrencyMapper::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $accountRepos->shouldReceive('setUser')->once();
-
- // get default currency
- $euro = TransactionCurrency::whereCode('EUR')->first();
- $usd = TransactionCurrency::whereCode('USD')->first();
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
-
- // set user and config:
- $repository->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setUser')->once();
- $opposingMapper->shouldReceive('setUser')->once();
- $currencyMapper->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
-
- // respond to mapping call:
- $asset = $this->user()->accounts()->where('account_type_id', 3)->first();
- $other = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $asset->id)->first();
-
- $assetMapper->shouldReceive('map')->once()->withArgs([null, $nullAccount])->andReturn($asset);
- $opposingMapper->shouldReceive('map')->once()->withArgs([null, '-45.67', $nullAccount])->andReturn($other);
- $currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn($usd);
- $currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
-
-
- $converter = new ImportableConverter;
- $converter->setImportJob($job);
- $converter->setMappedValues($validMappings);
- $result = $converter->convert($importables);
-
- // verify content of $result
- $this->assertEquals('transfer', $result[0]['transactions'][0]['type']);
- $this->assertEquals('2018-09-17 00:00:00', $result[0]['transactions'][0]['date']);
- $this->assertEquals([], $result[0]['transactions'][0]['tags']);
- $this->assertEquals(3, $result[0]['transactions'][0]['bill_id']);
- $this->assertEquals($importable->billName, $result[0]['transactions'][0]['bill_name']);
- $this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
-
- // since amount is negative, $asset sends the money
- $this->assertEquals($asset->id, $result[0]['transactions'][0]['source_id']);
- $this->assertEquals($other->id, $result[0]['transactions'][0]['destination_id']);
- }
-
- /**
- * When source and dest are weird account types, will give error.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
- */
- public function testBasicWeirdAccounts(): void
- {
- $nullAccount = ['name' => null, 'iban' => null, 'number' => null, 'bic' => null];
- $importable = new ImportTransaction;
- $importable->amount = '-45.67';
- $importable->date = '20180917';
- $importables = [$importable];
-
- $job = $this->user()->importJobs()->first();
- $job->configuration = [
- 'date-format' => 'Ymd',
- ];
- $job->save();
-
- // mock used classes:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $assetMapper = $this->mock(AssetAccountMapper::class);
- $opposingMapper = $this->mock(OpposingAccountMapper::class);
- $currencyMapper = $this->mock(CurrencyMapper::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $accountRepos->shouldReceive('setUser')->once();
-
- // get default currency
- $euro = TransactionCurrency::whereCode('EUR')->first();
- $usd = TransactionCurrency::whereCode('USD')->first();
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
-
- // set user and config:
- $repository->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setUser')->once();
- $opposingMapper->shouldReceive('setUser')->once();
- $currencyMapper->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
-
- // respond to mapping call:
- $asset = $this->user()->accounts()->where('account_type_id', 6)->first();
- $other = $this->user()->accounts()->where('account_type_id', 2)->where('id', '!=', $asset)->first();
-
- $assetMapper->shouldReceive('map')->once()->withArgs([null, $nullAccount])->andReturn($asset);
- $opposingMapper->shouldReceive('map')->once()->withArgs([null, '-45.67', $nullAccount])->andReturn($other);
- $currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn($usd);
- $currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
- $repository->shouldReceive('addErrorMessage')->withArgs(
- [Mockery::any(), 'Row #1: Cannot determine transaction type. Source account is a Initial balance account, destination is a Cash account']
- )->once();
-
- $converter = new ImportableConverter;
- $converter->setImportJob($job);
- $result = $converter->convert($importables);
- $this->assertEquals([], $result);
- }
-
- /**
- * Submit no amount information.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
- */
- public function testEmpty(): void
- {
-
- $job = $this->user()->importJobs()->first();
- $job->configuration = [];
- $job->save();
-
- // mock used classes:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $assetMapper = $this->mock(AssetAccountMapper::class);
- $opposingMapper = $this->mock(OpposingAccountMapper::class);
- $currencyMapper = $this->mock(CurrencyMapper::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $accountRepos->shouldReceive('setUser')->once();
-
- $euro = TransactionCurrency::whereCode('EUR')->first();
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
- $repository->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setUser')->once();
- $opposingMapper->shouldReceive('setUser')->once();
- $currencyMapper->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
-
- $converter = new ImportableConverter;
- $converter->setImportJob($job);
- }
-
- /**
- * Basic input until it stops crashing.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
- */
- public function testNoAmount(): void
- {
- $importable = new ImportTransaction;
- $importables = [$importable];
- $job = $this->user()->importJobs()->first();
- $job->configuration = [];
- $job->save();
-
- // mock used classes:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $assetMapper = $this->mock(AssetAccountMapper::class);
- $opposingMapper = $this->mock(OpposingAccountMapper::class);
- $currencyMapper = $this->mock(CurrencyMapper::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $accountRepos->shouldReceive('setUser')->once();
-
- $euro = TransactionCurrency::whereCode('EUR')->first();
- Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
- $repository->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setUser')->once();
- $opposingMapper->shouldReceive('setUser')->once();
- $currencyMapper->shouldReceive('setUser')->once();
- $assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
- $repository->shouldReceive('addErrorMessage')->withArgs([Mockery::any(), 'Row #1: No transaction amount information.'])->once();
-
- $converter = new ImportableConverter;
- $converter->setImportJob($job);
- $result = $converter->convert($importables);
- $this->assertEquals([], $result);
- }
-
-}
diff --git a/tests/Unit/Support/Import/Routine/File/ImportableCreatorTest.php b/tests/Unit/Support/Import/Routine/File/ImportableCreatorTest.php
deleted file mode 100644
index c592bddbda..0000000000
--- a/tests/Unit/Support/Import/Routine/File/ImportableCreatorTest.php
+++ /dev/null
@@ -1,77 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\Routine\File;
-
-
-use FireflyIII\Support\Import\Placeholder\ColumnValue;
-use FireflyIII\Support\Import\Placeholder\ImportTransaction;
-use FireflyIII\Support\Import\Routine\File\ImportableCreator;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class ImportableCreatorTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class ImportableCreatorTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\File\ImportableCreator
- */
- public function testConvertSets(): void
- {
- $columnValue = new ColumnValue();
- $columnValue->setOriginalRole('account-name');
- $columnValue->setRole('account-id');
- $columnValue->setValue('Checking Account');
- $columnValue->setMappedValue(1);
-
- $input = [
- [
- $columnValue,
- ],
- ];
-
-
- $creator = new ImportableCreator;
- $result = $creator->convertSets($input);
-
- $this->assertCount(1, $result);
- $this->assertInstanceOf(ImportTransaction::class, $result[0]);
- $this->assertEquals(1, $result[0]->accountId);
-
- }
-
-}
diff --git a/tests/Unit/Support/Import/Routine/File/LineReaderTest.php b/tests/Unit/Support/Import/Routine/File/LineReaderTest.php
deleted file mode 100644
index ccc3a07e70..0000000000
--- a/tests/Unit/Support/Import/Routine/File/LineReaderTest.php
+++ /dev/null
@@ -1,115 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\Routine\File;
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
-use FireflyIII\Import\Specifics\IngDescription;
-use FireflyIII\Models\Attachment;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Support\Import\Routine\File\LineReader;
-use Illuminate\Support\Collection;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class LineReaderTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class LineReaderTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\File\LineReader
- */
- public function testGetLines(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'linerA' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = [
- 'specifics' => [
- 'IngDescription' => 1,
- 'BadSpecific' => 1,
- ],
- 'has-headers' => true,
- 'delimiter' => ',',
- ];
- $job->save();
-
- $att = new Attachment;
- $att->filename = 'import_file';
- $att->user_id = $this->user()->id;
- $att->attachable_id = $job->id;
- $att->attachable_type = ImportJob::class;
- $att->md5 = md5('hello');
- $att->mime = 'fake';
- $att->size = 3;
- $att->save();
-
- // mock repositories:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $attachments = $this->mock(AttachmentHelperInterface::class);
- $specific = $this->mock(IngDescription::class);
-
- // fake file content:
- $content = "header1,header2,header3\ncolumn1,column2,column3\nA,B,C";
- $specifics = [['column1', 'column2', 'column3'], ['A', 'B', 'C']];
-
- // mock calls and returns:
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('getAttachments')->once()->andReturn(new Collection([$att]));
- $attachments->shouldReceive('getAttachmentContent')->andReturn($content)->once();
- $repository->shouldReceive('getConfiguration')->once()->andReturn($job->configuration);
-
- // expect the rows to be run throught the specific.
- $specific->shouldReceive('run')->withArgs([$specifics[0]])->andReturn($specifics[0])->once();
- $specific->shouldReceive('run')->withArgs([$specifics[1]])->andReturn($specifics[1])->once();
-
- $lineReader = new LineReader;
- $lineReader->setImportJob($job);
- try {
- $lines = $lineReader->getLines();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals($specifics, $lines);
- }
-
-}
diff --git a/tests/Unit/Support/Import/Routine/File/MappedValuesValidatorTest.php b/tests/Unit/Support/Import/Routine/File/MappedValuesValidatorTest.php
deleted file mode 100644
index 61be3d5aa2..0000000000
--- a/tests/Unit/Support/Import/Routine/File/MappedValuesValidatorTest.php
+++ /dev/null
@@ -1,140 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\Routine\File;
-
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Bill\BillRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Support\Import\Routine\File\MappedValuesValidator;
-use Illuminate\Support\Collection;
-use Log;
-use stdClass;
-use Tests\TestCase;
-
-/**
- * Class MappedValuesValidatorTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class MappedValuesValidatorTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\File\MappedValuesValidator
- */
- public function testValidateBasic(): void
- {
-
- $toValidate = [
- 'opposing-id' => [1, 2, 3],
- 'account-id' => [4, 5, 6],
- 'currency-id' => [7, 8, 9],
- 'foreign-currency-id' => [10, 11, 12],
- 'bill-id' => [13, 14, 15],
- 'budget-id' => [16, 17, 18],
- 'category-id' => [19, 20, 21],
- ];
- $return = [
- 'opposing-id' => new Collection([$this->objectWithId(1), $this->objectWithId(2)]),
- 'account-id' => new Collection([$this->objectWithId(4), $this->objectWithId(5)]),
- 'currency-id' => new Collection([$this->objectWithId(7), $this->objectWithId(9)]),
- 'foreign-currency-id' => new Collection([$this->objectWithId(10), $this->objectWithId(11)]),
- 'bill-id' => new Collection([$this->objectWithId(13), $this->objectWithId(15)]),
- 'budget-id' => new Collection([$this->objectWithId(16), $this->objectWithId(17)]),
- 'category-id' => new Collection([$this->objectWithId(19), $this->objectWithId(21)]),
- ];
- // mock stuff:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $billRepos = $this->mock(BillRepositoryInterface::class);
- $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
- $catRepos = $this->mock(CategoryRepositoryInterface::class);
-
- // should receive a lot of stuff:
- $repository->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('setUser')->once();
- $currencyRepos->shouldReceive('setUser')->once();
- $billRepos->shouldReceive('setUser')->once();
- $budgetRepos->shouldReceive('setUser')->once();
- $catRepos->shouldReceive('setUser')->once();
-
- $accountRepos->shouldReceive('getAccountsById')->once()->withArgs([$toValidate['account-id']])->andReturn($return['account-id']);
- $accountRepos->shouldReceive('getAccountsById')->once()->withArgs([$toValidate['opposing-id']])->andReturn($return['opposing-id']);
- $currencyRepos->shouldReceive('getByIds')->once()->withArgs([$toValidate['currency-id']])->andReturn($return['currency-id']);
- $currencyRepos->shouldReceive('getByIds')->once()->withArgs([$toValidate['foreign-currency-id']])->andReturn($return['foreign-currency-id']);
- $billRepos->shouldReceive('getByIds')->once()->withArgs([$toValidate['bill-id']])->andReturn($return['bill-id']);
- $budgetRepos->shouldReceive('getByIds')->once()->withArgs([$toValidate['budget-id']])->andReturn($return['budget-id']);
- $catRepos->shouldReceive('getByIds')->once()->withArgs([$toValidate['category-id']])->andReturn($return['category-id']);
-
-
- $expected = [
- 'opposing-id' => [1, 2],
- 'account-id' => [4, 5],
- 'currency-id' => [7, 9],
- 'foreign-currency-id' => [10, 11],
- 'bill-id' => [13, 15],
- 'budget-id' => [16, 17],
- 'category-id' => [19, 21],
- ];
- $validator = new MappedValuesValidator;
- $validator->setImportJob($this->user()->importJobs()->first());
-
- try {
- $result = $validator->validate($toValidate);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- $this->assertEquals($expected, $result);
-
- }
-
- /**
- * @param int $objectId
- *
- * @return stdClass
- */
- private function objectWithId(int $objectId): stdClass
- {
- $obj = new stdClass();
- $obj->id = $objectId;
-
- return $obj;
- }
-
-}
diff --git a/tests/Unit/Support/Import/Routine/File/MappingConvergerTest.php b/tests/Unit/Support/Import/Routine/File/MappingConvergerTest.php
deleted file mode 100644
index 9986351cbb..0000000000
--- a/tests/Unit/Support/Import/Routine/File/MappingConvergerTest.php
+++ /dev/null
@@ -1,169 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\Routine\File;
-
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Support\Import\Routine\File\MappingConverger;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class MappingConvergerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class MappingConvergerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\File\MappingConverger
- */
- public function testConverge(): void
- {
- $jobRepos = $this->mock(ImportJobRepositoryInterface::class);
- $jobRepos->shouldReceive('setUser')->once();
- // configuration
- $config = [
- 'column-roles' => [
- 0 => 'account-name',
- 1 => 'bill-name',
- 2 => 'budget-name',
- 3 => 'currency-code',
- 4 => 'category-name',
- 5 => 'foreign-currency-code',
- 6 => 'opposing-number',
- 7 => 'description',
- 8 => 'opposing-iban',
- ],
- 'column-mapping-config' => [
- 0 => [
- 'Checking Account' => 1,
- ],
- 1 => [
- 'BillX' => 2,
- ],
- 2 => [
- 'BudgetX' => 2,
- ],
- 3 => [
- 'EUR' => 7,
- ],
- 4 => [
- 'CategoryX' => 2,
- ],
- 5 => [
- 'USD' => 4,
- ],
- 6 => [
- 'SomeNumber' => 3,
- ],
- 8 => [
- 'IBANX' => 2,
- ],
- ],
- 'column-do-mapping' => [
- 0 => true,
- 1 => true,
- 2 => true,
- 3 => true,
- 4 => true,
- 5 => true,
- 6 => true,
- 7 => false,
- 8 => false,
- ],
- ];
-
- // just one line to process (should hit everything).
- $lines = [
- [
- 0 => 'Checking Account',
- 1 => 'BillX',
- 2 => 'BudgetX',
- 3 => 'EUR',
- 4 => 'CategoryX',
- 5 => 'USD',
- 6 => 'SomeNumber',
- 7 => 'I am a description',
- 8 => 'IBANX',
- ],
- [
- 0 => 'CheckingX Account',
- 1 => 'BillXA',
- 2 => 'BudgetBX',
- 3 => 'EUD',
- 4 => 'CategoryX',
- 5 => 'USA',
- 6 => 'SomeANumber',
- 7 => 'I am X description',
- 8 => 'IBANXX',
- ],
- ];
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'linerB' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'fake';
- $job->file_type = '';
- $job->configuration = $config;
- $job->save();
-
-
- $converger = new MappingConverger;
- $converger->setImportJob($job);
- try {
- $result = $converger->converge($lines);
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- // do some comparing, we know what to expect.
-
- // line 0, column 0 is the account name.
- $this->assertEquals($lines[0][0], $result[0][0]->getValue());
- $this->assertEquals($config['column-roles'][0], $result[0][0]->getOriginalRole());
- $this->assertEquals('account-id', $result[0][0]->getRole()); // role changed due to mapping.
- $this->assertEquals(1, $result[0][0]->getMappedValue()); // can see which value it was given.
-
- // line 1, column 0 is the account name, but it could not be mapped.
- $this->assertEquals($lines[1][0], $result[1][0]->getValue());
- $this->assertEquals($config['column-roles'][0], $result[1][0]->getOriginalRole());
- $this->assertEquals($config['column-roles'][0], $result[1][0]->getRole()); // role did not change, no mapping.
- $this->assertEquals(0, $result[1][0]->getMappedValue()); // value of mapping is 0.
- }
-
-}
diff --git a/tests/Unit/Support/Import/Routine/File/OpposingAccountMapperTest.php b/tests/Unit/Support/Import/Routine/File/OpposingAccountMapperTest.php
deleted file mode 100644
index 8d6618350e..0000000000
--- a/tests/Unit/Support/Import/Routine/File/OpposingAccountMapperTest.php
+++ /dev/null
@@ -1,242 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\Routine\File;
-
-
-use FireflyIII\Models\Account;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Support\Import\Routine\File\OpposingAccountMapper;
-use Log;
-use Tests\TestCase;
-
-/**
- * Class OpposingAccountMapperTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class OpposingAccountMapperTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- *
- * Should return account with given ID (which is of correct type).
- *
- * @covers \FireflyIII\Support\Import\Routine\File\OpposingAccountMapper
- */
- public function testAccountId(): void
- {
- $expected = $this->user()->accounts()->where('account_type_id', 4)->inRandomOrder()->first();
- $amount = '-12.34';
- $repository = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findNull')->andReturn($expected)->once();
- $mapper = new OpposingAccountMapper;
- $mapper->setUser($this->user());
- $mapper->map(1, $amount, []);
- }
-
- /**
- *
- * Should return account with given ID (which is of wrong account type).
- * Will continue the search or store a revenue account with that name.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\OpposingAccountMapper
- */
- public function testAccountIdBadType(): void
- {
- $expected = $this->getRandomRevenue();
- $expected->iban = null;
- $expected->save();
- $amount = '-12.34';
- $expectedArgs = [
- 'name' => $expected->name,
- 'iban' => null,
- 'account_number' => null,
- 'account_type_id' => null,
- 'account_type' => AccountType::EXPENSE,
- 'active' => true,
- 'BIC' => null,
- ];
- $repository = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findNull')->andReturn($expected)->once();
- $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::EXPENSE]])->andReturnNull();
- $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::ASSET]])->andReturnNull();
- $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::DEBT]])->andReturnNull();
- $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::MORTGAGE]])->andReturnNull();
- $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::LOAN]])->andReturnNull();
- $repository->shouldReceive('store')->withArgs([$expectedArgs])->once()
- ->andReturn(new Account);
-
-
- $mapper = new OpposingAccountMapper;
- $mapper->setUser($this->user());
- $mapper->map(1, $amount, []);
- }
-
- /**
- *
- * Should return account with given ID (which is of wrong account type).
- * Will continue the search or store a revenue account with that name.
- *
- * @covers \FireflyIII\Support\Import\Routine\File\OpposingAccountMapper
- */
- public function testAccountIdBadTypeIban(): void
- {
- $expected = $this->user()->accounts()->where('account_type_id', 5)->inRandomOrder()->first();
- $expected->iban = 'AD1200012030200359100100';
- $expected->save();
-
- $amount = '-12.34';
- $expectedArgs = [
- 'name' => $expected->name,
- 'iban' => $expected->iban,
- 'account_number' => null,
- 'account_type_id' => null,
- 'account_type' => AccountType::EXPENSE,
- 'active' => true,
- 'BIC' => null,
- ];
- $repository = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findNull')->andReturn($expected)->once();
- $repository->shouldReceive('findByIbanNull')->withArgs([$expected->iban, [AccountType::EXPENSE]])->andReturnNull();
- $repository->shouldReceive('findByIbanNull')->withArgs([$expected->iban, [AccountType::ASSET]])->andReturnNull();
- $repository->shouldReceive('findByIbanNull')->withArgs([$expected->iban, [AccountType::DEBT]])->andReturnNull();
- $repository->shouldReceive('findByIbanNull')->withArgs([$expected->iban, [AccountType::MORTGAGE]])->andReturnNull();
- $repository->shouldReceive('findByIbanNull')->withArgs([$expected->iban, [AccountType::LOAN]])->andReturnNull();
-
- $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::EXPENSE]])->andReturnNull();
- $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::ASSET]])->andReturnNull();
- $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::DEBT]])->andReturnNull();
- $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::MORTGAGE]])->andReturnNull();
- $repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::LOAN]])->andReturnNull();
- $repository->shouldReceive('store')->withArgs([$expectedArgs])->once()
- ->andReturn(new Account);
-
-
- $mapper = new OpposingAccountMapper;
- $mapper->setUser($this->user());
- $mapper->map(1, $amount, []);
- }
-
- /**
- * Amount = negative
- * ID = null
- * other data = null
- * Should call store() with "(no name") for expense account
- *
- * @covers \FireflyIII\Support\Import\Routine\File\OpposingAccountMapper
- */
- public function testBasic(): void
- {
- $amount = '-12.34';
- $expectedArgs = [
- 'name' => '(no name)',
- 'iban' => null,
- 'account_number' => null,
- 'account_type_id' => null,
- 'account_type' => AccountType::EXPENSE,
- 'active' => true,
- 'BIC' => null,
- ];
-
- $repository = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('store')->withArgs([$expectedArgs])->once()
- ->andReturn(new Account);
-
-
- $mapper = new OpposingAccountMapper;
- $mapper->setUser($this->user());
- $mapper->map(null, $amount, []);
- }
-
- /**
- * Amount = positive
- * ID = null
- * other data = null
- * Should call store() with "(no name") for revenue account
- *
- * @covers \FireflyIII\Support\Import\Routine\File\OpposingAccountMapper
- */
- public function testBasicPos(): void
- {
- $amount = '12.34';
- $expectedArgs = [
- 'name' => '(no name)',
- 'iban' => null,
- 'account_number' => null,
- 'account_type_id' => null,
- 'account_type' => AccountType::REVENUE,
- 'active' => true,
- 'BIC' => null,
- ];
-
- $repository = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('store')->withArgs([$expectedArgs])->once()
- ->andReturn(new Account);
-
-
- $mapper = new OpposingAccountMapper;
- $mapper->setUser($this->user());
- $mapper->map(null, $amount, []);
- }
-
- /**
- * Amount = negative
- * ID = null
- * other data = null
- * Should call store() with "(no name") for expense account
- *
- * @covers \FireflyIII\Support\Import\Routine\File\OpposingAccountMapper
- */
- public function testFindByAccountNumber(): void
- {
- $expected = $this->user()->accounts()->where('account_type_id', 4)->inRandomOrder()->first();
- $amount = '-12.34';
- $repository = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('findByAccountNumber')->withArgs(['12345', [AccountType::EXPENSE]])
- ->andReturn($expected)->once();
-
-
- $mapper = new OpposingAccountMapper;
- $mapper->setUser($this->user());
- $result = $mapper->map(null, $amount, ['number' => '12345']);
- $this->assertEquals($result->id, $expected->id);
- }
-
-}
diff --git a/tests/Unit/Support/Import/Routine/Spectre/StageAuthenticatedHandlerTest.php b/tests/Unit/Support/Import/Routine/Spectre/StageAuthenticatedHandlerTest.php
deleted file mode 100644
index e0b6d2164e..0000000000
--- a/tests/Unit/Support/Import/Routine/Spectre/StageAuthenticatedHandlerTest.php
+++ /dev/null
@@ -1,463 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\Routine\Spectre;
-
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Services\Spectre\Object\Account as SpectreAccount;
-use FireflyIII\Services\Spectre\Object\Attempt;
-use FireflyIII\Services\Spectre\Object\Holder;
-use FireflyIII\Services\Spectre\Object\Login;
-use FireflyIII\Services\Spectre\Request\ListAccountsRequest;
-use FireflyIII\Services\Spectre\Request\ListLoginsRequest;
-use FireflyIII\Support\Import\Routine\Spectre\StageAuthenticatedHandler;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class StageAuthenticatedHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class StageAuthenticatedHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * Already have logins in configuration.
- *
- * @covers \FireflyIII\Support\Import\Routine\Spectre\StageAuthenticatedHandler
- */
- public function testRunBasicHaveLogins(): void
- {
- // fake login:
- $holder = new Holder([]);
- $attempt = new Attempt(
- [
- 'api_mode' => 'x',
- 'api_version' => 4,
- 'automatic_fetch' => true,
- 'categorize' => true,
- 'created_at' => '2018-05-21 12:00:00',
- 'consent_given_at' => '2018-05-21 12:00:00',
- 'consent_types' => ['transactions'],
- 'custom_fields' => [],
- 'daily_refresh' => true,
- 'device_type' => 'mobile',
- 'user_agent' => 'Mozilla/x',
- 'remote_ip' => '127.0.0.1',
- 'exclude_accounts' => [],
- 'fail_at' => '2018-05-21 12:00:00',
- 'fail_error_class' => 'err',
- 'fail_message' => 'message',
- 'fetch_scopes' => [],
- 'finished' => true,
- 'finished_recent' => true,
- 'from_date' => '2018-05-21 12:00:00',
- 'id' => 1,
- 'interactive' => true,
- 'locale' => 'en',
- 'partial' => true,
- 'show_consent_confirmation' => true,
- 'stages' => [],
- 'store_credentials' => true,
- 'success_at' => '2018-05-21 12:00:00',
- 'to_date' => '2018-05-21 12:00:00',
- 'updated_at' => '2018-05-21 12:00:00',
- ]
- );
- $login = new Login(
- [
- 'consent_given_at' => '2018-05-21 12:00:00',
- 'consent_types' => ['transactions'],
- 'country_code' => 'NL',
- 'created_at' => '2018-05-21 12:00:00',
- 'updated_at' => '2018-05-21 12:00:00',
- 'customer_id' => '1',
- 'daily_refresh' => true,
- 'holder_info' => $holder->toArray(),
- 'id' => 1234,
- 'last_attempt' => $attempt->toArray(),
- 'last_success_at' => '2018-05-21 12:00:00',
- 'next_refresh_possible_at' => '2018-05-21 12:00:00',
- 'provider_code' => 'XF',
- 'provider_id' => '123',
- 'provider_name' => 'Fake',
- 'show_consent_confirmation' => true,
- 'status' => 'active',
- 'store_credentials' => true,
- ]
- );
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sa_a_' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [
- 'all-logins' => [
- $login->toArray(),
- ],
- 'selected-login' => 1234,
- ];
- $job->save();
-
- // needs to be a full spectre account this time.
- $spectreAccount = new SpectreAccount(
- [
- 'id' => 1234,
- 'login_id' => 5678,
- 'currency_code' => 'EUR',
- 'balance' => 1000,
- 'name' => 'Fake Spectre Account',
- 'nature' => 'account',
- 'created_at' => '2018-01-01 12:12:12',
- 'updated_at' => '2018-01-01 12:12:12',
- 'extra' => [],
- ]
- );
-
- // mock repository:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $laRequest = $this->mock(ListAccountsRequest::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $laRequest->shouldReceive('setUser')->once();
- $laRequest->shouldReceive('setLogin')->withArgs([Mockery::any()])->once();
- $laRequest->shouldReceive('call')->once();
- $laRequest->shouldReceive('getAccounts')->once()->andReturn([$spectreAccount]);
-
- $expected = [
- 'all-logins' => [
- $login->toArray(),
- ],
- 'selected-login' => 1234,
- 'accounts' => [
- 0 => $spectreAccount->toArray(),
- ],
- ];
-
- $repository->shouldReceive('setConfiguration')
- ->withArgs([Mockery::any(), $expected])->once();
-
- $handler = new StageAuthenticatedHandler;
- $handler->setImportJob($job);
- try {
- $handler->run();
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
- /**
- * Already have logins in configuration, but none selected.
- *
- * @covers \FireflyIII\Support\Import\Routine\Spectre\StageAuthenticatedHandler
- */
- public function testRunBasicHaveLoginsNull(): void
- {
- // fake login:
- $holder = new Holder([]);
- $attempt = new Attempt(
- [
- 'api_mode' => 'x',
- 'api_version' => 4,
- 'automatic_fetch' => true,
- 'categorize' => true,
- 'created_at' => '2018-05-21 12:00:00',
- 'consent_given_at' => '2018-05-21 12:00:00',
- 'consent_types' => ['transactions'],
- 'custom_fields' => [],
- 'daily_refresh' => true,
- 'device_type' => 'mobile',
- 'user_agent' => 'Mozilla/x',
- 'remote_ip' => '127.0.0.1',
- 'exclude_accounts' => [],
- 'fail_at' => '2018-05-21 12:00:00',
- 'fail_error_class' => 'err',
- 'fail_message' => 'message',
- 'fetch_scopes' => [],
- 'finished' => true,
- 'finished_recent' => true,
- 'from_date' => '2018-05-21 12:00:00',
- 'id' => 1,
- 'interactive' => true,
- 'locale' => 'en',
- 'partial' => true,
- 'show_consent_confirmation' => true,
- 'stages' => [],
- 'store_credentials' => true,
- 'success_at' => '2018-05-21 12:00:00',
- 'to_date' => '2018-05-21 12:00:00',
- 'updated_at' => '2018-05-21 12:00:00',
- ]
- );
- $login = new Login(
- [
- 'consent_given_at' => '2018-05-21 12:00:00',
- 'consent_types' => ['transactions'],
- 'country_code' => 'NL',
- 'created_at' => '2018-05-21 12:00:00',
- 'updated_at' => '2018-05-21 12:00:00',
- 'customer_id' => '1',
- 'daily_refresh' => true,
- 'holder_info' => $holder->toArray(),
- 'id' => 1234,
- 'last_attempt' => $attempt->toArray(),
- 'last_success_at' => '2018-05-21 12:00:00',
- 'next_refresh_possible_at' => '2018-05-21 12:00:00',
- 'provider_code' => 'XF',
- 'provider_id' => '123',
- 'provider_name' => 'Fake',
- 'show_consent_confirmation' => true,
- 'status' => 'active',
- 'store_credentials' => true,
- ]
- );
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sa_a_' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [
- 'all-logins' => [
- $login->toArray(),
- ],
- 'selected-login' => 0,
- ];
- $job->save();
-
- // needs to be a full spectre account this time.
- $spectreAccount = new SpectreAccount(
- [
- 'id' => 1234,
- 'login_id' => 5678,
- 'currency_code' => 'EUR',
- 'balance' => 1000,
- 'name' => 'Fake Spectre Account',
- 'nature' => 'account',
- 'created_at' => '2018-01-01 12:12:12',
- 'updated_at' => '2018-01-01 12:12:12',
- 'extra' => [],
- ]
- );
-
- // mock repository:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $laRequest = $this->mock(ListAccountsRequest::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $laRequest->shouldReceive('setUser')->once();
- $laRequest->shouldReceive('setLogin')->withArgs([Mockery::any()])->once();
- $laRequest->shouldReceive('call')->once();
- $laRequest->shouldReceive('getAccounts')->once()->andReturn([$spectreAccount]);
-
- $expected = [
- 'all-logins' => [
- $login->toArray(),
- ],
- 'selected-login' => 0,
- 'accounts' => [
- 0 => $spectreAccount->toArray(),
- ],
- ];
-
- $repository->shouldReceive('setConfiguration')
- ->withArgs([Mockery::any(), $expected])->once();
-
- $handler = new StageAuthenticatedHandler;
- $handler->setImportJob($job);
- try {
- $handler->run();
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
- /**
- * No logins in config, will grab them from Spectre.
- *
- * @covers \FireflyIII\Support\Import\Routine\Spectre\StageAuthenticatedHandler
- */
- public function testRunBasicZeroLogins(): void
- {
- // fake login:
- $holder = new Holder([]);
- $attempt = new Attempt(
- [
- 'api_mode' => 'x',
- 'api_version' => 4,
- 'automatic_fetch' => true,
- 'categorize' => true,
- 'created_at' => '2018-05-21 12:00:00',
- 'consent_given_at' => '2018-05-21 12:00:00',
- 'consent_types' => ['transactions'],
- 'custom_fields' => [],
- 'daily_refresh' => true,
- 'device_type' => 'mobile',
- 'user_agent' => 'Mozilla/x',
- 'remote_ip' => '127.0.0.1',
- 'exclude_accounts' => [],
- 'fail_at' => '2018-05-21 12:00:00',
- 'fail_error_class' => 'err',
- 'fail_message' => 'message',
- 'fetch_scopes' => [],
- 'finished' => true,
- 'finished_recent' => true,
- 'from_date' => '2018-05-21 12:00:00',
- 'id' => 1,
- 'interactive' => true,
- 'locale' => 'en',
- 'partial' => true,
- 'show_consent_confirmation' => true,
- 'stages' => [],
- 'store_credentials' => true,
- 'success_at' => '2018-05-21 12:00:00',
- 'to_date' => '2018-05-21 12:00:00',
- 'updated_at' => '2018-05-21 12:00:00',
- ]
- );
- $login = new Login(
- [
- 'consent_given_at' => '2018-05-21 12:00:00',
- 'consent_types' => ['transactions'],
- 'country_code' => 'NL',
- 'created_at' => '2018-05-21 12:00:00',
- 'updated_at' => '2018-05-21 12:00:00',
- 'customer_id' => '1',
- 'daily_refresh' => true,
- 'holder_info' => $holder->toArray(),
- 'id' => 1234,
- 'last_attempt' => $attempt->toArray(),
- 'last_success_at' => '2018-05-21 12:00:00',
- 'next_refresh_possible_at' => '2018-05-21 12:00:00',
- 'provider_code' => 'XF',
- 'provider_id' => '123',
- 'provider_name' => 'Fake',
- 'show_consent_confirmation' => true,
- 'status' => 'active',
- 'store_credentials' => true,
- ]
- );
-
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sa_a_' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [
- 'all-logins' => [],
- 'selected-login' => 0,
- ];
- $job->save();
-
- // needs to be a full spectre account this time.
- $spectreAccount = new SpectreAccount(
- [
- 'id' => 1234,
- 'login_id' => 5678,
- 'currency_code' => 'EUR',
- 'balance' => 1000,
- 'name' => 'Fake Spectre Account',
- 'nature' => 'account',
- 'created_at' => '2018-01-01 12:12:12',
- 'updated_at' => '2018-01-01 12:12:12',
- 'extra' => [],
- ]
- );
- // mock preference
- $fakeCustomerPreference = new Preference;
- $fakeCustomerPreference->name = 'spectre_customer';
- $fakeCustomerPreference->data = [
- 'id' => 1,
- 'identifier' => 'fake',
- 'secret' => 'Dumbledore dies',
- ];
-
- // mock call for preferences
- Preferences::shouldReceive('getForUser')->once()->withArgs([Mockery::any(), 'spectre_customer', null])->andReturn($fakeCustomerPreference);
-
- // mock repository:
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $laRequest = $this->mock(ListAccountsRequest::class);
- $llRequest = $this->mock(ListLoginsRequest::class);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once();
- $laRequest->shouldReceive('setUser')->once();
- $laRequest->shouldReceive('setLogin')->withArgs([Mockery::any()])->once();
- $laRequest->shouldReceive('call')->once();
- $laRequest->shouldReceive('getAccounts')->once()->andReturn([$spectreAccount]);
-
- // mock calls for list logins (return empty list for now).
- $llRequest->shouldReceive('setUser')->once();
- $llRequest->shouldReceive('setCustomer')->once();
- $llRequest->shouldReceive('call')->once();
- $llRequest->shouldReceive('getLogins')->once()->andReturn([$login]);
-
- $expected = [
- 'all-logins' => [
- $login->toArray(),
- ],
- 'selected-login' => 0,
- 'accounts' => [
- 0 => $spectreAccount->toArray(),
- ],
- ];
-
- $repository->shouldReceive('setConfiguration')
- ->withArgs([Mockery::any(), $expected])->once();
-
- $handler = new StageAuthenticatedHandler;
- $handler->setImportJob($job);
- try {
- $handler->run();
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
-}
diff --git a/tests/Unit/Support/Import/Routine/Spectre/StageImportDataHandlerTest.php b/tests/Unit/Support/Import/Routine/Spectre/StageImportDataHandlerTest.php
deleted file mode 100644
index 9164c81862..0000000000
--- a/tests/Unit/Support/Import/Routine/Spectre/StageImportDataHandlerTest.php
+++ /dev/null
@@ -1,643 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\Routine\Spectre;
-
-
-use Carbon\Carbon;
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Services\Spectre\Object\Account as SpectreAccount;
-use FireflyIII\Services\Spectre\Object\Transaction as SpectreTransaction;
-use FireflyIII\Services\Spectre\Request\ListTransactionsRequest;
-use FireflyIII\Support\Import\Routine\File\OpposingAccountMapper;
-use FireflyIII\Support\Import\Routine\Spectre\StageImportDataHandler;
-use Log;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class StageImportDataHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class StageImportDataHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\Spectre\StageImportDataHandler
- */
- public function testRunBasic(): void
- {
- // needs to be a full spectre account this time.
- $spectreAccount = new SpectreAccount(
- [
- 'id' => 1234,
- 'login_id' => 5678,
- 'currency_code' => 'EUR',
- 'balance' => 1000,
- 'name' => 'Fake Spectre Account',
- 'nature' => 'account',
- 'created_at' => '2018-01-01 12:12:12',
- 'updated_at' => '2018-01-01 12:12:12',
- 'extra' => [],
- ]
- );
-
- $today = new Carbon;
- // create fake transactions:
- $op1 = 'Some opposing account #' . $this->randomInt();
- $op2 = 'Some opposing revenue account #' . $this->randomInt();
- $transactions = [
- new SpectreTransaction(
- [
- 'id' => 1,
- 'mode' => 'mode',
- 'status' => 'active',
- 'made_on' => $today->toW3cString(),
- 'amount' => -123.45,
- 'currency_code' => 'EUR',
- 'description' => 'Fake description #' . $this->randomInt(),
- 'category' => 'some-category',
- 'duplicated' => false,
- 'extra' => [
- 'payee' => $op1,
- ],
- 'account_id' => 1234,
- 'created_at' => $today->toW3cString(),
- 'updated_at' => $today->toW3cString(),
- ]
- ),
- new SpectreTransaction(
- [
- 'id' => 2,
- 'mode' => 'mode',
- 'status' => 'active',
- 'made_on' => $today->toW3cString(),
- 'amount' => 563.21,
- 'currency_code' => 'EUR',
- 'description' => 'Fake second description #' . $this->randomInt(),
- 'category' => 'some-other-category',
- 'duplicated' => false,
- 'extra' => [
- 'payee' => $op2,
- ],
- 'account_id' => 1234,
- 'created_at' => $today->toW3cString(),
- 'updated_at' => $today->toW3cString(),
- ]
- ),
- ];
-
-
- $account = $this->user()->accounts()->where('account_type_id', 3)->first();
- $expense = $this->user()->accounts()->where('account_type_id', 4)->first();
- $revenue = $this->user()->accounts()->where('account_type_id', 5)->first();
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sid_a__' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [
- 'accounts' => [$spectreAccount->toArray()],
- 'account_mapping' => [
- 1234 => 322,
- ],
- ];
- $job->save();
-
- // mock repositories
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $lrRequest = $this->mock(ListTransactionsRequest::class);
- $mapper = $this->mock(OpposingAccountMapper::class);
-
- $expected = [
- 0 => [
- 'transactions' => [
- 0 => [
- // transaction here
- 'date' => $today->format('Y-m-d'),
- 'tags' => ['mode', 'active'],
- 'type' => 'withdrawal',
- 'user' => $job->user_id,
- 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op1 . " \n",
- 'external_id' => '1',
- // journal data:
- 'description' => $transactions[0]->getDescription(),
- 'piggy_bank_id' => null,
- 'piggy_bank_name' => null,
- 'bill_id' => null,
- 'bill_name' => null,
- 'original-source' => sprintf('spectre-v%s', config('firefly.version')),
- 'currency_id' => null,
- 'currency_code' => 'EUR',
- 'amount' => '-123.45',
- 'budget_id' => null,
- 'budget_name' => null,
- 'category_id' => null,
- 'category_name' => 'some-category',
- 'source_id' => $account->id,
- 'source_name' => null,
- 'destination_id' => $expense->id,
- 'destination_name' => null,
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => null,
- 'foreign_amount' => null,
- 'reconciled' => false,
- 'identifier' => 0,
- ],
- ],
- ],
- 1 => [
- 'transactions' => [
- 0 => [
- // transaction here
- 'date' => $today->format('Y-m-d'),
- 'tags' => ['mode', 'active'],
- 'type' => 'deposit',
- 'user' => $job->user_id,
- 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op2 . " \n",
- 'external_id' => '2',
- // journal data:
- 'description' => $transactions[1]->getDescription(),
- 'piggy_bank_id' => null,
- 'piggy_bank_name' => null,
- 'bill_id' => null,
- 'bill_name' => null,
- 'original-source' => sprintf('spectre-v%s', config('firefly.version')),
- 'currency_id' => null,
- 'currency_code' => 'EUR',
- 'amount' => '563.21',
- 'budget_id' => null,
- 'budget_name' => null,
- 'category_id' => null,
- 'category_name' => 'some-other-category',
- 'source_id' => $revenue->id,
- 'source_name' => null,
- 'destination_id' => $account->id,
- 'destination_name' => null,
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => null,
- 'foreign_amount' => null,
- 'reconciled' => false,
- 'identifier' => 0,
- ],
- ],
- ],
- ];
-
- $accountRepos->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('findNull')->once()->withArgs([322])->andReturn($account);
- $importRepos->shouldReceive('setUser')->once();
- $importRepos->shouldReceive('setTransactions')->once()->withArgs([Mockery::any(), $expected]);
- $lrRequest->shouldReceive('setUser')->once();
- $lrRequest->shouldReceive('setAccount')->once()->withArgs([Mockery::any()]);
- $lrRequest->shouldReceive('call')->once();
- $lrRequest->shouldReceive('getTransactions')->once()->andReturn($transactions);
- $mapper->shouldReceive('setUser')->once();
- // mapper should be called twice:
- $mapper->shouldReceive('map')->withArgs(
- [null, -123.45, ['name' => $op1, 'iban' => null, 'number' => null, 'bic' => null]]
- )->once()->andReturn($expense);
- $mapper->shouldReceive('map')->withArgs(
- [null, 563.21, ['name' => $op2, 'iban' => null, 'number' => null, 'bic' => null]]
- )->once()->andReturn($revenue);
-
-
- $handler = new StageImportDataHandler;
- $handler->setImportJob($job);
- try {
- $handler->run();
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
- /**
- * Also has empty local account.
- *
- * @covers \FireflyIII\Support\Import\Routine\Spectre\StageImportDataHandler
- */
- public function testRunForeignCurrency(): void
- {
- // needs to be a full spectre account this time.
- $spectreAccount = new SpectreAccount(
- [
- 'id' => 1234,
- 'login_id' => 5678,
- 'currency_code' => 'EUR',
- 'balance' => 1000,
- 'name' => 'Fake Spectre Account',
- 'nature' => 'account',
- 'created_at' => '2018-01-01 12:12:12',
- 'updated_at' => '2018-01-01 12:12:12',
- 'extra' => [],
- ]
- );
-
- $today = new Carbon;
- // create fake transactions:
- $op1 = 'Some opposing account #' . $this->randomInt();
- $op2 = 'Some opposing revenue account #' . $this->randomInt();
- $transactions = [
- new SpectreTransaction(
- [
- 'id' => 1,
- 'mode' => 'mode',
- 'status' => 'active',
- 'made_on' => $today->toW3cString(),
- 'amount' => -123.45,
- 'currency_code' => 'EUR',
- 'description' => 'Fake description #' . $this->randomInt(),
- 'category' => 'some-category',
- 'duplicated' => true,
- 'extra' => [
- 'payee' => $op1,
- 'original_amount' => -200.01,
- ],
- 'account_id' => 1234,
- 'created_at' => $today->toW3cString(),
- 'updated_at' => $today->toW3cString(),
- ]
- ),
- new SpectreTransaction(
- [
- 'id' => 2,
- 'mode' => 'mode',
- 'status' => 'active',
- 'made_on' => $today->toW3cString(),
- 'amount' => 563.21,
- 'currency_code' => 'EUR',
- 'description' => 'Fake second description #' . $this->randomInt(),
- 'category' => 'some-other-category',
- 'duplicated' => false,
- 'extra' => [
- 'payee' => $op2,
- 'customer_category_name' => 'cat-name',
- 'original_currency_code' => 'USD',
- ],
- 'account_id' => 1234,
- 'created_at' => $today->toW3cString(),
- 'updated_at' => $today->toW3cString(),
- ]
- ),
- ];
-
-
- $account = $this->user()->accounts()->where('account_type_id', 3)->first();
- $expense = $this->user()->accounts()->where('account_type_id', 4)->first();
- $revenue = $this->user()->accounts()->where('account_type_id', 5)->first();
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sid_a_' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [
- 'accounts' => [$spectreAccount->toArray()],
- 'account_mapping' => [
- 1234 => 322,
- 5678 => 0,
- ],
- ];
- $job->save();
-
- // mock repositories
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $lrRequest = $this->mock(ListTransactionsRequest::class);
- $mapper = $this->mock(OpposingAccountMapper::class);
-
- $expected = [
- 0 => [
- 'transactions' => [
- 0 => [
- // data here.
- 'date' => $today->format('Y-m-d'),
- 'type' => 'withdrawal',
- 'tags' => ['mode', 'active', 'possibly-duplicated'],
- 'user' => $job->user_id,
- 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op1 . " \n",
- 'external_id' => '1',
- // journal data:
- 'description' => $transactions[0]->getDescription(),
- 'piggy_bank_id' => null,
- 'piggy_bank_name' => null,
- 'bill_id' => null,
- 'bill_name' => null,
- 'original-source' => sprintf('spectre-v%s', config('firefly.version')),
- 'currency_id' => null,
- 'currency_code' => 'EUR',
- 'amount' => '-123.45',
- 'budget_id' => null,
- 'budget_name' => null,
- 'category_id' => null,
- 'category_name' => 'some-category',
- 'source_id' => $account->id,
- 'source_name' => null,
- 'destination_id' => $expense->id,
- 'destination_name' => null,
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => null,
- 'foreign_amount' => '-200.01',
- 'reconciled' => false,
- 'identifier' => 0,
- ],
- ],
- ],
- 1 => [
- 'transactions' => [
- 0 => [
- // data here.
- 'date' => $today->format('Y-m-d'),
- 'type' => 'deposit',
- 'tags' => ['mode', 'active', 'cat-name'],
- 'user' => $job->user_id,
- 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op2 . " \n",
- 'external_id' => '2',
- // journal data:
- 'description' => $transactions[1]->getDescription(),
- 'piggy_bank_id' => null,
- 'piggy_bank_name' => null,
- 'bill_id' => null,
- 'bill_name' => null,
- 'original-source' => sprintf('spectre-v%s', config('firefly.version')),
- 'currency_id' => null,
- 'currency_code' => 'EUR',
- 'amount' => '563.21',
- 'budget_id' => null,
- 'budget_name' => null,
- 'category_id' => null,
- 'category_name' => 'some-other-category',
- 'source_id' => $revenue->id,
- 'source_name' => null,
- 'destination_id' => $account->id,
- 'destination_name' => null,
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => 'USD',
- 'foreign_amount' => null,
- 'reconciled' => false,
- 'identifier' => 0,
- ],
- ],
- ],
- ];
-
- $accountRepos->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('findNull')->once()->withArgs([322])->andReturn($account);
- $importRepos->shouldReceive('setUser')->once();
- $importRepos->shouldReceive('setTransactions')->once()
- ->withArgs([Mockery::any(), $expected]);
- $lrRequest->shouldReceive('setUser')->once();
- $lrRequest->shouldReceive('setAccount')->once()->withArgs([Mockery::any()]);
- $lrRequest->shouldReceive('call')->once();
- $lrRequest->shouldReceive('getTransactions')->once()->andReturn($transactions);
- $mapper->shouldReceive('setUser')->once();
- // mapper should be called twice:
- $mapper->shouldReceive('map')->withArgs(
- [null, -123.45, ['name' => $op1, 'iban' => null, 'number' => null, 'bic' => null]]
- )->once()->andReturn($expense);
- $mapper->shouldReceive('map')->withArgs(
- [null, 563.21, ['name' => $op2, 'iban' => null, 'number' => null, 'bic' => null]]
- )->once()->andReturn($revenue);
-
-
- $handler = new StageImportDataHandler;
- $handler->setImportJob($job);
- try {
- $handler->run();
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
- /**
- * @covers \FireflyIII\Support\Import\Routine\Spectre\StageImportDataHandler
- */
- public function testRunWithDuplication(): void
- {
- // needs to be a full spectre account this time.
- $spectreAccount = new SpectreAccount(
- [
- 'id' => 1234,
- 'login_id' => 5678,
- 'currency_code' => 'EUR',
- 'balance' => 1000,
- 'name' => 'Fake Spectre Account',
- 'nature' => 'account',
- 'created_at' => '2018-01-01 12:12:12',
- 'updated_at' => '2018-01-01 12:12:12',
- 'extra' => [],
- ]
- );
-
- $today = new Carbon;
- // create fake transactions:
- $op1 = 'Some opposing account #' . $this->randomInt();
- $op2 = 'Some opposing revenue account #' . $this->randomInt();
- $transactions = [
- new SpectreTransaction(
- [
- 'id' => 1,
- 'mode' => 'mode',
- 'status' => 'active',
- 'made_on' => $today->toW3cString(),
- 'amount' => -123.45,
- 'currency_code' => 'EUR',
- 'description' => 'Fake description #' . $this->randomInt(),
- 'category' => 'some-category',
- 'duplicated' => true,
- 'extra' => [
- 'payee' => $op1,
- ],
- 'account_id' => 1234,
- 'created_at' => $today->toW3cString(),
- 'updated_at' => $today->toW3cString(),
- ]
- ),
- new SpectreTransaction(
- [
- 'id' => 2,
- 'mode' => 'mode',
- 'status' => 'active',
- 'made_on' => $today->toW3cString(),
- 'amount' => 563.21,
- 'currency_code' => 'EUR',
- 'description' => 'Fake second description #' . $this->randomInt(),
- 'category' => 'some-other-category',
- 'duplicated' => false,
- 'extra' => [
- 'payee' => $op2,
- 'customer_category_name' => 'cat-name',
- ],
- 'account_id' => 1234,
- 'created_at' => $today->toW3cString(),
- 'updated_at' => $today->toW3cString(),
- ]
- ),
- ];
-
-
- $account = $this->user()->accounts()->where('account_type_id', 3)->first();
- $expense = $this->user()->accounts()->where('account_type_id', 4)->first();
- $revenue = $this->user()->accounts()->where('account_type_id', 5)->first();
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sid_a_' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [
- 'accounts' => [$spectreAccount->toArray()],
- 'account_mapping' => [
- 1234 => 322,
- ],
- ];
- $job->save();
-
- // mock repositories
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $importRepos = $this->mock(ImportJobRepositoryInterface::class);
- $lrRequest = $this->mock(ListTransactionsRequest::class);
- $mapper = $this->mock(OpposingAccountMapper::class);
-
- $expected = [
- 0 => [
- 'transactions' => [
- 0 => [
- // data here
- 'date' => $today->format('Y-m-d'),
- 'type' => 'withdrawal',
- 'tags' => ['mode', 'active', 'possibly-duplicated'],
- 'user' => $job->user_id,
- 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op1 . " \n",
- 'external_id' => '1',
- // journal data:
- 'description' => $transactions[0]->getDescription(),
- 'piggy_bank_id' => null,
- 'piggy_bank_name' => null,
- 'bill_id' => null,
- 'bill_name' => null,
- 'original-source' => sprintf('spectre-v%s', config('firefly.version')),
- 'currency_id' => null,
- 'currency_code' => 'EUR',
- 'amount' => '-123.45',
- 'budget_id' => null,
- 'budget_name' => null,
- 'category_id' => null,
- 'category_name' => 'some-category',
- 'source_id' => $account->id,
- 'source_name' => null,
- 'destination_id' => $expense->id,
- 'destination_name' => null,
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => null,
- 'foreign_amount' => null,
- 'reconciled' => false,
- 'identifier' => 0,
- ],
- ],
- ],
- 1 => [
- 'transactions' => [
- 0 => [
- // data here
- 'date' => $today->format('Y-m-d'),
- 'type' => 'deposit',
- 'tags' => ['mode', 'active', 'cat-name'],
- 'user' => $job->user_id,
- 'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op2 . " \n",
- 'external_id' => '2',
- // journal data:
- 'description' => $transactions[1]->getDescription(),
- 'piggy_bank_id' => null,
- 'piggy_bank_name' => null,
- 'bill_id' => null,
- 'bill_name' => null,
- 'original-source' => sprintf('spectre-v%s', config('firefly.version')),
- 'currency_id' => null,
- 'currency_code' => 'EUR',
- 'amount' => '563.21',
- 'budget_id' => null,
- 'budget_name' => null,
- 'category_id' => null,
- 'category_name' => 'some-other-category',
- 'source_id' => $revenue->id,
- 'source_name' => null,
- 'destination_id' => $account->id,
- 'destination_name' => null,
- 'foreign_currency_id' => null,
- 'foreign_currency_code' => null,
- 'foreign_amount' => null,
- 'reconciled' => false,
- 'identifier' => 0,
- ],
- ],
- ],
- ];
-
- $accountRepos->shouldReceive('setUser')->once();
- $accountRepos->shouldReceive('findNull')->once()->withArgs([322])->andReturn($account);
- $importRepos->shouldReceive('setUser')->once();
- $importRepos->shouldReceive('setTransactions')->once()
- ->withArgs([Mockery::any(), $expected]);
- $lrRequest->shouldReceive('setUser')->once();
- $lrRequest->shouldReceive('setAccount')->once()->withArgs([Mockery::any()]);
- $lrRequest->shouldReceive('call')->once();
- $lrRequest->shouldReceive('getTransactions')->once()->andReturn($transactions);
- $mapper->shouldReceive('setUser')->once();
- // mapper should be called twice:
- $mapper->shouldReceive('map')->withArgs(
- [null, -123.45, ['name' => $op1, 'iban' => null, 'number' => null, 'bic' => null]]
- )->once()->andReturn($expense);
- $mapper->shouldReceive('map')->withArgs(
- [null, 563.21, ['name' => $op2, 'iban' => null, 'number' => null, 'bic' => null]]
- )->once()->andReturn($revenue);
-
-
- $handler = new StageImportDataHandler;
- $handler->setImportJob($job);
- try {
- $handler->run();
- } catch (FireflyException $e) {
- $this->assertFalse(true, $e->getMessage());
- }
- }
-
-}
diff --git a/tests/Unit/Support/Import/Routine/Spectre/StageNewHandlerTest.php b/tests/Unit/Support/Import/Routine/Spectre/StageNewHandlerTest.php
deleted file mode 100644
index 3e780198b2..0000000000
--- a/tests/Unit/Support/Import/Routine/Spectre/StageNewHandlerTest.php
+++ /dev/null
@@ -1,381 +0,0 @@
-.
- */
-
-declare(strict_types=1);
-
-namespace Tests\Unit\Support\Import\Routine\Spectre;
-
-
-use FireflyIII\Exceptions\FireflyException;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Models\Preference;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Services\Spectre\Object\Attempt;
-use FireflyIII\Services\Spectre\Object\Customer;
-use FireflyIII\Services\Spectre\Object\Holder;
-use FireflyIII\Services\Spectre\Object\Login;
-use FireflyIII\Services\Spectre\Request\ListCustomersRequest;
-use FireflyIII\Services\Spectre\Request\ListLoginsRequest;
-use FireflyIII\Services\Spectre\Request\NewCustomerRequest;
-use FireflyIII\Support\Import\Routine\Spectre\StageNewHandler;
-use Log;
-use Mockery;
-use Preferences;
-use Tests\TestCase;
-
-/**
- * Class StageNewHandlerTest
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.TooManyPublicMethods)
- */
-class StageNewHandlerTest extends TestCase
-{
- /**
- *
- */
- public function setUp(): void
- {
- parent::setUp();
- Log::info(sprintf('Now in %s.', get_class($this)));
- }
- // todo run() with zero logins and an existing customer (must be retrieved from Spectre).
- // todo run() with one login and an existing customer (must be retrieved from Spectre).
-
- /**
- * run() with zero logins and a non-existing customer (must be created by Spectre).
- *
- * @covers \FireflyIII\Support\Import\Information\GetSpectreCustomerTrait
- * @covers \FireflyIII\Support\Import\Routine\Spectre\StageNewHandler
- */
- public function testRunBasic(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sn_a_' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // fake Spectre customer:
- $fakeCustomer = new Customer(
- [
- 'id' => 1,
- 'identifier' => 'fake',
- 'secret' => 'Dumbledore dies',
- ]
- );
-
- // mock classes:
- $llRequest = $this->mock(ListLoginsRequest::class);
- $lcRequest = $this->mock(ListCustomersRequest::class);
- $ncRequest = $this->mock(NewCustomerRequest::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
-
-
- // mock calls for list logins (return empty list for now).
- $llRequest->shouldReceive('setUser')->once();
- $llRequest->shouldReceive('setCustomer')->once();
- $llRequest->shouldReceive('call')->once();
- $llRequest->shouldReceive('getLogins')->once()->andReturn([]);
-
- // mock calls for list customers (return empty list).
- $lcRequest->shouldReceive('setUser')->once();
- $lcRequest->shouldReceive('call')->once();
- $lcRequest->shouldReceive('getCustomers')->once()->andReturn([]);
-
- // create new customer:
- $ncRequest->shouldReceive('setUser')->once();
- $ncRequest->shouldReceive('getCustomer')->once()->andReturn($fakeCustomer);
- $ncRequest->shouldReceive('call')->once();
-
- // mock calls for repository:
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('getConfiguration')->once()->withArgs([Mockery::any()])->andReturn([]);
-
- // mock call for preferences
- Preferences::shouldReceive('getForUser')->once()->withArgs([Mockery::any(), 'spectre_customer', null])->andReturnNull();
-
-
- $handler = new StageNewHandler;
- $handler->setImportJob($job);
- try {
- $handler->run();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * run() with zero logins and an existing customer (from preferences).
- *
- * @covers \FireflyIII\Support\Import\Information\GetSpectreCustomerTrait
- * @covers \FireflyIII\Support\Import\Routine\Spectre\StageNewHandler
- */
- public function testRunExistingCustomer(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sn_a_' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- $fakeCustomerPreference = new Preference;
- $fakeCustomerPreference->name = 'spectre_customer';
- $fakeCustomerPreference->data = [
- 'id' => 1,
- 'identifier' => 'fake',
- 'secret' => 'Dumbledore dies',
- ];
-
- // mock classes:
- $llRequest = $this->mock(ListLoginsRequest::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
-
-
- // mock calls for list logins (return empty list for now).
- $llRequest->shouldReceive('setUser')->once();
- $llRequest->shouldReceive('setCustomer')->once();
- $llRequest->shouldReceive('call')->once();
- $llRequest->shouldReceive('getLogins')->once()->andReturn([]);
-
- // mock call for preferences
- Preferences::shouldReceive('getForUser')->once()->withArgs([Mockery::any(), 'spectre_customer', null])->andReturn($fakeCustomerPreference);
-
- // mock calls for repository:
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('getConfiguration')->once()->withArgs([Mockery::any()])->andReturn([]);
-
- $handler = new StageNewHandler;
- $handler->setImportJob($job);
- try {
- $handler->run();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * run() with zero logins and multiple customers at Spectre (none in prefs)
- *
- * @covers \FireflyIII\Support\Import\Information\GetSpectreCustomerTrait
- * @covers \FireflyIII\Support\Import\Routine\Spectre\StageNewHandler
- */
- public function testRunMultiCustomer(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sn_a_' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // fake Spectre customer:
- $fakeCustomer = new Customer(
- [
- 'id' => 1,
- 'identifier' => 'fake',
- 'secret' => 'Dumbledore dies',
- ]
- );
-
- $correctCustomer = new Customer(
- [
- 'id' => 1,
- 'identifier' => 'default_ff3_customer',
- 'secret' => 'Firefly III',
- ]
- );
-
- // mock classes:
- $llRequest = $this->mock(ListLoginsRequest::class);
- $lcRequest = $this->mock(ListCustomersRequest::class);
- $ncRequest = $this->mock(NewCustomerRequest::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
-
- // mock calls for list logins (return empty list for now).
- $llRequest->shouldReceive('setUser')->once();
- $llRequest->shouldReceive('setCustomer')->once();
- $llRequest->shouldReceive('call')->once();
- $llRequest->shouldReceive('getLogins')->once()->andReturn([]);
-
- // mock calls for list customers (return empty list).
- $lcRequest->shouldReceive('setUser')->once();
- $lcRequest->shouldReceive('call')->once();
- $lcRequest->shouldReceive('getCustomers')->once()->andReturn([$fakeCustomer, $correctCustomer]);
-
- // mock calls for repository:
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('getConfiguration')->once()->withArgs([Mockery::any()])->andReturn([]);
-
- // mock call for preferences
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'spectre_customer', null])->andReturnNull()->once();
- Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'spectre_customer', $correctCustomer->toArray()])->once();
-
- $handler = new StageNewHandler;
- $handler->setImportJob($job);
- try {
- $handler->run();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-
- /**
- * run() with one login and multiple customers at Spectre (none in prefs)
- *
- * @covers \FireflyIII\Support\Import\Information\GetSpectreCustomerTrait
- * @covers \FireflyIII\Support\Import\Routine\Spectre\StageNewHandler
- */
- public function testRunMultiCustomerLogin(): void
- {
- $job = new ImportJob;
- $job->user_id = $this->user()->id;
- $job->key = 'sn_a_' . $this->randomInt();
- $job->status = 'new';
- $job->stage = 'new';
- $job->provider = 'spectre';
- $job->file_type = '';
- $job->configuration = [];
- $job->save();
-
- // fake Spectre customer:
- $fakeCustomer = new Customer(
- [
- 'id' => 1,
- 'identifier' => 'fake',
- 'secret' => 'Dumbledore dies',
- ]
- );
-
- $correctCustomer = new Customer(
- [
- 'id' => 1,
- 'identifier' => 'default_ff3_customer',
- 'secret' => 'Firefly III',
- ]
- );
-
- // fake login:
- $holder = new Holder([]);
- $attempt = new Attempt(
- [
- 'api_mode' => 'x',
- 'api_version' => 4,
- 'automatic_fetch' => true,
- 'categorize' => true,
- 'created_at' => '2018-05-21 12:00:00',
- 'consent_given_at' => '2018-05-21 12:00:00',
- 'consent_types' => ['transactions'],
- 'custom_fields' => [],
- 'daily_refresh' => true,
- 'device_type' => 'mobile',
- 'user_agent' => 'Mozilla/x',
- 'remote_ip' => '127.0.0.1',
- 'exclude_accounts' => [],
- 'fail_at' => '2018-05-21 12:00:00',
- 'fail_error_class' => 'err',
- 'fail_message' => 'message',
- 'fetch_scopes' => [],
- 'finished' => true,
- 'finished_recent' => true,
- 'from_date' => '2018-05-21 12:00:00',
- 'id' => 1,
- 'interactive' => true,
- 'locale' => 'en',
- 'partial' => true,
- 'show_consent_confirmation' => true,
- 'stages' => [],
- 'store_credentials' => true,
- 'success_at' => '2018-05-21 12:00:00',
- 'to_date' => '2018-05-21 12:00:00',
- 'updated_at' => '2018-05-21 12:00:00',
- ]
- );
- $login = new Login(
- [
- 'consent_given_at' => '2018-05-21 12:00:00',
- 'consent_types' => ['transactions'],
- 'country_code' => 'NL',
- 'created_at' => '2018-05-21 12:00:00',
- 'updated_at' => '2018-05-21 12:00:00',
- 'customer_id' => '1',
- 'daily_refresh' => true,
- 'holder_info' => $holder->toArray(),
- 'id' => 123,
- 'last_attempt' => $attempt->toArray(),
- 'last_success_at' => '2018-05-21 12:00:00',
- 'next_refresh_possible_at' => '2018-05-21 12:00:00',
- 'provider_code' => 'XF',
- 'provider_id' => '123',
- 'provider_name' => 'Fake',
- 'show_consent_confirmation' => true,
- 'status' => 'active',
- 'store_credentials' => true,
- ]
- );
-
- // mock classes:
- $llRequest = $this->mock(ListLoginsRequest::class);
- $lcRequest = $this->mock(ListCustomersRequest::class);
- $ncRequest = $this->mock(NewCustomerRequest::class);
- $repository = $this->mock(ImportJobRepositoryInterface::class);
-
- // mock calls for list logins (return empty list for now).
- $llRequest->shouldReceive('setUser')->once();
- $llRequest->shouldReceive('setCustomer')->once();
- $llRequest->shouldReceive('call')->once();
- $llRequest->shouldReceive('getLogins')->once()->andReturn([$login]);
-
- // mock calls for list customers (return empty list).
- $lcRequest->shouldReceive('setUser')->once();
- $lcRequest->shouldReceive('call')->once();
- $lcRequest->shouldReceive('getCustomers')->once()->andReturn([$fakeCustomer, $correctCustomer]);
-
- // mock call for preferences
- Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'spectre_customer', null])->andReturnNull()->once();
- Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'spectre_customer', $correctCustomer->toArray()])->once();
-
- // mock calls for repository:
- $repository->shouldReceive('setUser')->once();
- $repository->shouldReceive('getConfiguration')->once()->withArgs([Mockery::any()])->andReturn([]);
- $repository->shouldReceive('setConfiguration')->once()
- ->withArgs([Mockery::any(), ['all-logins' => [$login->toArray()]]]);
-
- $handler = new StageNewHandler;
- $handler->setImportJob($job);
- try {
- $handler->run();
- } catch (FireflyException $e) {
- $this->assertTrue(false, $e->getMessage());
- }
- }
-}