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

@@ -127,12 +127,14 @@ class ChooseAccountsHandlerTest extends TestCase
'account_mapping' => [
'1234' => '456',
],
'apply_rules' => true,
];
$config = [
'accounts' => [
'accounts' => [
0 => ['id' => 1234, 'name' => 'bunq'],
],
'apply-rules' => true,
];
$expected = $config;
$expected['mapping'][1234] = 456;
@@ -179,12 +181,14 @@ class ChooseAccountsHandlerTest extends TestCase
'account_mapping' => [
'1234' => '456',
],
'apply_rules' => true,
];
$config = [
'accounts' => [
'accounts' => [
0 => ['id' => 1235, 'name' => 'bunq'],
],
'apply-rules' => true,
];
$expected = $config;
$expected['mapping'][0] = 456;
@@ -231,12 +235,14 @@ class ChooseAccountsHandlerTest extends TestCase
'account_mapping' => [
'1234' => '456',
],
'apply_rules' => true,
];
$config = [
'accounts' => [
'accounts' => [
0 => ['id' => 1234, 'name' => 'bunq'],
],
'apply-rules' => true,
];
$expected = $config;
$expected['mapping'][1234] = 0;
@@ -279,11 +285,13 @@ class ChooseAccountsHandlerTest extends TestCase
$job->save();
// data:
$data = ['account_mapping' => []];
$data = ['account_mapping' => [], 'apply_rules' => true,];
$config = [
'accounts' => [
0 => ['id' => 1234, 'name' => 'bunq'],
],
'apply-rules' => true,
];
// mock stuff

View File

@@ -48,16 +48,14 @@ class NewBunqJobHandlerTest extends TestCase
$job->save();
// expected config:
$expected = [
'apply-rules' => true,
];
//$expected = [];
// mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock calls
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('getConfiguration')->andReturn([])->once();
$repository->shouldReceive('setConfiguration')->withArgs([Mockery::any(), $expected])->once();
//$repository->shouldReceive('getConfiguration')->andReturn([])->once();
//$repository->shouldReceive('setConfiguration')->withArgs([Mockery::any(), $expected])->once();
$handler = new NewBunqJobHandler();
$handler->setImportJob($job);

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
*/