diff --git a/tests/Unit/Import/JobConfiguration/BunqJobConfigurationTest.php b/tests/Unit/Import/JobConfiguration/BunqJobConfigurationTest.php new file mode 100644 index 0000000000..8a65cca291 --- /dev/null +++ b/tests/Unit/Import/JobConfiguration/BunqJobConfigurationTest.php @@ -0,0 +1,180 @@ +. + */ + +declare(strict_types=1); + +namespace Tests\Unit\Import\JobConfiguration; + +use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Import\JobConfiguration\BunqJobConfiguration; +use FireflyIII\Models\ImportJob; +use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; +use FireflyIII\Support\Import\JobConfiguration\Bunq\ChooseAccountsHandler; +use FireflyIII\Support\Import\JobConfiguration\Bunq\NewBunqJobHandler; +use Illuminate\Support\MessageBag; +use Log; +use Tests\TestCase; + +/** + * Class BunqJobConfigurationTest + */ +class BunqJobConfigurationTest extends TestCase +{ + /** + * + */ + public function setUp(): void + { + parent::setUp(); + Log::info(sprintf('Now in %s.', \get_class($this))); + } + + + /** + * @covers \FireflyIII\Import\JobConfiguration\BunqJobConfiguration + */ + public function testConfigurationComplete(): void + { + $jobRepos = $this->mock(ImportJobRepositoryInterface::class); + $jobRepos->shouldReceive('setUser')->once(); + $job = new ImportJob; + $job->user_id = $this->user()->id; + $job->key = 'bunq_jc_A' . random_int(1, 100000); + $job->status = 'new'; + $job->stage = 'new'; + $job->provider = 'bunq'; + $job->file_type = ''; + $job->configuration = []; + $job->save(); + + // expect "NewBunqJobHandler" to be created because job is new. + $handler = $this->mock(NewBunqJobHandler::class); + $handler->shouldReceive('setImportJob')->once(); + $handler->shouldReceive('configurationComplete')->once()->andReturn(true); + + $config = new BunqJobConfiguration; + try { + $config->setImportJob($job); + } catch (FireflyException $e) { + $this->assertTrue(false, $e->getMessage()); + } + $this->assertTrue($config->configurationComplete()); + } + + /** + * @covers \FireflyIII\Import\JobConfiguration\BunqJobConfiguration + */ + public function testConfigureJob(): void + { + $jobRepos = $this->mock(ImportJobRepositoryInterface::class); + $jobRepos->shouldReceive('setUser')->once(); + $job = new ImportJob; + $job->user_id = $this->user()->id; + $job->key = 'bunq_jc_B' . random_int(1, 10000); + $job->status = 'new'; + $job->stage = 'new'; + $job->provider = 'bunq'; + $job->file_type = ''; + $job->configuration = []; + $job->save(); + $configData = ['ssome' => 'values']; + $return = new MessageBag(); + $return->add('some', 'return message'); + + // expect "NewBunqJobHandler" to be created because job is in "do-authenticate". + $handler = $this->mock(NewBunqJobHandler::class); + $handler->shouldReceive('setImportJob')->once(); + $handler->shouldReceive('configureJob')->once()->withArgs([$configData])->andReturn($return); + + $config = new BunqJobConfiguration; + try { + $config->setImportJob($job); + } catch (FireflyException $e) { + $this->assertTrue(false, $e->getMessage()); + } + $this->assertEquals($return, $config->configureJob($configData)); + } + + /** + * @covers \FireflyIII\Import\JobConfiguration\BunqJobConfiguration + */ + public function testGetNextData(): void + { + $jobRepos = $this->mock(ImportJobRepositoryInterface::class); + $jobRepos->shouldReceive('setUser')->once(); + $job = new ImportJob; + $job->user_id = $this->user()->id; + $job->key = 'bunq_jc_C' . random_int(1, 10000); + $job->status = 'new'; + $job->stage = 'new'; + $job->provider = 'bunq'; + $job->file_type = ''; + $job->configuration = []; + $job->save(); + $data = ['ssome' => 'values']; + + // Expect "NewBunqJobHandler" because of state. + $handler = $this->mock(NewBunqJobHandler::class); + $handler->shouldReceive('setImportJob')->once(); + $handler->shouldReceive('getNextData')->once()->andReturn($data); + + $config = new BunqJobConfiguration; + try { + $config->setImportJob($job); + } catch (FireflyException $e) { + $this->assertTrue(false, $e->getMessage()); + } + $this->assertEquals($data, $config->getNextData()); + } + + /** + * @covers \FireflyIII\Import\JobConfiguration\BunqJobConfiguration + */ + public function testGetNextViewAccount(): void + { + $jobRepos = $this->mock(ImportJobRepositoryInterface::class); + $jobRepos->shouldReceive('setUser')->once(); + $job = new ImportJob; + $job->user_id = $this->user()->id; + $job->key = 'bunq_jc_E' . random_int(1, 100000); + $job->status = 'new'; + $job->stage = 'choose-accounts'; + $job->provider = 'bunq'; + $job->file_type = ''; + $job->configuration = []; + $job->save(); + + // expect "ChooseAccountsHandler" because of state. + $handler = $this->mock(ChooseAccountsHandler::class); + $handler->shouldReceive('setImportJob')->once(); + $handler->shouldReceive('getNextView')->once()->andReturn('import.fake.view2'); + + $config = new BunqJobConfiguration; + try { + $config->setImportJob($job); + } catch (FireflyException $e) { + $this->assertTrue(false, $e->getMessage()); + } + $this->assertEquals('import.fake.view2', $config->getNextView()); + } + + +} diff --git a/tests/Unit/Import/JobConfiguration/YnabJobConfigurationTest.php b/tests/Unit/Import/JobConfiguration/YnabJobConfigurationTest.php new file mode 100644 index 0000000000..0737b87e7f --- /dev/null +++ b/tests/Unit/Import/JobConfiguration/YnabJobConfigurationTest.php @@ -0,0 +1,184 @@ +. + */ + +declare(strict_types=1); + +namespace Tests\Unit\Import\JobConfiguration; + +use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Import\JobConfiguration\BunqJobConfiguration; +use FireflyIII\Import\JobConfiguration\YnabJobConfiguration; +use FireflyIII\Models\ImportJob; +use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; +use FireflyIII\Support\Import\JobConfiguration\Bunq\ChooseAccountsHandler; +use FireflyIII\Support\Import\JobConfiguration\Bunq\NewBunqJobHandler; +use FireflyIII\Support\Import\JobConfiguration\Ynab\NewYnabJobHandler; +use FireflyIII\Support\Import\JobConfiguration\Ynab\SelectAccountsHandler; +use FireflyIII\Support\Import\JobConfiguration\Ynab\SelectBudgetHandler; +use Illuminate\Support\MessageBag; +use Log; +use Tests\TestCase; + +/** + * Class YnabJobConfigurationTest + */ +class YnabJobConfigurationTest extends TestCase +{ + /** + * + */ + public function setUp(): void + { + parent::setUp(); + Log::info(sprintf('Now in %s.', \get_class($this))); + } + + + /** + * @covers \FireflyIII\Import\JobConfiguration\YnabJobConfiguration + */ + public function testConfigurationComplete(): void + { + $jobRepos = $this->mock(ImportJobRepositoryInterface::class); + $jobRepos->shouldReceive('setUser')->once(); + $job = new ImportJob; + $job->user_id = $this->user()->id; + $job->key = 'ynab_jc_A' . random_int(1, 100000); + $job->status = 'new'; + $job->stage = 'new'; + $job->provider = 'ynab'; + $job->file_type = ''; + $job->configuration = []; + $job->save(); + + // expect "NewYnabJobHandler" to be created because job is new. + $handler = $this->mock(NewYnabJobHandler::class); + $handler->shouldReceive('setImportJob')->once(); + $handler->shouldReceive('configurationComplete')->once()->andReturn(true); + + $config = new YnabJobConfiguration; + try { + $config->setImportJob($job); + } catch (FireflyException $e) { + $this->assertTrue(false, $e->getMessage()); + } + $this->assertTrue($config->configurationComplete()); + } + + /** + * @covers \FireflyIII\Import\JobConfiguration\YnabJobConfiguration + */ + public function testConfigureJob(): void + { + $jobRepos = $this->mock(ImportJobRepositoryInterface::class); + $jobRepos->shouldReceive('setUser')->once(); + $job = new ImportJob; + $job->user_id = $this->user()->id; + $job->key = 'ynab_jc_B' . random_int(1, 10000); + $job->status = 'new'; + $job->stage = 'select_budgets'; + $job->provider = 'ynab'; + $job->file_type = ''; + $job->configuration = []; + $job->save(); + $configData = ['ssome' => 'values']; + $return = new MessageBag(); + $return->add('some', 'return message'); + + // expect "SelectBudgetHandler" to be created because job is in "select_budgets". + $handler = $this->mock(SelectBudgetHandler::class); + $handler->shouldReceive('setImportJob')->once(); + $handler->shouldReceive('configureJob')->once()->withArgs([$configData])->andReturn($return); + + $config = new YnabJobConfiguration; + try { + $config->setImportJob($job); + } catch (FireflyException $e) { + $this->assertTrue(false, $e->getMessage()); + } + $this->assertEquals($return, $config->configureJob($configData)); + } + + /** + * @covers \FireflyIII\Import\JobConfiguration\YnabJobConfiguration + */ + public function testGetNextData(): void + { + $jobRepos = $this->mock(ImportJobRepositoryInterface::class); + $jobRepos->shouldReceive('setUser')->once(); + $job = new ImportJob; + $job->user_id = $this->user()->id; + $job->key = 'ynab_jc_C' . random_int(1, 10000); + $job->status = 'new'; + $job->stage = 'select_accounts'; + $job->provider = 'ynab'; + $job->file_type = ''; + $job->configuration = []; + $job->save(); + $data = ['ssome' => 'values']; + + // Expect "SelectAccountsHandler" because state is "select_accounts" + $handler = $this->mock(SelectAccountsHandler::class); + $handler->shouldReceive('setImportJob')->once(); + $handler->shouldReceive('getNextData')->once()->andReturn($data); + + $config = new YnabJobConfiguration; + try { + $config->setImportJob($job); + } catch (FireflyException $e) { + $this->assertTrue(false, $e->getMessage()); + } + $this->assertEquals($data, $config->getNextData()); + } + + /** + * @covers \FireflyIII\Import\JobConfiguration\YnabJobConfiguration + */ + public function testGetNextView(): void + { + $jobRepos = $this->mock(ImportJobRepositoryInterface::class); + $jobRepos->shouldReceive('setUser')->once(); + $job = new ImportJob; + $job->user_id = $this->user()->id; + $job->key = 'ynab_jc_E' . random_int(1, 100000); + $job->status = 'new'; + $job->stage = 'new'; + $job->provider = 'ynab'; + $job->file_type = ''; + $job->configuration = []; + $job->save(); + + // expect "NewYnabJobHandler" because of state. + $handler = $this->mock(NewYnabJobHandler::class); + $handler->shouldReceive('setImportJob')->once(); + $handler->shouldReceive('getNextView')->once()->andReturn('import.fake.view2'); + + $config = new YnabJobConfiguration; + try { + $config->setImportJob($job); + } catch (FireflyException $e) { + $this->assertTrue(false, $e->getMessage()); + } + $this->assertEquals('import.fake.view2', $config->getNextView()); + } + + +} diff --git a/tests/Unit/Import/Mapper/AssetAccountIbansTest.php b/tests/Unit/Import/Mapper/AssetAccountIbansTest.php index 638ac271e3..a043e73926 100644 --- a/tests/Unit/Import/Mapper/AssetAccountIbansTest.php +++ b/tests/Unit/Import/Mapper/AssetAccountIbansTest.php @@ -64,7 +64,13 @@ class AssetAccountIbansTest extends TestCase $two->name = 'Else'; $two->account_type_id = $loan->id; - $collection = new Collection([$one, $two]); + $three = new Account; + $three->id = 66; + $three->name = 'I have IBAN'; + $three->iban = 'IBAN'; + $three->account_type_id = $loan->id; + + $collection = new Collection([$one, $two, $three]); $repository = $this->mock(AccountRepositoryInterface::class); $repository->shouldReceive('getAccountsByType')->withArgs( @@ -73,11 +79,12 @@ class AssetAccountIbansTest extends TestCase $mapper = new AssetAccountIbans(); $mapping = $mapper->getMap(); - $this->assertCount(3, $mapping); + $this->assertCount(4, $mapping); // assert this is what the result looks like: $result = [ 0 => (string)trans('import.map_do_not_map'), 53 => 'Else (liability)', + 66 => 'IBAN (I have IBAN) (liability)', 17 => 'IBAN (Something)', ]; $this->assertEquals($result, $mapping); diff --git a/tests/Unit/Import/Mapper/OpposingAccountIbansTest.php b/tests/Unit/Import/Mapper/OpposingAccountIbansTest.php index 8eb1370518..2d8366d8b5 100644 --- a/tests/Unit/Import/Mapper/OpposingAccountIbansTest.php +++ b/tests/Unit/Import/Mapper/OpposingAccountIbansTest.php @@ -64,7 +64,13 @@ class OpposingAccountIbansTest extends TestCase $two->name = 'Else'; $two->account_type_id = $loan->id; - $collection = new Collection([$one, $two]); + $three = new Account; + $three->id = 66; + $three->name = 'I have IBAN'; + $three->iban = 'IBAN'; + $three->account_type_id = $loan->id; + + $collection = new Collection([$one, $two, $three]); $repository = $this->mock(AccountRepositoryInterface::class); $repository->shouldReceive('getAccountsByType')->withArgs( @@ -74,11 +80,12 @@ class OpposingAccountIbansTest extends TestCase $mapper = new OpposingAccountIbans(); $mapping = $mapper->getMap(); - $this->assertCount(3, $mapping); + $this->assertCount(4, $mapping); // assert this is what the result looks like: $result = [ 0 => (string)trans('import.map_do_not_map'), 17 => 'Else (liability)', + 66 => 'IBAN (I have IBAN) (liability)', 21 => 'IBAN (Something)', ]; $this->assertEquals($result, $mapping);