Delete import related tests

This commit is contained in:
James Cole
2020-03-15 15:33:00 +01:00
parent 328c960950
commit 524f85b9c1
31 changed files with 0 additions and 10326 deletions

View File

@@ -1,111 +0,0 @@
<?php
/**
* CallbackControllerTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Import;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use Log;
use Mockery;
use Tests\TestCase;
/**
*
* Class CallbackControllerTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class CallbackControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\CallbackController
*/
public function testYnabBasic(): void
{
$repository = $this->mock(ImportJobRepositoryInterface::class);
$importJob = $this->getRandomImportJob();
// config for job:
$config = [];
$newConfig = ['auth_code' => 'abc'];
$this->mockDefaultSession();
// mock calls.
$repository->shouldReceive('findByKey')->andReturn($importJob)->once();
$repository->shouldReceive('getConfiguration')->andReturn($config)->once();
$repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $newConfig]);
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'ready_to_run']);
$repository->shouldReceive('setStage')->once()->withArgs([Mockery::any(), 'get_access_token']);
$this->be($this->user());
$response = $this->get(route('import.callback.ynab') . '?code=abc&state=def');
$response->assertStatus(302);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\CallbackController
*/
public function testYnabBasicBadJob(): void
{
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock calls.
$repository->shouldReceive('findByKey')->andReturnNull()->once();
$this->mockDefaultSession();
$this->be($this->user());
$response = $this->get(route('import.callback.ynab') . '?code=abc&state=def');
$response->assertStatus(200);
$response->assertSee('You Need A Budget did not reply with the correct state identifier. Firefly III cannot continue.');
}
/**
* @covers \FireflyIII\Http\Controllers\Import\CallbackController
*/
public function testYnabBasicNoCode(): void
{
$this->mock(ImportJobRepositoryInterface::class);
$this->mockDefaultSession();
// mock calls.
$this->be($this->user());
$response = $this->get(route('import.callback.ynab') . '?code=&state=def');
$response->assertStatus(200);
$response->assertSee('You Need A Budget did not reply with a valid authorization code. Firefly III cannot continue.');
}
}

View File

