Expand test coverage.

This commit is contained in:
James Cole
2018-08-31 21:12:53 +02:00
parent 69b4632ef6
commit 13f72c73fb
16 changed files with 552 additions and 71 deletions

View File

@@ -23,11 +23,12 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Chart;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use Log;
use Steam;
use Tests\TestCase;
use Mockery;
/**
* Class ReportControllerTest
*/
@@ -47,13 +48,25 @@ class ReportControllerTest extends TestCase
*/
public function testNetWorth(): void
{
$generator = $this->mock(GeneratorInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
// mock calls:
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getMetaValue')->times(2)
->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1','0');
$accountRepos->shouldReceive('getMetaValue')
->withArgs([Mockery::any(), 'currency_id'])->andReturn(1);
$accountRepos->shouldReceive('getMetaValue')
->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
Steam::shouldReceive('balancesByAccounts')->andReturn(['5', '10']);
$generator->shouldReceive('multiSet')->andReturn([]);
$this->be($this->user());
$response = $this->get(route('chart.report.net-worth', [1, '20120101', '20120131']));
$response = $this->get(route('chart.report.net-worth', ['1,2', '20120101', '20120131']));
$response->assertStatus(200);
}

View File

@@ -87,6 +87,42 @@ class IndexControllerTest extends TestCase
$response->assertStatus(404);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController
*/
public function testCreateDemoUser(): void
{
// mock stuff:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$userRepository = $this->mock(UserRepositoryInterface::class);
$fakePrerequisites = $this->mock(FakePrerequisites::class);
$bunqPrerequisites = $this->mock(BunqPrerequisites::class);
$spectrePrerequisites = $this->mock(SpectrePrerequisites::class);
$ynabPrerequisites = $this->mock(YnabPrerequisites::class);
// fake job:
$importJob = new ImportJob;
$importJob->provider = 'spectre';
$importJob->key = 'fake_job_1';
// mock calls:
$ynabPrerequisites->shouldReceive('setUser')->times(2);
$fakePrerequisites->shouldReceive('setUser')->times(2);
$bunqPrerequisites->shouldReceive('setUser')->times(2);
$spectrePrerequisites->shouldReceive('setUser')->times(2);
$fakePrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true);
$bunqPrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true);
$spectrePrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true);
$ynabPrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true);
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->times(3);
$this->be($this->user());
$response = $this->get(route('import.create', ['spectre']));
$response->assertStatus(302);
$response->assertRedirect(route('import.index'));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController
*/

View File

@@ -124,7 +124,7 @@ class JobConfigurationControllerTest extends TestCase
// mock calls:
$configurator->shouldReceive('setImportJob')->once();
$configurator->shouldReceive('configurationComplete')->once()->andReturn(true);
$repository->shouldReceive('updateStatus')->withArgs([Mockery::any(), 'ready_to_run']);
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run']);
$this->be($this->user());
$response = $this->get(route('import.job.configuration.index', [$job->key]));
@@ -216,7 +216,7 @@ class JobConfigurationControllerTest extends TestCase
// mock calls:
$configurator->shouldReceive('setImportJob')->once();
$configurator->shouldReceive('configurationComplete')->once()->andReturn(true);
$repository->shouldReceive('updateStatus')->withArgs([Mockery::any(), 'ready_to_run']);
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run']);
// call thing.
$this->be($this->user());

View File

