Fix tests.

This commit is contained in:
James Cole
2018-07-01 09:27:22 +02:00
parent 0502f2a4a5
commit db149ca6e1
50 changed files with 551 additions and 647 deletions

View File

@@ -148,11 +148,13 @@ class ChooseAccountsHandlerTest extends TestCase
// 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,
];
@@ -175,6 +177,65 @@ class ChooseAccountsHandlerTest extends TestCase
$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' . random_int(1, 1000);
$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.
*
@@ -203,11 +264,13 @@ class ChooseAccountsHandlerTest extends TestCase
// 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,
];
@@ -260,11 +323,13 @@ class ChooseAccountsHandlerTest extends TestCase
// 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,
];
@@ -287,64 +352,6 @@ class ChooseAccountsHandlerTest extends TestCase
$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' . random_int(1, 1000);
$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,],
];
// expected configuration:
$config = [
'accounts' => [0 => ['id' => 3134, 'name' => 'Some fake account',],],
'account_mapping' => [0 => 0,],
];
// 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());
}
/**
* @covers \FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccountsHandler
*/