@@ -1,344 +0,0 @@
<?php
/**
* IndexControllerTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Import;
use FireflyIII\Import\Prerequisites\BunqPrerequisites;
use FireflyIII\Import\Prerequisites\FakePrerequisites;
use FireflyIII\Import\Prerequisites\SpectrePrerequisites;
use FireflyIII\Import\Prerequisites\YnabPrerequisites;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class IndexControllerTest
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class IndexControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController
*/
public function testCreateBadJob(): void
{
$this->mockDefaultSession();
// mock stuff:
$this->mock(ImportJobRepositoryInterface::class);
$userRepository = $this->mock(UserRepositoryInterface::class);
$bunqPrerequisites = $this->mock(BunqPrerequisites::class);
$spectrePrerequisites = $this->mock(SpectrePrerequisites::class);
$ynabPrerequisites = $this->mock(YnabPrerequisites::class);
// fake job:
$importJob = new ImportJob;
$importJob->provider = 'fake';
$importJob->key = 'fake_job_1';
// mock calls:
$ynabPrerequisites->shouldReceive('setUser')->once();
//$fakePrerequisites->shouldReceive('setUser')->once();
$bunqPrerequisites->shouldReceive('setUser')->once();
$spectrePrerequisites->shouldReceive('setUser')->once();
//$fakePrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
$bunqPrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
$spectrePrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
$ynabPrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->once();
$this->be($this->user());
$response = $this->get(route('import.create', ['bad']));
$response->assertStatus(404);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController
*/
public function testCreateDemoUser(): void
{
Log::debug(sprintf('Now in test %s', __METHOD__));
// mock stuff:
$this->mock(ImportJobRepositoryInterface::class);
$userRepository = $this->mock(UserRepositoryInterface::class);
$fakePrerequisites = $this->mock(FakePrerequisites::class);
// fake job:
$importJob = new ImportJob;
$importJob->provider = 'spectre';
$importJob->key = 'fake_job_1';
$this->mockDefaultSession();
// mock calls:
$fakePrerequisites->shouldReceive('setUser')->atLeast()->once();
$fakePrerequisites->shouldReceive('isComplete')->atLeast()->once()->andReturn(true);
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->atLeast()->once();
$this->be($this->user());
$response = $this->get(route('import.create', ['spectre']));
$response->assertStatus(404);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController
*/
public function testCreateFake(): void
{
// mock stuff:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$userRepository = $this->mock(UserRepositoryInterface::class);
$fakePrerequisites = $this->mock(FakePrerequisites::class);
// fake job:
$importJob = new ImportJob;
$importJob->provider = 'fake';
$importJob->key = 'fake_job_1';
$importJob->user_id = 1;
$this->mockDefaultSession();
// mock calls
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->times(3);
$repository->shouldReceive('create')->withArgs(['fake'])->andReturn($importJob);
$fakePrerequisites->shouldReceive('isComplete')->times(3)->andReturn(false);
$fakePrerequisites->shouldReceive('setUser')->times(3);
$this->be($this->user());
$response = $this->get(route('import.create', ['fake']));
$response->assertStatus(302);
// expect a redirect to prerequisites
$response->assertRedirect(route('import.prerequisites.index', ['fake', 'fake_job_1']));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController
*/
public function testCreateFakeNoPrereq(): void
{
// mock stuff:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$userRepository = $this->mock(UserRepositoryInterface::class);
$fakePrerequisites = $this->mock(FakePrerequisites::class);
// fake job:
$importJob = new ImportJob;
$importJob->provider = 'fake';
$importJob->key = 'fake_job_2';
$importJob->user_id = 1;
$this->mockDefaultSession();
// mock call:
$fakePrerequisites->shouldReceive('isComplete')->times(3)->andReturn(true);
$fakePrerequisites->shouldReceive('setUser')->times(3);
$repository->shouldReceive('create')->withArgs(['fake'])->andReturn($importJob);
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'has_prereq'])->andReturn($importJob)->once();
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->times(3);
$this->be($this->user());
$response = $this->get(route('import.create', ['fake']));
$response->assertStatus(302);
// expect a redirect to prerequisites
$response->assertRedirect(route('import.job.configuration.index', ['fake_job_2']));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController
*/
public function testCreateFileHasNoPrereq(): void
{
// mock stuff:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$userRepository = $this->mock(UserRepositoryInterface::class);
$bunqPrerequisites = $this->mock(BunqPrerequisites::class);
$spectrePrerequisites = $this->mock(SpectrePrerequisites::class);
$ynabPrerequisites = $this->mock(YnabPrerequisites::class);
// fake job:
$importJob = new ImportJob;
$importJob->provider = 'file';
$importJob->key = 'file_job_1';
$importJob->user_id = 1;
$this->mockDefaultSession();
// mock calls
//$fakePrerequisites->shouldReceive('setUser')->times(2);
$bunqPrerequisites->shouldReceive('setUser')->times(2);
$spectrePrerequisites->shouldReceive('setUser')->times(2);
$ynabPrerequisites->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(false)->times(3);
$repository->shouldReceive('create')->withArgs(['file'])->andReturn($importJob);
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'has_prereq'])->andReturn($importJob)->once();
$this->be($this->user());
$response = $this->get(route('import.create', ['file']));
$response->assertStatus(302);
// expect a redirect to prerequisites
$response->assertRedirect(route('import.job.configuration.index', ['file_job_1']));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController
*/
public function testDownload(): void
{
// mock stuff:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$userRepository = $this->mock(UserRepositoryInterface::class);
$bunqPrerequisites = $this->mock(BunqPrerequisites::class);
$spectrePrerequisites = $this->mock(SpectrePrerequisites::class);
$ynabPrerequisites = $this->mock(YnabPrerequisites::class);
$this->mockDefaultSession();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'dc_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'go-for-import';
$job->provider = 'file';
$job->file_type = '';
$job->configuration = [];
$job->save();
$fakeConfig = [
'hi' => 'there',
1 => true,
'column-mapping-config' => ['a', 'b', 'c'],
];
$repository->shouldReceive('getConfiguration')->andReturn($fakeConfig)->once();
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
//$fakePrerequisites->shouldReceive('setUser')->times(1);
$bunqPrerequisites->shouldReceive('setUser')->times(1);
$spectrePrerequisites->shouldReceive('setUser')->times(1);
$ynabPrerequisites->shouldReceive('setUser')->times(1);
//$filePrerequisites->shouldReceive('setUser')->times(1);
//$fakePrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true);
$bunqPrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true);
$spectrePrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true);
$ynabPrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true);
//$filePrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true);
$this->be($this->user());
$response = $this->get(route('import.job.download', [$job->key]));
$response->assertStatus(200);
$response->assertExactJson(['column-mapping-config' => ['a', 'b', 'c'], 'delimiter' => ',', 'hi' => 'there', 1 => true]);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController
*/
public function testIndex(): void
{
$this->be($this->user());
// fake stuff:
$userRepository = $this->mock(UserRepositoryInterface::class);
$bunqPrerequisites = $this->mock(BunqPrerequisites::class);
$spectrePrerequisites = $this->mock(SpectrePrerequisites::class);
$ynabPrerequisites = $this->mock(YnabPrerequisites::class);
$this->mock(ImportJobRepositoryInterface::class);
$this->mockDefaultSession();
// call methods:
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false);
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(false);
//$fakePrerequisites->shouldReceive('setUser')->once();
$bunqPrerequisites->shouldReceive('setUser')->once();
$spectrePrerequisites->shouldReceive('setUser')->once();
$ynabPrerequisites->shouldReceive('setUser')->once();
//$fakePrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
$bunqPrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
$spectrePrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
$ynabPrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
$response = $this->get(route('import.index'));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Import\IndexController
*/
public function testIndexDemo(): void
{
$this->be($this->user());
// fake stuff:
$fakePrerequisites = $this->mock(FakePrerequisites::class);
$userRepository = $this->mock(UserRepositoryInterface::class);
$this->mock(ImportJobRepositoryInterface::class);
$this->mockDefaultSession();
// call methods:
$fakePrerequisites->shouldReceive('setUser')->once();
$fakePrerequisites->shouldReceive('isComplete')->once()->andReturn(true);
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true);
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(false);
$response = $this->get(route('import.index'));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
}

