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

@@ -76,29 +76,29 @@ class IndexController extends Controller
*/
public function create(string $importProvider)
{
Log::debug(sprintf('Will create job for provider "%s"', $importProvider));
$importJob = $this->repository->create($importProvider);
$hasPreReq = (bool)config(sprintf('import.has_prereq.%s', $importProvider));
$hasConfig = (bool)config(sprintf('import.has_job_config.%s', $importProvider));
$allowedForDemo = (bool)config(sprintf('import.allowed_for_demo.%s', $importProvider));
$isDemoUser = $this->userRepository->hasRole(auth()->user(), 'demo');
Log::debug(sprintf('Will create job for provider "%s"', $importProvider));
Log::debug(sprintf('Is demo user? %s',var_export($isDemoUser, true)));
Log::debug(sprintf('Is allowed for user? %s',var_export($allowedForDemo, true)));
Log::debug(sprintf('Has prerequisites? %s',var_export($hasPreReq, true)));
Log::debug(sprintf('Has config? %s',var_export($hasConfig, true)));
if ($isDemoUser && !$allowedForDemo) {
Log::debug('User is demo and this provider doesnt work for demo users.');
return redirect(route('import.index'));
}
$importJob = $this->repository->create($importProvider);
Log::debug(sprintf('Created job #%d for provider %s', $importJob->id, $importProvider));
// no prerequisites and no config:
if (false === $hasPreReq && false === $hasConfig) {
Log::debug('Provider needs no configuration for job. Job is ready to start.');
$this->repository->updateStatus($importJob, 'ready_to_run');
Log::debug('Redirect to status-page.');
return redirect(route('import.job.status.index', [$importJob->key]));
}
// no prerequisites but job has config:
if (false === $hasPreReq && false !== $hasConfig) {
Log::debug('Provider has no prerequisites. Continue.');
@@ -130,7 +130,7 @@ class IndexController extends Controller
if (false === $hasConfig) {
// @codeCoverageIgnoreStart
Log::debug('Provider has no configuration. Job is ready to start.');
$this->repository->updateStatus($importJob, 'ready_to_run');
$this->repository->setStatus($importJob, 'ready_to_run');
Log::debug('Redirect to status-page.');
return redirect(route('import.job.status.index', [$importJob->key]));