Improve test coverage.

This commit is contained in:
James Cole
2019-08-29 17:53:25 +02:00
parent 91b6b86202
commit 19feefda2d
86 changed files with 3173 additions and 2626 deletions

View File

@@ -120,6 +120,7 @@ class BudgetLimitControllerTest extends TestCase
$repository->shouldReceive('setUser')->once();
// call API
Log::warning('The following error is part of a test.');
$response = $this->post(route('api.v1.budget_limits.store'), $data);
$response->assertStatus(500);
$response->assertSee('Unknown budget.');

View File

@@ -24,8 +24,11 @@ namespace Tests\Api\V1\Controllers\Chart;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;
use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
use Laravel\Passport\Passport;
use Log;
use Tests\Support\TestDataTrait;
use Tests\TestCase;
/**
@@ -36,6 +39,8 @@ use Tests\TestCase;
*/
class CategoryControllerTest extends TestCase
{
use TestDataTrait;
/**
*
*/
@@ -52,65 +57,21 @@ class CategoryControllerTest extends TestCase
public function testOverview(): void
{
$repository = $this->mock(CategoryRepositoryInterface::class);
$noCatRepos =$this->mock(NoCategoryRepositoryInterface::class);
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
$spent = [
2 => [
'name' => 'Some other category',
'spent' => [
// earned in this currency.
1 => [
'currency_decimal_places' => 2,
'currency_symbol' => 'x',
'currency_code' => 'EUR',
'currency_id' => 1,
'spent' => '-522',
],
],
],
];
$earned = [
1 => [
'name' => 'Some category',
'earned' => [
// earned in this currency.
2 => [
'currency_decimal_places' => 2,
'currency_id' => 1,
'currency_symbol' => 'x',
'currency_code' => 'EUR',
'earned' => '123',
],
],
],
];
$earnedNoCategory = [
1 => [
'currency_decimal_places' => 2,
'currency_id' => 3,
'currency_symbol' => 'x',
'currency_code' => 'EUR',
'earned' => '123',
],
];
$spentNoCategory = [
5 => [
'currency_decimal_places' => 2,
'currency_symbol' => 'x',
'currency_code' => 'EUR',
'currency_id' => 4,
'spent' => '-345',
],
];
// mock calls:
$repository->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('spentInPeriodPerCurrency')->atLeast()->once()->andReturn($spent);
$repository->shouldReceive('earnedInPeriodPerCurrency')->atLeast()->once()->andReturn($earned);
$noCatRepos->shouldReceive('setUser')->atLeast()->once();
$opsRepos->shouldReceive('setUser')->atLeast()->once();
$opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses());
$opsRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome());
$noCatRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->noCategoryListExpenses());
$noCatRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->noCategoryListIncome());
$repository->shouldReceive('earnedInPeriodPcWoCategory')->atLeast()->once()->andReturn($earnedNoCategory);
$repository->shouldReceive('spentInPeriodPcWoCategory')->atLeast()->once()->andReturn($spentNoCategory);
$parameters = [
'start' => '2019-01-01',

View File

@@ -118,6 +118,7 @@ class LinkTypeControllerTest extends TestCase
];
// test API
Log::warning('The following error is part of a test.');
$response = $this->post(route('api.v1.link_types.store'), $data, ['Accept' => 'application/json']);
$response->assertStatus(500);
$response->assertSee('You need the \"owner\"-role to do this.');
@@ -207,6 +208,7 @@ class LinkTypeControllerTest extends TestCase
];
// test API
Log::warning('The following error is part of a test.');
$response = $this->put(route('api.v1.link_types.update', [$linkType->id]), $data, ['Accept' => 'application/json']);
$response->assertStatus(500);
$response->assertSee('You cannot edit this link type ');
@@ -248,6 +250,7 @@ class LinkTypeControllerTest extends TestCase
];
// test API
Log::warning('The following error is part of a test.');
$response = $this->put(route('api.v1.link_types.update', [$linkType->id]), $data, ['Accept' => 'application/json']);
$response->assertStatus(500);
$response->assertSee('You need the \"owner\"-role to do this.');

View File

@@ -112,6 +112,7 @@ class PiggyBankControllerTest extends TestCase
];
// test API
Log::warning('The following error is part of a test.');
$response = $this->post(route('api.v1.piggy_banks.store'), $data, ['Accept' => 'application/json']);
$response->assertStatus(500);
$response->assertHeader('Content-Type', 'application/json');

View File

@@ -1256,7 +1256,7 @@ class RecurrenceControllerTest extends TestCase
[
'message' => 'The given data was invalid.',
'errors' => [
'description' => [
'repetitions' => [
'Need at least one repetition.',
],
],
@@ -1309,7 +1309,7 @@ class RecurrenceControllerTest extends TestCase
[
'message' => 'The given data was invalid.',
'errors' => [
'description' => [
'transactions' => [
'Need at least one transaction.',
],
],

View File

@@ -172,6 +172,7 @@ class RuleGroupControllerTest extends TestCase
// call API
$group = $this->user()->ruleGroups()->first();
Log::warning('The following error is part of a test.');
$response = $this->get(route('api.v1.rule_groups.test', [$group->id]), ['Accept' => 'application/json']);
$response->assertStatus(500);
$response->assertSee('{"message":"No rules in this rule group.","exception":"FireflyIII\\\\Exceptions\\\\FireflyException"');

View File

@@ -257,6 +257,7 @@ class TransactionLinkControllerTest extends TestCase
];
// test API
Log::warning('The following error is part of a test.');
$response = $this->post(route('api.v1.transaction_links.store'), $data, ['Accept' => 'application/json']);
$response->assertStatus(500);
$response->assertSee('Source or destination is NULL.'); // the creation moment.
@@ -380,6 +381,7 @@ class TransactionLinkControllerTest extends TestCase
];
// test API
Log::warning('The following error is part of a test.');
$response = $this->put(route('api.v1.transaction_links.update', $journalLink->id), $data, ['Accept' => 'application/json']);
$response->assertStatus(500);
$response->assertSee('Source or destination is NULL.'); // the creation moment.