mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Refactor and rename test code.
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Support\Import\Configuration\File;
|
||||
namespace Tests\Unit\Support\Import\JobConfiguration\File;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
@@ -31,7 +31,7 @@ use FireflyIII\Import\Specifics\IngDescription;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\Configuration\File\ConfigureMappingHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Csv\Exception;
|
||||
use League\Csv\Reader;
|
||||
@@ -41,12 +41,11 @@ use Tests\TestCase;
|
||||
/**
|
||||
* Class ConfigureMappingHandlerTest
|
||||
*
|
||||
* @package Tests\Unit\Support\Import\Configuration\File
|
||||
*/
|
||||
class ConfigureMappingHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureMappingHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
|
||||
*/
|
||||
public function testApplySpecifics(): void
|
||||
{
|
||||
@@ -81,7 +80,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureMappingHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
|
||||
*/
|
||||
public function testConfigureJob(): void
|
||||
{
|
||||
@@ -145,7 +144,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureMappingHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
|
||||
*/
|
||||
public function testDoColumnConfig(): void
|
||||
{
|
||||
@@ -208,7 +207,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureMappingHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
|
||||
*/
|
||||
public function testDoMapOfColumn(): void
|
||||
{
|
||||
@@ -238,7 +237,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureMappingHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
|
||||
*/
|
||||
public function testGetNextData(): void
|
||||
{
|
||||
@@ -319,7 +318,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureMappingHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
|
||||
*/
|
||||
public function testGetPreProcessorName(): void
|
||||
{
|
||||
@@ -347,7 +346,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureMappingHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
|
||||
*/
|
||||
public function testGetReader(): void
|
||||
{
|
||||
@@ -395,7 +394,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureMappingHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
|
||||
*/
|
||||
public function testGetValuesForMapping(): void
|
||||
{
|
||||
@@ -462,7 +461,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureMappingHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureMappingHandler
|
||||
*/
|
||||
public function testSanitizeColumnName(): void
|
||||
{
|
@@ -21,7 +21,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Support\Import\Configuration\File;
|
||||
namespace Tests\Unit\Support\Import\JobConfiguration\File;
|
||||
|
||||
|
||||
use Exception;
|
||||
@@ -31,7 +31,7 @@ use FireflyIII\Import\Specifics\IngDescription;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Csv\Reader;
|
||||
use Mockery;
|
||||
@@ -43,7 +43,7 @@ use Tests\TestCase;
|
||||
class ConfigureRolesHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
|
||||
*/
|
||||
public function testConfigurationCompleteBasic(): void
|
||||
{
|
||||
@@ -63,7 +63,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
|
||||
*/
|
||||
public function testConfigurationCompleteForeign(): void
|
||||
{
|
||||
@@ -87,7 +87,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
|
||||
*/
|
||||
public function testConfigurationCompleteNoAmount(): void
|
||||
{
|
||||
@@ -111,7 +111,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
|
||||
*/
|
||||
public function testConfigureJob(): void
|
||||
{
|
||||
@@ -164,7 +164,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
|
||||
*/
|
||||
public function testGetExampleFromLine(): void
|
||||
{
|
||||
@@ -187,7 +187,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
|
||||
*/
|
||||
public function testGetExamplesFromFile(): void
|
||||
{
|
||||
@@ -225,7 +225,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
|
||||
*/
|
||||
public function testGetHeadersHas(): void
|
||||
{
|
||||
@@ -246,7 +246,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
|
||||
*/
|
||||
public function testGetHeadersNone(): void
|
||||
{
|
||||
@@ -334,7 +334,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
|
||||
*/
|
||||
public function testGetReader(): void
|
||||
{
|
||||
@@ -382,7 +382,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
|
||||
*/
|
||||
public function testIgnoreUnmappableColumns(): void
|
||||
{
|
||||
@@ -425,7 +425,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
|
||||
*/
|
||||
public function testIsMappingNecessaryNo(): void
|
||||
{
|
||||
@@ -438,7 +438,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
|
||||
*/
|
||||
public function testIsMappingNecessaryYes(): void
|
||||
{
|
||||
@@ -451,7 +451,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
|
||||
*/
|
||||
public function testMakeExamplesUnique(): void
|
||||
{
|
||||
@@ -477,7 +477,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
|
||||
*/
|
||||
public function testProcessSpecifics(): void
|
||||
{
|
||||
@@ -498,7 +498,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureRolesHandler
|
||||
*/
|
||||
public function testSaveColumCount(): void
|
||||
{
|
@@ -21,13 +21,13 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Support\Import\Configuration\File;
|
||||
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\Configuration\File\ConfigureUploadHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\File\ConfigureUploadHandler;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -37,7 +37,7 @@ use Tests\TestCase;
|
||||
class ConfigureUploadHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureUploadHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureUploadHandler
|
||||
*/
|
||||
public function testConfigureJobAccount(): void
|
||||
{
|
||||
@@ -86,7 +86,7 @@ class ConfigureUploadHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureUploadHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureUploadHandler
|
||||
*/
|
||||
public function testConfigureJobNoAccount(): void
|
||||
{
|
||||
@@ -134,7 +134,7 @@ class ConfigureUploadHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureUploadHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureUploadHandler
|
||||
*/
|
||||
public function testGetNextData(): void
|
||||
{
|
||||
@@ -164,7 +164,7 @@ class ConfigureUploadHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\ConfigureUploadHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\ConfigureUploadHandler
|
||||
*/
|
||||
public function testGetSpecifics(): void
|
||||
{
|
@@ -21,7 +21,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Support\Import\Configuration\File;
|
||||
namespace Tests\Unit\Support\Import\JobConfiguration\File;
|
||||
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
@@ -29,7 +29,7 @@ use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\Configuration\File\NewFileJobHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\File\NewFileJobHandler;
|
||||
use Illuminate\Support\Collection;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
@@ -40,7 +40,7 @@ use Tests\TestCase;
|
||||
class NewFileJobHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\NewFileJobHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\NewFileJobHandler
|
||||
*/
|
||||
public function testConfigureJob(): void
|
||||
{
|
||||
@@ -95,7 +95,7 @@ class NewFileJobHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\NewFileJobHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\NewFileJobHandler
|
||||
*/
|
||||
public function testConfigureJobBadData(): void
|
||||
{
|
||||
@@ -153,7 +153,7 @@ class NewFileJobHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\NewFileJobHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\NewFileJobHandler
|
||||
*/
|
||||
public function testStoreConfiguration(): void
|
||||
{
|
||||
@@ -200,7 +200,7 @@ class NewFileJobHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\NewFileJobHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\NewFileJobHandler
|
||||
*/
|
||||
public function testValidateAttachments(): void
|
||||
{
|
||||
@@ -248,7 +248,7 @@ class NewFileJobHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Configuration\File\NewFileJobHandler
|
||||
* @covers \FireflyIII\Support\Import\JobConfiguration\File\NewFileJobHandler
|
||||
*/
|
||||
public function testValidateNotUTF(): void
|
||||
{
|
@@ -24,13 +24,22 @@ 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\Support\Import\Information\GetSpectreCustomerTrait;
|
||||
use FireflyIII\Services\Spectre\Request\NewCustomerRequest;
|
||||
use FireflyIII\Support\Import\Routine\Spectre\StageNewHandler;
|
||||
use Tests\TestCase;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class StageNewHandlerTest
|
||||
*/
|
||||
@@ -43,6 +52,7 @@ class StageNewHandlerTest extends TestCase
|
||||
/**
|
||||
* 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
|
||||
@@ -57,24 +67,303 @@ class StageNewHandlerTest extends TestCase
|
||||
$job->configuration = [];
|
||||
$job->save();
|
||||
|
||||
// mock classes:
|
||||
$trait = $this->mock(GetSpectreCustomerTrait::class);
|
||||
$llRequest = $this->mock(ListLoginsRequest::class);
|
||||
$lcRequest = $this->mock(ListCustomersRequest::class);
|
||||
// fake Spectre customer:
|
||||
$fakeCustomer = new Customer(
|
||||
[
|
||||
'id' => 1,
|
||||
'identifier' => 'fake',
|
||||
'secret' => 'Dumbledore dies',
|
||||
]
|
||||
);
|
||||
|
||||
// mock calls for list logins
|
||||
// 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);
|
||||
|
||||
// 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_' . random_int(1, 1000);
|
||||
$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
|
||||
// todo here we are
|
||||
Preferences::shouldReceive('getForUser');
|
||||
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);
|
||||
$handler->run();
|
||||
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_' . random_int(1, 1000);
|
||||
$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_' . random_int(1, 1000);
|
||||
$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());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user