@@ -182,6 +182,37 @@ class BoxControllerTest extends TestCase
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\BoxController
*/
public function testNetWorthNoInclude(): void
{
$result = [
[
'currency' => TransactionCurrency::find(1),
'balance' => '3',
],
];
$netWorthHelper = $this->mock(NetWorthInterface::class);
$netWorthHelper->shouldReceive('setUser')->once();
$netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('0');
$this->be($this->user());
$response = $this->get(route('json.box.net-worth'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\BoxController
*/

View File

@@ -24,6 +24,7 @@ namespace Tests\Feature\Controllers\Json;
use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Services\Currency\ExchangeRateInterface;
use Log;
use Tests\TestCase;
@@ -60,6 +61,24 @@ class ExchangeControllerTest extends TestCase
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\ExchangeController
*/
public function testGetRateNull(): void
{
$repository = $this->mock(CurrencyRepositoryInterface::class);
$rate = factory(CurrencyExchangeRate::class)->make();
$repository->shouldReceive('getExchangeRate')->andReturnNull();
$interface = $this->mock(ExchangeRateInterface::class);
$interface->shouldReceive('setUser')->once();
$interface->shouldReceive('getRate')->andReturn($rate);
$this->be($this->user());
$response = $this->get(route('json.rate', ['EUR', 'USD', '20170101']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\ExchangeController
*/

View File

@@ -0,0 +1,360 @@
<?php
/**
* RecurrenceControllerTest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Json;
use Carbon\Carbon;
use FireflyIII\Models\RecurrenceRepetition;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use Log;
use Tests\TestCase;
/**
*
* Class RecurrenceControllerTest
*/
class RecurrenceControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
}
/**
* Ndom test
*
* @covers \FireflyIII\Http\Controllers\Json\RecurrenceController
*/
public function testEventsNdom(): void
{
$repository = $this->mock(RecurringRepositoryInterface::class);
// collection of dates:
$dates = [new Carbon('2018-01-01'), new Carbon('2018-01-07')];
$repository->shouldReceive('getOccurrencesInRange')->withAnyArgs()->once()
->andReturn($dates);
$parameters = [
'start' => '2018-01-01',
'end' => '2018-01-31',
'first_date' => '2018-01-01',
'ends' => 'forever',
'type' => 'ndom,1,1', // weekly on Monday
'reps' => 0,
'weekend' => RecurrenceRepetition::WEEKEND_DO_NOTHING,
'skip' => 0,
];
$this->be($this->user());
$response = $this->get(route('recurring.events') . '?' . http_build_query($parameters));
$response->assertStatus(200);
// expected data:
$expected = [
[
'id' => 'ndom20180101',
'title' => 'X',
'allDay' => true,
'start' => '2018-01-01',
'end' => '2018-01-01',
'editable' => false,
'rendering' => 'background',
],
[
'id' => 'ndom20180101',
'title' => 'X',
'allDay' => true,
'start' => '2018-01-07',
'end' => '2018-01-07',
'editable' => false,
'rendering' => 'background',
],
];
$response->assertExactJson($expected);
}
/**
* yearly, until date
*
* @covers \FireflyIII\Http\Controllers\Json\RecurrenceController
*/
public function testEventsNumberOfEvents(): void
{
$repository = $this->mock(RecurringRepositoryInterface::class);
// collection of dates:
$dates = [new Carbon('2018-01-01'), new Carbon('2018-01-07')];
$repository->shouldReceive('getXOccurrences')->withAnyArgs()->once()
->andReturn($dates);
$parameters = [
'start' => '2018-01-01',
'end' => '2018-01-31',
'first_date' => '2018-01-01',
'ends' => 'times',
'type' => 'yearly,1,1', // weekly on Monday
'reps' => 0,
'weekend' => RecurrenceRepetition::WEEKEND_DO_NOTHING,
'skip' => 0,
];
$this->be($this->user());
$response = $this->get(route('recurring.events') . '?' . http_build_query($parameters));
$response->assertStatus(200);
// expected data:
$expected = [
[
'id' => 'yearly20180101',
'title' => 'X',
'allDay' => true,
'start' => '2018-01-01',
'end' => '2018-01-01',
'editable' => false,
'rendering' => 'background',
],
[
'id' => 'yearly20180101',
'title' => 'X',
'allDay' => true,
'start' => '2018-01-07',
'end' => '2018-01-07',
'editable' => false,
'rendering' => 'background',
],
];
$response->assertExactJson($expected);
}
/**
* First date is after range, so nothing happens.
*
* @covers \FireflyIII\Http\Controllers\Json\RecurrenceController
*/
public function testEventsStartAfterEnd(): void
{
$parameters = [
'start' => '2018-01-01',
'end' => '2018-01-31',
'first_date' => '2018-02-01',
'ends' => '',
'type' => 'daily,',
'reps' => 1,
];
$this->be($this->user());
$response = $this->get(route('recurring.events') . '?' . http_build_query($parameters));
$response->assertStatus(200);
$response->assertExactJson([]);
}
/**
* yearly, until date
*
* @covers \FireflyIII\Http\Controllers\Json\RecurrenceController
*/
public function testEventsUntilDate(): void
{
$repository = $this->mock(RecurringRepositoryInterface::class);
// collection of dates:
$dates = [new Carbon('2018-01-01'), new Carbon('2018-01-07')];
$repository->shouldReceive('getOccurrencesInRange')->withAnyArgs()->once()
->andReturn($dates);
$parameters = [
'start' => '2018-01-01',
'end' => '2018-01-31',
'first_date' => '2018-01-01',
'ends' => 'until_date',
'type' => 'yearly,1,1', // weekly on Monday
'reps' => 0,
'weekend' => RecurrenceRepetition::WEEKEND_DO_NOTHING,
'skip' => 0,
];
$this->be($this->user());
$response = $this->get(route('recurring.events') . '?' . http_build_query($parameters));
$response->assertStatus(200);
// expected data:
$expected = [
[
'id' => 'yearly20180101',
'title' => 'X',
'allDay' => true,
'start' => '2018-01-01',
'end' => '2018-01-01',
'editable' => false,
'rendering' => 'background',
],
[
'id' => 'yearly20180101',
'title' => 'X',
'allDay' => true,
'start' => '2018-01-07',
'end' => '2018-01-07',
'editable' => false,
'rendering' => 'background',
],
];
$response->assertExactJson($expected);
}
/**
* Every week on Monday.
*
* @covers \FireflyIII\Http\Controllers\Json\RecurrenceController
*/
public function testEventsWeeklyMonday(): void
{
$repository = $this->mock(RecurringRepositoryInterface::class);
// collection of dates:
$dates = [new Carbon('2018-01-01'), new Carbon('2018-01-07')];
$repository->shouldReceive('getOccurrencesInRange')->withAnyArgs()->once()
->andReturn($dates);
$parameters = [
'start' => '2018-01-01',
'end' => '2018-01-31',
'first_date' => '2018-01-01',
'ends' => 'forever',
'type' => 'weekly,1', // weekly on Monday
'reps' => 0,
'weekend' => RecurrenceRepetition::WEEKEND_DO_NOTHING,
'skip' => 0,
];
$this->be($this->user());
$response = $this->get(route('recurring.events') . '?' . http_build_query($parameters));
$response->assertStatus(200);
// expected data:
$expected = [
[
'id' => 'weekly20180101',
'title' => 'X',
'allDay' => true,
'start' => '2018-01-01',
'end' => '2018-01-01',
'editable' => false,
'rendering' => 'background',
],
[
'id' => 'weekly20180101',
'title' => 'X',
'allDay' => true,
'start' => '2018-01-07',
'end' => '2018-01-07',
'editable' => false,
'rendering' => 'background',
],
];
$response->assertExactJson($expected);
}
/**
* yearly
*
* @covers \FireflyIII\Http\Controllers\Json\RecurrenceController
*/
public function testEventsYearly(): void
{
$repository = $this->mock(RecurringRepositoryInterface::class);
// collection of dates:
$dates = [new Carbon('2018-01-01'), new Carbon('2018-01-07')];
$repository->shouldReceive('getOccurrencesInRange')->withAnyArgs()->once()
->andReturn($dates);
$parameters = [
'start' => '2018-01-01',
'end' => '2018-01-31',
'first_date' => '2018-01-01',
'ends' => 'forever',
'type' => 'yearly,1,1', // weekly on Monday
'reps' => 0,
'weekend' => RecurrenceRepetition::WEEKEND_DO_NOTHING,
'skip' => 0,
];
$this->be($this->user());
$response = $this->get(route('recurring.events') . '?' . http_build_query($parameters));
$response->assertStatus(200);
// expected data:
$expected = [
[
'id' => 'yearly20180101',
'title' => 'X',
'allDay' => true,
'start' => '2018-01-01',
'end' => '2018-01-01',
'editable' => false,
'rendering' => 'background',
],
[
'id' => 'yearly20180101',
'title' => 'X',
'allDay' => true,
'start' => '2018-01-07',
'end' => '2018-01-07',
'editable' => false,
'rendering' => 'background',
],
];
$response->assertExactJson($expected);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\RecurrenceController
*/
public function testSuggest(): void
{
$this->be($this->user());
$parameters = [
'past' => 'true',
'pre_select' => 'daily',
'date' => '2018-01-01',
];
$response = $this->get(route('recurring.suggest') . '?' . http_build_query($parameters));
$response->assertStatus(200);
$expected = [
'daily' => ['label' => 'Every day', 'selected' => true],
'monthly,1' => ['label' => 'Every month on the 1(st/nd/rd/th) day', 'selected' => false],
'ndom,1,1' => ['label' => 'Every month on the 1(st/nd/rd/th) Monday', 'selected' => false],
'weekly,1' => ['label' => 'Every week on Monday', 'selected' => false],
'yearly,2018-01-01' => ['label' => 'Every year on January 1', 'selected' => false],
];
$response->assertExactJson($expected);
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* CreateControllerTest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Recurring;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
*
* Class CreateControllerTest
*/
class CreateControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
}
public function testCreate() {
$recurringRepos =$this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection)->once();
\Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(1));
$this->be($this->user());
$response = $this->get(route('recurring.create'));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
}

View File

@@ -115,6 +115,7 @@ class SelectControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$matcher->shouldReceive('setStrict')->once()->withArgs([false]);
$matcher->shouldReceive('setLimit')->withArgs([10])->andReturnSelf()->once();
$matcher->shouldReceive('setRange')->withArgs([200])->andReturnSelf()->once();
$matcher->shouldReceive('setTriggers')->andReturnSelf()->once();
@@ -180,6 +181,8 @@ class SelectControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$matcher->shouldReceive('setStrict')->once()->withArgs([false]);
$matcher->shouldReceive('setLimit')->withArgs([10])->andReturnSelf()->once();
$matcher->shouldReceive('setRange')->withArgs([200])->andReturnSelf()->once();
$matcher->shouldReceive('setTriggers')->andReturnSelf()->once();