View File

@@ -1,291 +0,0 @@
<?php
/**
* JobConfigurationControllerTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Import;
use FireflyIII\Import\JobConfiguration\FakeJobConfiguration;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\MessageBag;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class JobConfigurationControllerTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class JobConfigurationControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobConfigurationController
*/
public function testIndex(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = '1Afake_job_' . $this->randomInt();
$job->status = 'has_prereq';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
$this->mockDefaultSession();
// mock repositories and configuration handling classes:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator = $this->mock(FakeJobConfiguration::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
// mock calls:
$configurator->shouldReceive('setImportJob')->once();
$configurator->shouldReceive('configurationComplete')->once()->andReturn(false);
$configurator->shouldReceive('getNextView')->once()->andReturn('import.fake.apply-rules');
$configurator->shouldReceive('getNextData')->once()
->andReturn(['rulesOptions' => [1 => 'Y', 0 => 'N',],]);
$this->be($this->user());
$response = $this->get(route('import.job.configuration.index', [$job->key]));
$response->assertStatus(200);
// expect a redirect to prerequisites
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobConfigurationController
*/
public function testIndexBadState(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = '2Bfake_job_' . $this->randomInt();
$job->status = 'some_bad_state';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
$this->mockDefaultSession();
// mock repositories and configuration handling classes:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator = $this->mock(FakeJobConfiguration::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->be($this->user());
$response = $this->get(route('import.job.configuration.index', [$job->key]));
$response->assertStatus(302);
$response->assertRedirect(route('import.index'));
$response->assertSessionHas('error', 'To access this page, your import job cannot have status "some_bad_state".');
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobConfigurationController
*/
public function testIndexComplete(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = '3Cfake_job_' . $this->randomInt();
$job->status = 'has_prereq';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
$this->mockDefaultSession();
// mock repositories and configuration handling classes:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator = $this->mock(FakeJobConfiguration::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// mock calls:
$configurator->shouldReceive('setImportJob')->once();
$configurator->shouldReceive('configurationComplete')->once()->andReturn(true);
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run']);
$this->be($this->user());
$response = $this->get(route('import.job.configuration.index', [$job->key]));
$response->assertStatus(302);
$response->assertRedirect(route('import.job.status.index', [$job->key]));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobConfigurationController
*/
public function testPost(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = '4Dfake_job_' . $this->randomInt();
$job->status = 'has_prereq';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
$this->mockDefaultSession();
$messages = new MessageBag;
$messages->add('some', 'srrange message');
// mock repositories and configuration handling classes:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator = $this->mock(FakeJobConfiguration::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// mock calls:
$configurator->shouldReceive('setImportJob')->once();
$configurator->shouldReceive('configurationComplete')->once()->andReturn(false);
$configurator->shouldReceive('configureJob')->withArgs([[]])->once()->andReturn($messages);
// call thing.
$this->be($this->user());
$response = $this->post(route('import.job.configuration.post', [$job->key]));
$response->assertStatus(302);
$response->assertRedirect(route('import.job.configuration.index', [$job->key]));
$response->assertSessionHas('warning', $messages->first());
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobConfigurationController
*/
public function testPostBadState(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = '5Ffake_job_' . $this->randomInt();
$job->status = 'some_bad_state';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
$this->mockDefaultSession();
$messages = new MessageBag;
$messages->add('some', 'srrange message');
// mock repositories and configuration handling classes:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator = $this->mock(FakeJobConfiguration::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// call thing.
$this->be($this->user());
$response = $this->post(route('import.job.configuration.post', [$job->key]));
$response->assertStatus(302);
$response->assertRedirect(route('import.index'));
$response->assertSessionHas('error', 'To access this page, your import job cannot have status "some_bad_state".');
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobConfigurationController
*/
public function testPostComplete(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = '6Efake_job_' . $this->randomInt();
$job->status = 'has_prereq';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
$this->mockDefaultSession();
// mock repositories and configuration handling classes:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator = $this->mock(FakeJobConfiguration::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// mock calls:
$configurator->shouldReceive('setImportJob')->once();
$configurator->shouldReceive('configurationComplete')->once()->andReturn(true);
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run']);
// call thing.
$this->be($this->user());
$response = $this->post(route('import.job.configuration.post', [$job->key]));
$response->assertStatus(302);
$response->assertRedirect(route('import.job.status.index', [$job->key]));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobConfigurationController
*/
public function testPostWithUpload(): void
{
$file = UploadedFile::fake()->image('avatar.jpg');
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = '7Dfake_job_' . $this->randomInt();
$job->status = 'has_prereq';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
$this->mockDefaultSession();
$messages = new MessageBag;
$messages->add('some', 'srrange message');
// mock repositories and configuration handling classes:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator = $this->mock(FakeJobConfiguration::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// mock calls:
$configurator->shouldReceive('setImportJob')->once();
$configurator->shouldReceive('configurationComplete')->once()->andReturn(false);
$configurator->shouldReceive('configureJob')->once()->andReturn($messages);
$repository->shouldReceive('storeFileUpload')->once()->andReturn(new MessageBag);
// call thing.
$this->be($this->user());
$response = $this->post(route('import.job.configuration.post', [$job->key]), ['import_file' => $file]);
$response->assertStatus(302);
$response->assertRedirect(route('import.job.configuration.index', [$job->key]));
$response->assertSessionHas('warning', $messages->first());
}
}

View File

@@ -1,440 +0,0 @@
<?php
/**
* JobStatusControllerTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Import;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Routine\FakeRoutine;
use FireflyIII\Import\Storage\ImportArrayStorage;
use FireflyIII\Models\ImportJob;
use FireflyIII\Models\Tag;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class JobStatusControllerTest
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class JobStatusControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobStatusController
*/
public function testIndex(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'Afake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
$this->mockDefaultSession();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
// call thing.
$this->be($this->user());
$response = $this->get(route('import.job.status.index', [$job->key]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobStatusController
*/
public function testJson(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'Bfake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'file';
$job->transactions = [];
$job->file_type = '';
$job->save();
$this->mockDefaultSession();
$importRepos->shouldReceive('countTransactions')->once()->andReturn(0);
// call thing.
$this->be($this->user());
$response = $this->get(route('import.job.status.json', [$job->key]));
$response->assertStatus(200);
$response->assertSee(
'No transactions have been imported. Perhaps they were all duplicates is simply no transactions where present to be imported. Perhaps the log files can tell you what happened. If you import data regularly, this is normal.'
);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobStatusController
*/
public function testJsonWithTag(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$tag = $this->getRandomTag();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'Cfake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->tag()->associate($tag);
$job->save();
$this->mockDefaultSession();
$importRepos->shouldReceive('countTransactions')->once()->andReturn(0);
$importRepos->shouldReceive('countByTag')->atLeast()->once()->andReturn(0);
// call thing.
$this->be($this->user());
$response = $this->get(route('import.job.status.json', [$job->key]));
$response->assertStatus(200);
$response->assertSee(
'No transactions have been imported. Perhaps they were all duplicates is simply no transactions where present to be imported. Perhaps the log files can tell you what happened. If you import data regularly, this is normal.'
);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobStatusController
*/
public function testJsonWithTagManyJournals(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
/** @var Tag $tag */
$tag = $this->user()->tags()->first();
$journal = $this->user()->transactionJournals()->first();
$second = $this->user()->transactionJournals()->where('id', '!=', $journal->id)->first();
$tag->transactionJournals()->sync([$journal->id, $second->id]);
$this->mockDefaultSession();
$importRepos->shouldReceive('countTransactions')->once()->andReturn(2);
$importRepos->shouldReceive('countByTag')->atLeast()->once()->andReturn(2);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'Dfake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->tag()->associate($tag);
$job->save();
// call thing.
$this->be($this->user());
$response = $this->get(route('import.job.status.json', [$job->key]));
$response->assertStatus(200);
$response->assertSee(
'Firefly III has imported 2 transactions. They are stored under tag <a href=\"http:\/\/localhost\/tags\/show\/' . $tag->id
);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobStatusController
*/
public function testJsonWithTagOneJournal(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
/** @var Tag $tag */
$tag = $this->user()->tags()->first();
$journal = $this->user()->transactionJournals()->first();
$tag->transactionJournals()->sync([$journal->id]);
$this->mockDefaultSession();
$importRepos->shouldReceive('countTransactions')->once()->andReturn(1);
$importRepos->shouldReceive('countByTag')->atLeast()->once()->andReturn(1);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'Efake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->tag()->associate($tag);
$job->save();
// call thing.
$this->be($this->user());
$response = $this->get(route('import.job.status.json', [$job->key]));
$response->assertStatus(200);
$response->assertSee(
'Exactly one transaction has been imported. It is stored under tag <a href=\"http:\/\/localhost\/tags\/show\/' . $tag->id
);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobStatusController
*/
public function testStart(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'Ffake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
$this->mockDefaultSession();
// mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class);
$routine = $this->mock(FakeRoutine::class);
// mock calls:
$routine->shouldReceive('setImportJob')->once();
$routine->shouldReceive('run')->once();
// call thing.
$this->be($this->user());
$response = $this->post(route('import.job.start', [$job->key]));
$response->assertStatus(200);
$response->assertExactJson(['status' => 'OK', 'message' => 'stage_finished']);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobStatusController
*/
public function testStartException(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'Gfake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
$this->mockDefaultSession();
// mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class);
$routine = $this->mock(FakeRoutine::class);
// mock calls:
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'error']);
$routine->shouldReceive('setImportJob')->once();
$routine->shouldReceive('run')->andThrow(new Exception('Unknown exception'));
// call thing.
Log::warning('The following error is part of a test.');
$this->be($this->user());
$response = $this->post(route('import.job.start', [$job->key]));
$response->assertStatus(200);
$response->assertExactJson(['status' => 'NOK', 'message' => 'The import routine crashed: Unknown exception']);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobStatusController
*/
public function testStartFireflyException(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'Hfake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
$this->mockDefaultSession();
// mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class);
$routine = $this->mock(FakeRoutine::class);
// mock calls:
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'error']);
$routine->shouldReceive('setImportJob')->once();
$routine->shouldReceive('run')->andThrow(new FireflyException('Unknown exception'));
// call thing.
Log::warning('The following error is part of a test.');
$this->be($this->user());
$response = $this->post(route('import.job.start', [$job->key]));
$response->assertStatus(200);
$response->assertExactJson(['status' => 'NOK', 'message' => 'The import routine crashed: Unknown exception']);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobStatusController
*/
public function testStartInvalidState(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// mock calls:
$importRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'error'])
->atLeast()->once();
$this->mockDefaultSession();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'Ifake_job_' . $this->randomInt();
$job->status = 'bad_state';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
// call thing.
$this->be($this->user());
$response = $this->post(route('import.job.start', [$job->key]));
$response->assertStatus(200);
$response->assertExactJson(['status' => 'NOK', 'message' => 'JobStatusController::start expects status "ready_to_run" instead of "bad_state".']);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobStatusController
*/
public function testStore(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'Jfake_job_' . $this->randomInt();
$job->status = 'provider_finished';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
$this->mockDefaultSession();
// mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class);
$storage = $this->mock(ImportArrayStorage::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// mock calls:
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'storing_data']);
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'storage_finished']);
$storage->shouldReceive('setImportJob')->once();
$storage->shouldReceive('store')->once();
$this->be($this->user());
$response = $this->post(route('import.job.store', [$job->key]));
$response->assertStatus(200);
$response->assertExactJson(['status' => 'OK', 'message' => 'storage_finished']);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobStatusController
*/
public function testStoreException(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'Lfake_job_' . $this->randomInt();
$job->status = 'provider_finished';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
$this->mockDefaultSession();
// mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class);
$storage = $this->mock(ImportArrayStorage::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// mock calls:
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'storing_data']);
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'error']);
$storage->shouldReceive('setImportJob')->once();
$storage->shouldReceive('store')->once()->andThrow(new FireflyException('Some storage exception.'));
$this->be($this->user());
$response = $this->post(route('import.job.store', [$job->key]));
$response->assertStatus(200);
$response->assertExactJson(['status' => 'NOK', 'message' => 'The import storage routine crashed: Some storage exception.']);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\JobStatusController
*/
public function testStoreInvalidState(): void
{
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'Kfake_job_' . $this->randomInt();
$job->status = 'some_bad_state';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
$this->mockDefaultSession();
$this->be($this->user());
$response = $this->post(route('import.job.store', [$job->key]));
$response->assertStatus(200);
$response->assertExactJson(
['status' => 'NOK', 'message' => 'JobStatusController::start expects status "provider_finished" instead of "' . $job->status . '".']
);
}
}

View File

@@ -1,371 +0,0 @@
<?php
/**
* PrerequisitesControllerTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Import;
use FireflyIII\Import\Prerequisites\BunqPrerequisites;
use FireflyIII\Import\Prerequisites\FakePrerequisites;
use FireflyIII\Import\Prerequisites\SpectrePrerequisites;
use FireflyIII\Import\Prerequisites\YnabPrerequisites;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\MessageBag;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
/**
* Class AccountControllerTest
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class PrerequisitesControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController
*/
public function testIndex(): void
{
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$prereq = $this->mock(BunqPrerequisites::class);
$this->mock(ImportJobRepositoryInterface::class);
// mock some prerequisites:
$spectrePrereq = $this->mock(SpectrePrerequisites::class);
$ynabPrereq = $this->mock(YnabPrerequisites::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'A_pre_job_' . $this->randomInt();
$job->status = 'new';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
$prereq->shouldReceive('setUser')->atLeast()->once();
$spectrePrereq->shouldReceive('setUser')->atLeast()->once();
$ynabPrereq->shouldReceive('setUser')->atLeast()->once();
$prereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
$spectrePrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
$ynabPrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
$prereq->shouldReceive('getView')->once()->andReturn('import.fake.prerequisites');
$prereq->shouldReceive('getViewParameters')->once()->andReturn(['api_key' => '']);
$this->be($this->user());
$response = $this->get(route('import.prerequisites.index', ['bunq', $job->key]));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController
*/
public function testIndexBadState(): void
{
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(ImportJobRepositoryInterface::class);
// mock some prerequisites:
$bunqPrereq = $this->mock(BunqPrerequisites::class);
$spectrePrereq = $this->mock(SpectrePrerequisites::class);
$ynabPrereq = $this->mock(YnabPrerequisites::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'B_pre_job_' . $this->randomInt();
$job->status = 'some_Bad_state';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
// fake calls to prereq classes
$bunqPrereq->shouldReceive('setUser')->atLeast()->once();
$spectrePrereq->shouldReceive('setUser')->atLeast()->once();
$ynabPrereq->shouldReceive('setUser')->atLeast()->once();
$bunqPrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
$spectrePrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
$ynabPrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
$this->be($this->user());
$response = $this->get(route('import.prerequisites.index', ['bunq', $job->key]));
$response->assertStatus(302);
$response->assertRedirect(route('import.index'));
}
/**
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController
*/
public function testIndexComplete(): void
{
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock some prerequisites:
$bunqPrereq = $this->mock(BunqPrerequisites::class);
$spectrePrereq = $this->mock(SpectrePrerequisites::class);
$ynabPrereq = $this->mock(YnabPrerequisites::class);
// fake calls to prereq classes
$bunqPrereq->shouldReceive('setUser')->atLeast()->once();
$spectrePrereq->shouldReceive('setUser')->atLeast()->once();
$ynabPrereq->shouldReceive('setUser')->atLeast()->once();
$bunqPrereq->shouldReceive('isComplete')->andReturn(true)->atLeast()->once();
$spectrePrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
$ynabPrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once();
//Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(),'x','x'])->atLeast()->once();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'C_pre_job_' . $this->randomInt();
$job->status = 'new';
$job->provider = 'bunq';
$job->transactions = [];
$job->file_type = '';
$job->save();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'has_prereq']);
$this->be($this->user());
$response = $this->get(route('import.prerequisites.index', ['bunq', $job->key]));
$response->assertStatus(302);
$response->assertRedirect(route('import.job.configuration.index', [$job->key]));
}
/**
* Redirects to configuration.
*
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController
*/
public function testPost(): void
{
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock some prerequisites:
$bunqPrereq = $this->mock(BunqPrerequisites::class);
$spectrePrereq = $this->mock(SpectrePrerequisites::class);
$ynabPrereq = $this->mock(YnabPrerequisites::class);
// fake calls to prereq classes
$bunqPrereq->shouldReceive('setUser')->atLeast()->once();
$spectrePrereq->shouldReceive('setUser')->atLeast()->once();
$ynabPrereq->shouldReceive('setUser')->atLeast()->once();
$bunqPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
$spectrePrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
$ynabPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
$bunqPrereq->shouldReceive('storePrerequisites')->atLeast()->once()->andReturn(new MessageBag);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'D_pre_job_' . $this->randomInt();
$job->status = 'new';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
//$prereq->shouldReceive('setUser')->times(2);
//$prereq->shouldReceive('storePrerequisites')->once()->andReturn(new MessageBag);
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'has_prereq']);
$this->be($this->user());
$response = $this->post(route('import.prerequisites.post', ['bunq', $job->key]));
$response->assertStatus(302);
$response->assertRedirect(route('import.job.configuration.index', [$job->key]));
}
/**
* Bad state gives errors.
*
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController
*/
public function testPostBadState(): void
{
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$prereq = $this->mock(FakePrerequisites::class);
$this->mock(ImportJobRepositoryInterface::class);
// mock some prerequisites:
$bunqPrereq = $this->mock(BunqPrerequisites::class);
$spectrePrereq = $this->mock(SpectrePrerequisites::class);
$ynabPrereq = $this->mock(YnabPrerequisites::class);
// fake calls to prereq classes
$bunqPrereq->shouldReceive('setUser')->atLeast()->once();
$spectrePrereq->shouldReceive('setUser')->atLeast()->once();
$ynabPrereq->shouldReceive('setUser')->atLeast()->once();
$bunqPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
$spectrePrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
$ynabPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
//Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturnNull();
//Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'spectre_app_id', null])->andReturnNull();
//Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturnNull();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'D_pre_job_' . $this->randomInt();
$job->status = 'badstate';
$job->provider = 'bunq';
$job->transactions = [];
$job->file_type = '';
$job->save();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
$this->be($this->user());
$response = $this->post(route('import.prerequisites.post', ['bunq', $job->key]));
$response->assertStatus(302);
$response->assertRedirect(route('import.index'));
$response->assertSessionHas('error', 'To access this page, your import job cannot have status "badstate".');
}
/**
* Redirects to index.
*
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController
*/
public function testPostNoJob(): void
{
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(ImportJobRepositoryInterface::class);
// mock some prerequisites:
$bunqPrereq = $this->mock(BunqPrerequisites::class);
$spectrePrereq = $this->mock(SpectrePrerequisites::class);
$ynabPrereq = $this->mock(YnabPrerequisites::class);
// fake calls to prereq classes
$bunqPrereq->shouldReceive('setUser')->atLeast()->once();
$spectrePrereq->shouldReceive('setUser')->atLeast()->once();
$ynabPrereq->shouldReceive('setUser')->atLeast()->once();
$bunqPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
$spectrePrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
$ynabPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
$bunqPrereq->shouldReceive('storePrerequisites')->atLeast()->once()->andReturn(new MessageBag);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
$this->be($this->user());
$response = $this->post(route('import.prerequisites.post', ['bunq']));
$response->assertStatus(302);
$response->assertRedirect(route('import.index'));
}
/**
* Error messages? Redirect back
*
* @covers \FireflyIII\Http\Controllers\Import\PrerequisitesController
*/
public function testPostWithMessages(): void
{
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$prereq = $this->mock(FakePrerequisites::class);
$this->mock(ImportJobRepositoryInterface::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'D_pre_job_' . $this->randomInt();
$job->status = 'new';
$job->provider = 'bunq';
$job->transactions = [];
$job->file_type = '';
$job->save();
$messages = new MessageBag;
$messages->add('some', 'message');
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
// mock some prerequisites:
$bunqPrereq = $this->mock(BunqPrerequisites::class);
$spectrePrereq = $this->mock(SpectrePrerequisites::class);
$ynabPrereq = $this->mock(YnabPrerequisites::class);
// fake calls to prereq classes
$bunqPrereq->shouldReceive('setUser')->atLeast()->once();
$spectrePrereq->shouldReceive('setUser')->atLeast()->once();
$ynabPrereq->shouldReceive('setUser')->atLeast()->once();
$bunqPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
$spectrePrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
$ynabPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false);
$bunqPrereq->shouldReceive('storePrerequisites')->atLeast()->once()->andReturn($messages);
$this->be($this->user());
$response = $this->post(route('import.prerequisites.post', ['bunq', $job->key]));
$response->assertStatus(302);
$response->assertRedirect(route('import.prerequisites.index', ['bunq', $job->key]));
$response->assertSessionHas('error', 'message');
}
}