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

View File

@@ -61,8 +61,7 @@ class CurrencyMapperTest extends TestCase
$repository = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('findNull')->once()->withArgs([$currency->id])->andReturn(null);
$repository->shouldReceive('store')->once()
->withArgs([['code' => null, 'name' => null, 'symbol' => null, 'decimal_places' => 2]])->andReturn(null);
$mapper = new CurrencyMapper();
$mapper->setUser($this->user());
@@ -161,9 +160,6 @@ class CurrencyMapperTest extends TestCase
// mock data
$repository = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('store')->once()
->withArgs([['code' => null, 'name' => null, 'symbol' => null, 'decimal_places' => 2]])->andReturn(null);
$mapper = new CurrencyMapper();
$mapper->setUser($this->user());

View File

@@ -148,6 +148,7 @@ class ImportableConverterTest extends TestCase
$opposingMapper->shouldReceive('map')->once()->withArgs([null, '45.67', $nullAccount])->andReturn($other);
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn(null);
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
$currencyMapper->shouldReceive('map')->times(2)->withArgs([$euro->id, []])->andReturn($euro);
$converter = new ImportableConverter;
@@ -173,7 +174,7 @@ class ImportableConverterTest extends TestCase
$importable = new ImportTransaction;
$importable->amount = '45.67';
$importable->date = '20180917';
$importable->meta['date-book'] = '2018-01-02';
$importable->meta['date-book'] = '20180102';
$importables = [$importable];
$job = $this->user()->importJobs()->first();
@@ -221,7 +222,7 @@ class ImportableConverterTest extends TestCase
$this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
$this->assertEquals($revenue->id, $result[0]['transactions'][0]['source_id']);
$this->assertEquals($asset->id, $result[0]['transactions'][0]['destination_id']);
$this->assertEquals($importable->meta['date-book'], $result[0]['book_date']);
$this->assertEquals('2018-01-02', $result[0]['book_date']);
}
@@ -291,8 +292,8 @@ class ImportableConverterTest extends TestCase
$importable = new ImportTransaction;
$importable->amount = '45.67';
$importable->date = '20180917';
$importable->billId = 2; // will be ignored because it's not valid.
$importable->billName = 'Some Bill'; // will be included because bill ID is not valid.
$importable->billId = 2; // will NOT be ignored despite it's not valid.
$importable->billName = 'Some Bill'; // will always be included even when bill ID is not valid.
$importables = [$importable];
$job = $this->user()->importJobs()->first();
@@ -337,7 +338,7 @@ class ImportableConverterTest extends TestCase
$this->assertEquals('transfer', $result[0]['type']);
$this->assertEquals('2018-09-17', $result[0]['date']);
$this->assertEquals([], $result[0]['tags']);
$this->assertNull($result[0]['bill_id']);
$this->assertEquals(2, $result[0]['bill_id']); // will NOT be ignored.
$this->assertEquals($importable->billName, $result[0]['bill_name']);
$this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
// since amount is positive, $asset recieves the money
@@ -357,7 +358,7 @@ class ImportableConverterTest extends TestCase
$importable->amount = '-45.67';
$importable->date = '20180917';
$importable->billId = 3; // is added to array of valid values, see below.
$importable->billName = 'Some bill'; // will be ignored because ID is valid.
$importable->billName = 'Some bill'; // will be added even when ID is valid.
$importables = [$importable];
$validMappings = [
@@ -408,7 +409,7 @@ class ImportableConverterTest extends TestCase
$this->assertEquals('2018-09-17', $result[0]['date']);
$this->assertEquals([], $result[0]['tags']);
$this->assertEquals(3, $result[0]['bill_id']);
$this->assertNull($result[0]['bill_name']);
$this->assertEquals($importable->billName, $result[0]['bill_name']);
$this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
// since amount is negative, $asset sends the money
$this->assertEquals($asset->id, $result[0]['transactions'][0]['source_id']);

View File

@@ -97,6 +97,7 @@ class StageNewHandlerTest extends TestCase
// create new customer:
$ncRequest->shouldReceive('setUser')->once();
$ncRequest->shouldReceive('getCustomer')->once()->andReturn($fakeCustomer);
$ncRequest->shouldReceive('call')->once();
// mock calls for repository:
$repository->shouldReceive('setUser')->once();