Expand tests.

This commit is contained in:
James Cole
2017-03-05 13:21:36 +01:00
parent 57fb75bef4
commit 2fbeaaccd3
9 changed files with 367 additions and 21 deletions

View File

@@ -23,7 +23,6 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\ExportJob; use FireflyIII\Models\ExportJob;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface; use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface;
use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface as EJRI;
use Illuminate\Http\Response as LaravelResponse; use Illuminate\Http\Response as LaravelResponse;
use Preferences; use Preferences;
use Response; use Response;
@@ -55,8 +54,8 @@ class ExportController extends Controller
} }
/** /**
* @param EJRI $repository * @param ExportJobRepositoryInterface $repository
* @param ExportJob $job * @param ExportJob $job
* *
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
* @throws FireflyException * @throws FireflyException
@@ -103,12 +102,12 @@ class ExportController extends Controller
} }
/** /**
* @param AccountRepositoryInterface $repository * @param AccountRepositoryInterface $repository
* @param EJRI $jobs * @param ExportJobRepositoryInterface $jobs
* *
* @return View * @return View
*/ */
public function index(AccountRepositoryInterface $repository, EJRI $jobs) public function index(AccountRepositoryInterface $repository, ExportJobRepositoryInterface $jobs)
{ {
// create new export job. // create new export job.
$job = $jobs->create(); $job = $jobs->create();
@@ -129,13 +128,13 @@ class ExportController extends Controller
} }
/** /**
* @param ExportFormRequest $request * @param ExportFormRequest $request
* @param AccountRepositoryInterface $repository * @param AccountRepositoryInterface $repository
* @param EJRI $jobs * @param ExportJobRepositoryInterface $jobs
* *
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
public function postIndex(ExportFormRequest $request, AccountRepositoryInterface $repository, EJRI $jobs) public function postIndex(ExportFormRequest $request, AccountRepositoryInterface $repository, ExportJobRepositoryInterface $jobs)
{ {
$job = $jobs->findByKey($request->get('job')); $job = $jobs->findByKey($request->get('job'));
$settings = [ $settings = [

View File

@@ -17,7 +17,7 @@ use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@@ -97,11 +97,11 @@ class HomeController extends Controller
} }
/** /**
* @param ARI $repository * @param AccountRepositoryInterface $repository
* *
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
*/ */
public function index(ARI $repository) public function index(AccountRepositoryInterface $repository)
{ {
$types = config('firefly.accountTypesByIdentifier.asset'); $types = config('firefly.accountTypesByIdentifier.asset');
$count = $repository->count($types); $count = $repository->count($types);

View File

@@ -33,6 +33,24 @@ $factory->define(
} }
); );
$factory->define(
FireflyIII\Models\Tag::class, function (Faker\Generator $faker) {
return [
'id' => $faker->numberBetween(1, 10),
'tag' => $faker->words(1, true),
];
}
);
$factory->define(
FireflyIII\Models\Category::class, function (Faker\Generator $faker) {
return [
'id' => $faker->numberBetween(1, 10),
'name' => $faker->words(3, true),
];
}
);
$factory->define( $factory->define(
FireflyIII\Models\Budget::class, function (Faker\Generator $faker) { FireflyIII\Models\Budget::class, function (Faker\Generator $faker) {
return [ return [

View File

@@ -11,9 +11,18 @@ declare(strict_types = 1);
namespace Tests\Feature\Controllers; namespace Tests\Feature\Controllers;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection;
use Tests\TestCase; use Tests\TestCase;
/**
* Class CurrencyControllerTest
*
* @package Tests\Feature\Controllers
*/
class CurrencyControllerTest extends TestCase class CurrencyControllerTest extends TestCase
{ {
@@ -22,6 +31,10 @@ class CurrencyControllerTest extends TestCase
*/ */
public function testCreate() public function testCreate()
{ {
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('currencies.create')); $response = $this->get(route('currencies.create'));
$response->assertStatus(200); $response->assertStatus(200);
@@ -34,6 +47,10 @@ class CurrencyControllerTest extends TestCase
*/ */
public function testDefaultCurrency() public function testDefaultCurrency()
{ {
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('currencies.default', [1])); $response = $this->get(route('currencies.default', [1]));
$response->assertStatus(302); $response->assertStatus(302);
@@ -45,6 +62,12 @@ class CurrencyControllerTest extends TestCase
*/ */
public function testDelete() public function testDelete()
{ {
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('canDeleteCurrency')->andReturn(true);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('currencies.delete', [2])); $response = $this->get(route('currencies.delete', [2]));
$response->assertStatus(200); $response->assertStatus(200);
@@ -57,11 +80,16 @@ class CurrencyControllerTest extends TestCase
*/ */
public function testDestroy() public function testDestroy()
{ {
$this->session(['currencies.delete.url' => 'http://localhost']); // mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class); $repository = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('canDeleteCurrency')->andReturn(true); $repository->shouldReceive('canDeleteCurrency')->andReturn(true);
$repository->shouldReceive('destroy')->andReturn(true); $repository->shouldReceive('destroy')->andReturn(true);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->session(['currencies.delete.url' => 'http://localhost']);
$this->be($this->user()); $this->be($this->user());
$response = $this->post(route('currencies.destroy', [1])); $response = $this->post(route('currencies.destroy', [1]));
$response->assertStatus(302); $response->assertStatus(302);
@@ -73,6 +101,10 @@ class CurrencyControllerTest extends TestCase
*/ */
public function testEdit() public function testEdit()
{ {
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('currencies.edit', [2])); $response = $this->get(route('currencies.edit', [2]));
$response->assertStatus(200); $response->assertStatus(200);
@@ -86,6 +118,13 @@ class CurrencyControllerTest extends TestCase
*/ */
public function testIndex() public function testIndex()
{ {
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('getCurrencyByPreference')->andReturn(new TransactionCurrency);
$repository->shouldReceive('get')->andReturn(new Collection);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('currencies.index')); $response = $this->get(route('currencies.index'));
$response->assertStatus(200); $response->assertStatus(200);
@@ -98,6 +137,12 @@ class CurrencyControllerTest extends TestCase
*/ */
public function testStore() public function testStore()
{ {
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('store')->andReturn(new TransactionCurrency);
$this->session(['currencies.create.url' => 'http://localhost']); $this->session(['currencies.create.url' => 'http://localhost']);
$data = [ $data = [
'name' => 'XX', 'name' => 'XX',
@@ -116,6 +161,12 @@ class CurrencyControllerTest extends TestCase
*/ */
public function testUpdate() public function testUpdate()
{ {
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('update')->andReturn(new TransactionCurrency);
$this->session(['currencies.edit.url' => 'http://localhost']); $this->session(['currencies.edit.url' => 'http://localhost']);
$data = [ $data = [
'name' => 'XA', 'name' => 'XA',

View File

@@ -13,12 +13,20 @@ namespace Tests\Feature\Controllers;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Export\ProcessorInterface; use FireflyIII\Export\ProcessorInterface;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\ExportJob; use FireflyIII\Models\ExportJob;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface; use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Tests\TestCase; use Tests\TestCase;
/**
* Class ExportControllerTest
*
* @package Tests\Feature\Controllers
*/
class ExportControllerTest extends TestCase class ExportControllerTest extends TestCase
{ {
@@ -27,7 +35,11 @@ class ExportControllerTest extends TestCase
*/ */
public function testDownload() public function testDownload()
{ {
$repository = $this->mock(ExportJobRepositoryInterface::class); // mock stuff
$repository = $this->mock(ExportJobRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('exists')->once()->andReturn(true); $repository->shouldReceive('exists')->once()->andReturn(true);
$repository->shouldReceive('getContent')->once()->andReturn('Some content beep boop'); $repository->shouldReceive('getContent')->once()->andReturn('Some content beep boop');
@@ -41,6 +53,10 @@ class ExportControllerTest extends TestCase
*/ */
public function testGetStatus() public function testGetStatus()
{ {
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('export.status', ['testExport'])); $response = $this->get(route('export.status', ['testExport']));
$response->assertStatus(200); $response->assertStatus(200);
@@ -52,6 +68,15 @@ class ExportControllerTest extends TestCase
*/ */
public function testIndex() public function testIndex()
{ {
// mock stuff
$repository = $this->mock(ExportJobRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('create')->andReturn(new ExportJob);
$repository->shouldReceive('cleanup');
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('export.index')); $response = $this->get(route('export.index'));
$response->assertStatus(200); $response->assertStatus(200);
@@ -65,13 +90,19 @@ class ExportControllerTest extends TestCase
*/ */
public function testPostIndex() public function testPostIndex()
{ {
// mock stuff
$repository = $this->mock(ExportJobRepositoryInterface::class);
$processor = $this->mock(ProcessorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
$this->session( $this->session(
['first' => new Carbon('2014-01-01')] ['first' => new Carbon('2014-01-01')]
); );
$data = [ $data = [
'export_start_range' => '2015-01-01', 'export_start_range' => '2015-01-01',
'export_end_range' => '2015-01-21', 'export_end_range' => '2015-01-21',
'exportFormat' => 'csv', 'exportFormat' => 'csv',
@@ -79,17 +110,14 @@ class ExportControllerTest extends TestCase
'job' => 'testExport', 'job' => 'testExport',
]; ];
$accountRepository = $this->mock(AccountRepositoryInterface::class); $accountRepos->shouldReceive('getAccountsById')->withArgs([$data['accounts']])->andReturn(new Collection);
$accountRepository->shouldReceive('getAccountsById')->withArgs([$data['accounts']])->andReturn(new Collection);
$processor = $this->mock(ProcessorInterface::class);
$processor->shouldReceive('setSettings')->once(); $processor->shouldReceive('setSettings')->once();
$processor->shouldReceive('collectJournals')->once(); $processor->shouldReceive('collectJournals')->once();
$processor->shouldReceive('convertJournals')->once(); $processor->shouldReceive('convertJournals')->once();
$processor->shouldReceive('exportJournals')->once(); $processor->shouldReceive('exportJournals')->once();
$processor->shouldReceive('createZipFile')->once(); $processor->shouldReceive('createZipFile')->once();
$repository = $this->mock(ExportJobRepositoryInterface::class);
$repository->shouldReceive('changeStatus')->andReturn(true); $repository->shouldReceive('changeStatus')->andReturn(true);
$repository->shouldReceive('findByKey')->andReturn(new ExportJob); $repository->shouldReceive('findByKey')->andReturn(new ExportJob);

View File

@@ -14,6 +14,11 @@ namespace Tests\Feature\Controllers;
use FireflyIII\Helpers\Help\HelpInterface; use FireflyIII\Helpers\Help\HelpInterface;
use Tests\TestCase; use Tests\TestCase;
/**
* Class HelpControllerTest
*
* @package Tests\Feature\Controllers
*/
class HelpControllerTest extends TestCase class HelpControllerTest extends TestCase
{ {

View File

@@ -11,8 +11,21 @@ declare(strict_types = 1);
namespace Tests\Feature\Controllers; namespace Tests\Feature\Controllers;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection;
use Tests\TestCase; use Tests\TestCase;
/**
* Class HomeControllerTest
*
* @package Tests\Feature\Controllers
*/
class HomeControllerTest extends TestCase class HomeControllerTest extends TestCase
{ {
/** /**
@@ -21,6 +34,10 @@ class HomeControllerTest extends TestCase
*/ */
public function testDateRange() public function testDateRange()
{ {
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
@@ -39,6 +56,10 @@ class HomeControllerTest extends TestCase
*/ */
public function testDisplayError() public function testDisplayError()
{ {
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('error')); $response = $this->get(route('error'));
$response->assertStatus(500); $response->assertStatus(500);
@@ -49,6 +70,10 @@ class HomeControllerTest extends TestCase
*/ */
public function testFlush() public function testFlush()
{ {
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('flush')); $response = $this->get(route('flush'));
$response->assertStatus(302); $response->assertStatus(302);
@@ -64,17 +89,61 @@ class HomeControllerTest extends TestCase
*/ */
public function testIndex(string $range) public function testIndex(string $range)
{ {
// mock stuff
$account = factory(Account::class)->make();
$collector = $this->mock(JournalCollectorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$billRepos = $this->mock(BillRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('count')->andReturn(1);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection([$account]));
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$billRepos->shouldReceive('getBills')->andReturn(new Collection);
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
$response = $this->get(route('index')); $response = $this->get(route('index'));
$response->assertStatus(200); $response->assertStatus(200);
} }
/**
* @covers \FireflyIII\Http\Controllers\HomeController::index
* @covers \FireflyIII\Http\Controllers\HomeController::__construct
* @covers \FireflyIII\Http\Controllers\Controller::__construct
* @dataProvider dateRangeProvider
*
* @param $range
*/
public function testIndexEmpty(string $range)
{
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('count')->andReturn(0);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('index'));
$response->assertStatus(302);
}
/** /**
* @covers \FireflyIII\Http\Controllers\HomeController::testFlash * @covers \FireflyIII\Http\Controllers\HomeController::testFlash
*/ */
public function testTestFlash() public function testTestFlash()
{ {
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('test-flash')); $response = $this->get(route('test-flash'));
$response->assertStatus(302); $response->assertStatus(302);

View File

@@ -13,16 +13,28 @@ namespace Tests\Feature\Controllers;
use FireflyIII\Import\ImportProcedureInterface; use FireflyIII\Import\ImportProcedureInterface;
use FireflyIII\Import\Setup\CsvSetup; use FireflyIII\Import\Setup\CsvSetup;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Http\UploadedFile; use Illuminate\Http\UploadedFile;
use Tests\TestCase; use Tests\TestCase;
/**
* Class ImportControllerTest
*
* @package Tests\Feature\Controllers
*/
class ImportControllerTest extends TestCase class ImportControllerTest extends TestCase
{ {
/** /**
* @covers \FireflyIII\Http\Controllers\ImportController::complete * @covers \FireflyIII\Http\Controllers\ImportController::complete
* @covers \FireflyIII\Http\Controllers\ImportController::jobInCorrectStep
* @covers \FireflyIII\Http\Controllers\ImportController::redirectToCorrectStep
*/ */
public function testComplete() public function testComplete()
{ {
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('import.complete', ['complete'])); $response = $this->get(route('import.complete', ['complete']));
$response->assertStatus(200); $response->assertStatus(200);
@@ -31,9 +43,18 @@ class ImportControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\ImportController::configure * @covers \FireflyIII\Http\Controllers\ImportController::configure
* @covers \FireflyIII\Http\Controllers\ImportController::makeImporter
*/ */
public function testConfigure() public function testConfigure()
{ {
$setup = $this->mock(CsvSetup::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$setup->shouldReceive('setJob')->once();
$setup->shouldReceive('configure')->once();
$setup->shouldReceive('getConfigurationData')->andReturn(['specifics' => [], 'delimiters' => [], 'accounts' => []])->once();
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('import.configure', ['configure'])); $response = $this->get(route('import.configure', ['configure']));
$response->assertStatus(200); $response->assertStatus(200);
@@ -45,10 +66,19 @@ class ImportControllerTest extends TestCase
*/ */
public function testDownload() public function testDownload()
{ {
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('import.download', ['configure'])); $response = $this->get(route('import.download', ['configure']));
$response->assertStatus(200); $response->assertStatus(200);
$response->assertSee('[]'); $response->assertJson(
[
'delimiter' => 'tab',
'column-roles-complete' => false,
'column-mapping-complete' => false,
]
);
} }
/** /**
@@ -56,6 +86,9 @@ class ImportControllerTest extends TestCase
*/ */
public function testFinished() public function testFinished()
{ {
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('import.finished', ['finished'])); $response = $this->get(route('import.finished', ['finished']));
$response->assertStatus(200); $response->assertStatus(200);
@@ -68,6 +101,9 @@ class ImportControllerTest extends TestCase
*/ */
public function testIndex() public function testIndex()
{ {
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('import.index')); $response = $this->get(route('import.index'));
$response->assertStatus(200); $response->assertStatus(200);
@@ -78,6 +114,9 @@ class ImportControllerTest extends TestCase
*/ */
public function testJson() public function testJson()
{ {
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('import.json', ['configure'])); $response = $this->get(route('import.json', ['configure']));
$response->assertStatus(200); $response->assertStatus(200);
@@ -88,6 +127,9 @@ class ImportControllerTest extends TestCase
*/ */
public function testPostConfigure() public function testPostConfigure()
{ {
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$importer = $this->mock(CsvSetup::class); $importer = $this->mock(CsvSetup::class);
$importer->shouldReceive('setJob')->once(); $importer->shouldReceive('setJob')->once();
$importer->shouldReceive('saveImportConfiguration')->once(); $importer->shouldReceive('saveImportConfiguration')->once();
@@ -104,6 +146,9 @@ class ImportControllerTest extends TestCase
*/ */
public function testPostSettings() public function testPostSettings()
{ {
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$importer = $this->mock(CsvSetup::class); $importer = $this->mock(CsvSetup::class);
$importer->shouldReceive('setJob')->once(); $importer->shouldReceive('setJob')->once();
$importer->shouldReceive('storeSettings')->once(); $importer->shouldReceive('storeSettings')->once();
@@ -119,6 +164,9 @@ class ImportControllerTest extends TestCase
*/ */
public function testSettings() public function testSettings()
{ {
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$importer = $this->mock(CsvSetup::class); $importer = $this->mock(CsvSetup::class);
$importer->shouldReceive('setJob')->once(); $importer->shouldReceive('setJob')->once();
$importer->shouldReceive('requireUserSettings')->once()->andReturn(false); $importer->shouldReceive('requireUserSettings')->once()->andReturn(false);
@@ -133,6 +181,9 @@ class ImportControllerTest extends TestCase
*/ */
public function testStart() public function testStart()
{ {
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
/** @var ImportProcedureInterface $procedure */ /** @var ImportProcedureInterface $procedure */
$procedure = $this->mock(ImportProcedureInterface::class); $procedure = $this->mock(ImportProcedureInterface::class);
@@ -149,6 +200,9 @@ class ImportControllerTest extends TestCase
*/ */
public function testStatus() public function testStatus()
{ {
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
// complete // complete
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('import.status', ['complete'])); $response = $this->get(route('import.status', ['complete']));
@@ -160,6 +214,9 @@ class ImportControllerTest extends TestCase
*/ */
public function testUpload() public function testUpload()
{ {
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
$path = resource_path('stubs/csv.csv'); $path = resource_path('stubs/csv.csv');
$file = new UploadedFile($path, 'upload.csv', filesize($path), 'text/csv', null, true); $file = new UploadedFile($path, 'upload.csv', filesize($path), 'text/csv', null, true);
$response = $this->post(route('import.upload'), [], [], ['import_file' => $file], ['Accept' => 'application/json']); $response = $this->post(route('import.upload'), [], [], ['import_file' => $file], ['Accept' => 'application/json']);

View File

@@ -11,8 +11,26 @@ declare(strict_types = 1);
namespace Tests\Feature\Controllers; namespace Tests\Feature\Controllers;
use Amount;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Support\Collection;
use Tests\TestCase; use Tests\TestCase;
/**
* Class JsonControllerTest
*
* @package Tests\Feature\Controllers
*/
class JsonControllerTest extends TestCase class JsonControllerTest extends TestCase
{ {
@@ -21,6 +39,10 @@ class JsonControllerTest extends TestCase
*/ */
public function testAction() public function testAction()
{ {
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('json.action')); $response = $this->get(route('json.action'));
$response->assertStatus(200); $response->assertStatus(200);
@@ -31,9 +53,16 @@ class JsonControllerTest extends TestCase
*/ */
public function testBoxBillsPaid() public function testBoxBillsPaid()
{ {
// mock stuff
$billRepos = $this->mock(BillRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$billRepos->shouldReceive('getBillsUnpaidInRange')->andReturn('100');
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('json.box.paid')); $response = $this->get(route('json.box.paid'));
$response->assertStatus(200); $response->assertStatus(200);
$response->assertExactJson(['amount' => Amount::format('100', false), 'amount_raw' => '100', 'box' => 'bills-unpaid']);
} }
/** /**
@@ -41,9 +70,17 @@ class JsonControllerTest extends TestCase
*/ */
public function testBoxBillsUnpaid() public function testBoxBillsUnpaid()
{ {
// mock stuff
$billRepos = $this->mock(BillRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$billRepos->shouldReceive('getBillsPaidInRange')->andReturn('-100');
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('json.box.unpaid')); $response = $this->get(route('json.box.unpaid'));
$response->assertStatus(200); $response->assertStatus(200);
$response->assertExactJson(['amount' => Amount::format('100', false), 'amount_raw' => '100', 'box' => 'bills-paid']);
} }
/** /**
@@ -51,9 +88,21 @@ class JsonControllerTest extends TestCase
*/ */
public function testBoxIn() public function testBoxIn()
{ {
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$tasker = $this->mock(AccountTaskerInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH])])->once()->andReturn(
new Collection
);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([([AccountType::DEFAULT, AccountType::ASSET])])->once()->andReturn(new Collection);
$tasker->shouldReceive('amountInInPeriod')->andReturn('100');
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('json.box.in')); $response = $this->get(route('json.box.in'));
$response->assertStatus(200); $response->assertStatus(200);
$response->assertExactJson(['amount' => Amount::format('100', false), 'amount_raw' => '100', 'box' => 'in']);
} }
/** /**
@@ -61,9 +110,21 @@ class JsonControllerTest extends TestCase
*/ */
public function testBoxOut() public function testBoxOut()
{ {
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$tasker = $this->mock(AccountTaskerInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH])])->once()->andReturn(
new Collection
);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([([AccountType::DEFAULT, AccountType::ASSET])])->once()->andReturn(new Collection);
$tasker->shouldReceive('amountOutInPeriod')->andReturn('100');
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('json.box.out')); $response = $this->get(route('json.box.out'));
$response->assertStatus(200); $response->assertStatus(200);
$response->assertExactJson(['amount' => Amount::format('100', false), 'amount_raw' => '100', 'box' => 'out']);
} }
/** /**
@@ -71,9 +132,16 @@ class JsonControllerTest extends TestCase
*/ */
public function testCategories() public function testCategories()
{ {
// mock stuff
$category = factory(Category::class)->make();
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('json.categories')); $response = $this->get(route('json.categories'));
$response->assertStatus(200); $response->assertStatus(200);
$response->assertExactJson([$category->name]);
} }
/** /**
@@ -81,9 +149,14 @@ class JsonControllerTest extends TestCase
*/ */
public function testEndTour() public function testEndTour()
{ {
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->post(route('json.end-tour')); $response = $this->post(route('json.end-tour'));
$response->assertStatus(200); $response->assertStatus(200);
$response->assertExactJson(['true']);
} }
/** /**
@@ -91,9 +164,19 @@ class JsonControllerTest extends TestCase
*/ */
public function testExpenseAccounts() public function testExpenseAccounts()
{ {
// mock stuff
$account = factory(Category::class)->make();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->once()->andReturn(
new Collection([$account])
);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('json.expense-accounts')); $response = $this->get(route('json.expense-accounts'));
$response->assertStatus(200); $response->assertStatus(200);
$response->assertExactJson([$account->name]);
} }
/** /**
@@ -101,9 +184,19 @@ class JsonControllerTest extends TestCase
*/ */
public function testRevenueAccounts() public function testRevenueAccounts()
{ {
// mock stuff
$account = factory(Category::class)->make();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->once()->andReturn(
new Collection([$account])
);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('json.revenue-accounts')); $response = $this->get(route('json.revenue-accounts'));
$response->assertStatus(200); $response->assertStatus(200);
$response->assertExactJson([$account->name]);
} }
/** /**
@@ -111,9 +204,17 @@ class JsonControllerTest extends TestCase
*/ */
public function testTags() public function testTags()
{ {
// mock stuff
$tag = factory(Tag::class)->make();
$tagRepos = $this->mock(TagRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]))->once();
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('json.tags')); $response = $this->get(route('json.tags'));
$response->assertStatus(200); $response->assertStatus(200);
$response->assertExactJson([$tag->tag]);
} }
/** /**
@@ -121,6 +222,10 @@ class JsonControllerTest extends TestCase
*/ */
public function testTour() public function testTour()
{ {
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('json.tour')); $response = $this->get(route('json.tour'));
$response->assertStatus(200); $response->assertStatus(200);
@@ -131,9 +236,19 @@ class JsonControllerTest extends TestCase
*/ */
public function testTransactionJournals() public function testTransactionJournals()
{ {
// mock stuff
$collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$collector->shouldReceive('setTypes')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('json.transaction-journals', ['deposit'])); $response = $this->get(route('json.transaction-journals', ['deposit']));
$response->assertStatus(200); $response->assertStatus(200);
$response->assertExactJson([]);
} }
/** /**
@@ -141,6 +256,10 @@ class JsonControllerTest extends TestCase
*/ */
public function testTrigger() public function testTrigger()
{ {
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('json.trigger')); $response = $this->get(route('json.trigger'));
$response->assertStatus(200); $response->assertStatus(200);