mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
Improve test coverage, remove dead code.
This commit is contained in:
@@ -28,6 +28,7 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
@@ -1399,7 +1400,10 @@ class TransactionControllerTest extends TestCase
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
|
||||
$count = $journal->transactions()->count();
|
||||
} while ($count !== 2);
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $journal->transactions()->first();
|
||||
$transaction->description = null;
|
||||
$transaction->save();
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
|
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
/**
|
||||
* SpectreJobConfigurationTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Import\JobConfiguration;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Import\JobConfiguration\SpectreJobConfiguration;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\AuthenticateConfig;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\AuthenticatedConfigHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccount;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseLoginHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\NewConfig;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class SpectreJobConfigurationTest
|
||||
*/
|
||||
class SpectreJobConfigurationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Import\JobConfiguration\SpectreJobConfiguration
|
||||
*/
|
||||
public function testConfigurationComplete(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'spectre_jc_A' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'spectre';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// expect "NewConfig" to be created because job is new.
|
||||
$handler = $this->mock(NewConfig::class);
|
||||
$handler->shouldReceive('setImportJob')->once();
|
||||
$handler->shouldReceive('configurationComplete')->once()->andReturn(true);
|
||||
|
||||
$config = new SpectreJobConfiguration;
|
||||
try {
|
||||
$config->setImportJob($job);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertTrue($config->configurationComplete());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\JobConfiguration\SpectreJobConfiguration
|
||||
*/
|
||||
public function testConfigureJob(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'spectre_jc_B' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'authenticate';
|
||||
$job->provider = 'spectre';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
$configData = ['ssome' => 'values'];
|
||||
$return = new MessageBag();
|
||||
$return->add('some', 'return message');
|
||||
|
||||
// expect "NewConfig" to be created because job is new.
|
||||
$handler = $this->mock(AuthenticateConfig::class);
|
||||
$handler->shouldReceive('setImportJob')->once();
|
||||
$handler->shouldReceive('configureJob')->once()->withArgs([$configData])->andReturn($return);
|
||||
|
||||
$config = new SpectreJobConfiguration;
|
||||
try {
|
||||
$config->setImportJob($job);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($return, $config->configureJob($configData));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\JobConfiguration\SpectreJobConfiguration
|
||||
*/
|
||||
public function testGetNextData(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'spectre_jc_C' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'choose-login';
|
||||
$job->provider = 'spectre';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
$data = ['ssome' => 'values'];
|
||||
|
||||
$handler = $this->mock(ChooseLoginHandler::class);
|
||||
$handler->shouldReceive('setImportJob')->once();
|
||||
$handler->shouldReceive('getNextData')->once()->andReturn($data);
|
||||
|
||||
$config = new SpectreJobConfiguration;
|
||||
try {
|
||||
$config->setImportJob($job);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($data, $config->getNextData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\JobConfiguration\SpectreJobConfiguration
|
||||
*/
|
||||
public function testGetNextView(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'spectre_jc_D' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'authenticated';
|
||||
$job->provider = 'spectre';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
$handler = $this->mock(AuthenticatedConfigHandler::class);
|
||||
$handler->shouldReceive('setImportJob')->once();
|
||||
$handler->shouldReceive('getNextView')->once()->andReturn('import.fake.view');
|
||||
|
||||
$config = new SpectreJobConfiguration;
|
||||
try {
|
||||
$config->setImportJob($job);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals('import.fake.view', $config->getNextView());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\JobConfiguration\SpectreJobConfiguration
|
||||
*/
|
||||
public function testGetNextViewAccount(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'spectre_jc_E' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'choose-account';
|
||||
$job->provider = 'spectre';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
$handler = $this->mock(ChooseAccount::class);
|
||||
$handler->shouldReceive('setImportJob')->once();
|
||||
$handler->shouldReceive('getNextView')->once()->andReturn('import.fake.view2');
|
||||
|
||||
$config = new SpectreJobConfiguration;
|
||||
try {
|
||||
$config->setImportJob($job);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals('import.fake.view2', $config->getNextView());
|
||||
}
|
||||
|
||||
|
||||
}
|
245
tests/Unit/Import/Prerequisites/SpectrePrerequisitesTest.php
Normal file
245
tests/Unit/Import/Prerequisites/SpectrePrerequisitesTest.php
Normal file
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
/**
|
||||
* SpectrePrerequisitesTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Import\Prerequisites;
|
||||
|
||||
|
||||
use FireflyIII\Import\Prerequisites\SpectrePrerequisites;
|
||||
use FireflyIII\Models\Preference;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class SpectrePrerequisitesTest
|
||||
*/
|
||||
class SpectrePrerequisitesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
|
||||
*/
|
||||
public function testGetView(): void
|
||||
{
|
||||
|
||||
$object = new SpectrePrerequisites;
|
||||
$object->setUser($this->user());
|
||||
$this->assertEquals('import.spectre.prerequisites', $object->getView());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns NULL as much as possible, forcing system to generate new keys.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
|
||||
*/
|
||||
public function testGetViewParameters(): void
|
||||
{
|
||||
$publicKey = new Preference;
|
||||
$publicKey->name = 'spectre_public_key';
|
||||
$publicKey->data = '---PUBKEY---';
|
||||
|
||||
$privateKey = new Preference;
|
||||
$privateKey->name = 'spectre_private_key';
|
||||
$privateKey->data = '---PRIVKEY---';
|
||||
|
||||
// get secret
|
||||
Preferences::shouldReceive('getForUser')->once()
|
||||
->withArgs([Mockery::any(), 'spectre_secret', null])
|
||||
->andReturnNull();
|
||||
|
||||
// get App ID
|
||||
Preferences::shouldReceive('getForUser')->once()
|
||||
->withArgs([Mockery::any(), 'spectre_app_id', null])
|
||||
->andReturnNull();
|
||||
|
||||
// get users public key
|
||||
// second time it should exist.
|
||||
Preferences::shouldReceive('getForUser')->twice()
|
||||
->withArgs([Mockery::any(), 'spectre_public_key', null])
|
||||
->andReturn(null, $publicKey);
|
||||
// SET users new pulic key
|
||||
Preferences::shouldReceive('setForUser')->once()
|
||||
->withArgs([Mockery::any(), 'spectre_public_key', Mockery::any()])
|
||||
->andReturn($publicKey);
|
||||
// SET private key
|
||||
Preferences::shouldReceive('setForUser')->once()
|
||||
->withArgs([Mockery::any(), 'spectre_private_key', Mockery::any()])
|
||||
->andReturn($privateKey);
|
||||
|
||||
|
||||
$object = new SpectrePrerequisites;
|
||||
$object->setUser($this->user());
|
||||
$return = $object->getViewParameters();
|
||||
$this->assertEquals(
|
||||
[
|
||||
'app_id' => '',
|
||||
'secret' => '',
|
||||
'public_key' => '---PUBKEY---',
|
||||
], $return
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* App ID exists, secret is empty.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
|
||||
*/
|
||||
public function testIsComplete(): void
|
||||
{
|
||||
$appId = new Preference;
|
||||
$appId->name = 'spectre_app_id';
|
||||
$appId->data = 'Some app id';
|
||||
|
||||
$secret = new Preference;
|
||||
$secret->name = 'spectre_secret';
|
||||
$secret->data = 'Hello';
|
||||
// get App ID
|
||||
Preferences::shouldReceive('getForUser')->once()
|
||||
->withArgs([Mockery::any(), 'spectre_app_id', null])
|
||||
->andReturn($appId);
|
||||
|
||||
// get secret
|
||||
Preferences::shouldReceive('getForUser')->once()
|
||||
->withArgs([Mockery::any(), 'spectre_secret', null])
|
||||
->andReturn($secret);
|
||||
|
||||
$object = new SpectrePrerequisites;
|
||||
$object->setUser($this->user());
|
||||
$this->assertTrue($object->isComplete());
|
||||
}
|
||||
|
||||
/**
|
||||
* App ID exists, secret is null.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
|
||||
*/
|
||||
public function testIsCompleteAppId(): void
|
||||
{
|
||||
$appId = new Preference;
|
||||
$appId->name = 'spectre_app_id';
|
||||
$appId->data = 'Some app id';
|
||||
// get App ID
|
||||
Preferences::shouldReceive('getForUser')->once()
|
||||
->withArgs([Mockery::any(), 'spectre_app_id', null])
|
||||
->andReturn($appId);
|
||||
|
||||
// get secret
|
||||
Preferences::shouldReceive('getForUser')->once()
|
||||
->withArgs([Mockery::any(), 'spectre_secret', null])
|
||||
->andReturnNull();
|
||||
|
||||
$object = new SpectrePrerequisites;
|
||||
$object->setUser($this->user());
|
||||
$this->assertFalse($object->isComplete());
|
||||
}
|
||||
|
||||
/**
|
||||
* App ID is "" and Secret is NULL. Since App ID is "" secret won't be polled.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
|
||||
*/
|
||||
public function testIsCompleteEmpty(): void
|
||||
{
|
||||
$appId = new Preference;
|
||||
$appId->name = 'spectre_app_id';
|
||||
$appId->data = '';
|
||||
|
||||
// get App ID
|
||||
Preferences::shouldReceive('getForUser')->once()
|
||||
->withArgs([Mockery::any(), 'spectre_app_id', null])
|
||||
->andReturn($appId);
|
||||
|
||||
$object = new SpectrePrerequisites;
|
||||
$object->setUser($this->user());
|
||||
$this->assertFalse($object->isComplete());
|
||||
}
|
||||
|
||||
/**
|
||||
* App ID and Secret are NULL. Since App ID is null secret won't be polled.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
|
||||
*/
|
||||
public function testIsCompleteNull(): void
|
||||
{
|
||||
// get App ID
|
||||
Preferences::shouldReceive('getForUser')->once()
|
||||
->withArgs([Mockery::any(), 'spectre_app_id', null])
|
||||
->andReturnNull();
|
||||
|
||||
$object = new SpectrePrerequisites;
|
||||
$object->setUser($this->user());
|
||||
$this->assertFalse($object->isComplete());
|
||||
}
|
||||
|
||||
/**
|
||||
* App ID exists, secret is empty.
|
||||
*
|
||||
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
|
||||
*/
|
||||
public function testIsCompleteSecretEmpty(): void
|
||||
{
|
||||
$appId = new Preference;
|
||||
$appId->name = 'spectre_app_id';
|
||||
$appId->data = 'Some app id';
|
||||
|
||||
$secret = new Preference;
|
||||
$secret->name = 'spectre_secret';
|
||||
$secret->data = '';
|
||||
// get App ID
|
||||
Preferences::shouldReceive('getForUser')->once()
|
||||
->withArgs([Mockery::any(), 'spectre_app_id', null])
|
||||
->andReturn($appId);
|
||||
|
||||
// get secret
|
||||
Preferences::shouldReceive('getForUser')->once()
|
||||
->withArgs([Mockery::any(), 'spectre_secret', null])
|
||||
->andReturn($secret);
|
||||
|
||||
$object = new SpectrePrerequisites;
|
||||
$object->setUser($this->user());
|
||||
$this->assertFalse($object->isComplete());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers \FireflyIII\Import\Prerequisites\SpectrePrerequisites
|
||||
*/
|
||||
public function testStorePrerequisites(): void
|
||||
{
|
||||
$data = [
|
||||
'app_id' => 'Some app ID',
|
||||
'secret' => 'Very secret!',
|
||||
];
|
||||
// set values
|
||||
Preferences::shouldReceive('setForUser')->once()
|
||||
->withArgs([Mockery::any(), 'spectre_app_id', $data['app_id']])
|
||||
->andReturn(new Preference());
|
||||
Preferences::shouldReceive('setForUser')->once()
|
||||
->withArgs([Mockery::any(), 'spectre_secret', $data['secret']])
|
||||
->andReturn(new Preference());
|
||||
|
||||
$object = new SpectrePrerequisites;
|
||||
$object->setUser($this->user());
|
||||
$this->assertEquals(0, $object->storePrerequisites($data)->count());
|
||||
}
|
||||
|
||||
}
|
229
tests/Unit/Import/Routine/SpectreRoutineTest.php
Normal file
229
tests/Unit/Import/Routine/SpectreRoutineTest.php
Normal file
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
/**
|
||||
* SpectreRoutineTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Import\Routine;
|
||||
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Import\Routine\SpectreRoutine;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\Routine\Spectre\StageImportDataHandler;
|
||||
use FireflyIII\Support\Import\Routine\Spectre\StageAuthenticatedHandler;
|
||||
use FireflyIII\Support\Import\Routine\Spectre\StageNewHandler;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class SpectreRoutineTest
|
||||
*/
|
||||
class SpectreRoutineTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Routine\SpectreRoutine
|
||||
*/
|
||||
public function testRunAuthenticate(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'SRA' . random_int(1, 1000);
|
||||
$job->status = 'ready_to_run';
|
||||
$job->stage = 'authenticate';
|
||||
$job->provider = 'spectre';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock handler and repository
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// mock calls for repository
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'need_job_config'])->once();
|
||||
|
||||
$routine = new SpectreRoutine;
|
||||
$routine->setImportJob($job);
|
||||
try {
|
||||
$routine->run();
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Routine\SpectreRoutine
|
||||
*/
|
||||
public function testRunAuthenticated(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'SRA' . random_int(1, 1000);
|
||||
$job->status = 'ready_to_run';
|
||||
$job->stage = 'authenticated';
|
||||
$job->provider = 'spectre';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock handler and repository
|
||||
$handler = $this->mock(StageAuthenticatedHandler::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// mock calls for repository
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
|
||||
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'need_job_config'])->once();
|
||||
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'choose-account'])->once();
|
||||
|
||||
// mock calls for handler
|
||||
$handler->shouldReceive('setImportJob')->once();
|
||||
$handler->shouldReceive('run')->once();
|
||||
|
||||
$routine = new SpectreRoutine;
|
||||
$routine->setImportJob($job);
|
||||
try {
|
||||
$routine->run();
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Routine\SpectreRoutine
|
||||
*/
|
||||
public function testRunGoImport(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'SRA' . random_int(1, 1000);
|
||||
$job->status = 'ready_to_run';
|
||||
$job->stage = 'go-for-import';
|
||||
$job->provider = 'spectre';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock handler and repository
|
||||
$handler = $this->mock(StageImportDataHandler::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// mock calls for repository
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
|
||||
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->once();
|
||||
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'do_import'])->once();
|
||||
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once();
|
||||
|
||||
// mock calls for handler
|
||||
$handler->shouldReceive('setImportJob')->once();
|
||||
$handler->shouldReceive('run')->once();
|
||||
|
||||
$routine = new SpectreRoutine;
|
||||
$routine->setImportJob($job);
|
||||
try {
|
||||
$routine->run();
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Routine\SpectreRoutine
|
||||
*/
|
||||
public function testRunNewOneLogin(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'SRA' . random_int(1, 1000);
|
||||
$job->status = 'ready_to_run';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'spectre';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock handler and repository
|
||||
$handler = $this->mock(StageNewHandler::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// mock calls for repository
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
|
||||
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'need_job_config'])->once();
|
||||
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'choose-login'])->once();
|
||||
|
||||
// mock calls for handler
|
||||
$handler->shouldReceive('setImportJob')->once();
|
||||
$handler->shouldReceive('getCountLogins')->once()->andReturn(2);
|
||||
$handler->shouldReceive('run')->once();
|
||||
|
||||
|
||||
$routine = new SpectreRoutine;
|
||||
$routine->setImportJob($job);
|
||||
try {
|
||||
$routine->run();
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Import\Routine\SpectreRoutine
|
||||
*/
|
||||
public function testRunNewZeroLogins(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'SRA' . random_int(1, 1000);
|
||||
$job->status = 'ready_to_run';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'spectre';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock handler and repository
|
||||
$handler = $this->mock(StageNewHandler::class);
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
// mock calls for repository
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
|
||||
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run'])->once();
|
||||
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'authenticate'])->once();
|
||||
|
||||
// mock calls for handler
|
||||
$handler->shouldReceive('setImportJob')->once();
|
||||
$handler->shouldReceive('getCountLogins')->once()->andReturn(0);
|
||||
$handler->shouldReceive('run')->once();
|
||||
|
||||
|
||||
$routine = new SpectreRoutine;
|
||||
$routine->setImportJob($job);
|
||||
try {
|
||||
$routine->run();
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* StageNewHandlerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests\Unit\Support\Import\Routine\Spectre;
|
||||
|
||||
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Services\Spectre\Request\ListCustomersRequest;
|
||||
use FireflyIII\Services\Spectre\Request\ListLoginsRequest;
|
||||
use FireflyIII\Support\Import\Information\GetSpectreCustomerTrait;
|
||||
use FireflyIII\Support\Import\Routine\Spectre\StageNewHandler;
|
||||
use Tests\TestCase;
|
||||
use Preferences;
|
||||
/**
|
||||
* Class StageNewHandlerTest
|
||||
*/
|
||||
class StageNewHandlerTest extends TestCase
|
||||
{
|
||||
|
||||
// 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\Routine\Spectre\StageNewHandler
|
||||
*/
|
||||
public function testRunBasic(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'sn_a_' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'spectre';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock classes:
|
||||
$trait = $this->mock(GetSpectreCustomerTrait::class);
|
||||
$llRequest = $this->mock(ListLoginsRequest::class);
|
||||
$lcRequest = $this->mock(ListCustomersRequest::class);
|
||||
|
||||
// mock calls for list logins
|
||||
$llRequest->shouldReceive('setUser')->once();
|
||||
$llRequest->shouldReceive('setCustomer')->once();
|
||||
$llRequest->shouldReceive('call')->once();
|
||||
$llRequest->shouldReceive('getLogins')->once()->andReturn([]);
|
||||
|
||||
// mock call for preferences
|
||||
// todo here we are
|
||||
Preferences::shouldReceive('getForUser');
|
||||
|
||||
|
||||
$handler = new StageNewHandler;
|
||||
$handler->setImportJob($job);
|
||||
$handler->run();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user