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]));

View File

@@ -88,7 +88,7 @@ class JobConfigurationController extends Controller
if (!(bool)config(sprintf('import.has_job_config.%s', $importProvider))) {
// @codeCoverageIgnoreStart
Log::debug('Job needs no config, is ready to run!');
$this->repository->updateStatus($importJob, 'ready_to_run');
$this->repository->setStatus($importJob, 'ready_to_run');
return redirect(route('import.job.status.index', [$importJob->key]));
// @codeCoverageIgnoreEnd
@@ -97,7 +97,7 @@ class JobConfigurationController extends Controller
$configurator = $this->makeConfigurator($importJob);
if ($configurator->configurationComplete()) {
Log::debug('Config is complete, set status to ready_to_run.');
$this->repository->updateStatus($importJob, 'ready_to_run');
$this->repository->setStatus($importJob, 'ready_to_run');
return redirect(route('import.job.status.index', [$importJob->key]));
}
@@ -137,7 +137,7 @@ class JobConfigurationController extends Controller
// is the job already configured?
if ($configurator->configurationComplete()) {
$this->repository->updateStatus($importJob, 'ready_to_run');
$this->repository->setStatus($importJob, 'ready_to_run');
return redirect(route('import.job.status.index', [$importJob->key]));
}

View File

@@ -291,32 +291,4 @@ class BoxController extends Controller
return response()->json($return);
}
/**
* Get a currency or return default currency.
*
* @param Account $account
*
* @return TransactionCurrency
*/
protected function getCurrencyOrDefault(Account $account): TransactionCurrency // get a preference
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
/** @var CurrencyRepositoryInterface $currencyRepos */
$currencyRepos = app(CurrencyRepositoryInterface::class);
$currency = app('amount')->getDefaultCurrency();
$accountCurrency = null;
$currencyId = (int)$repository->getMetaValue($account, 'currency_id');
if (0 !== $currencyId) {
$accountCurrency = $currencyRepos->findNull($currencyId);
}
if (null === $accountCurrency) {
$accountCurrency = $currency;
}
return $accountCurrency;
}
}

View File

@@ -67,10 +67,12 @@ class FrontpageController extends Controller
if (\count($info) > 0) {
try {
$html = view('json.piggy-banks', compact('info'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::error(sprintf('Cannot render json.piggy-banks: %s', $e->getMessage()));
$html = 'Could not render view.';
}
// @codeCoverageIgnoreEnd
}
return response()->json(['html' => $html]);

View File

@@ -119,7 +119,7 @@ class ReconcileController extends Controller
/** @var Transaction $transaction */
foreach ($cleared as $transaction) {
if ($transaction->transactionJournal->date <= $end) {
$clearedAmount = bcadd($clearedAmount, $transaction->amount);
$clearedAmount = bcadd($clearedAmount, $transaction->amount); // @codeCoverageIgnore
++$countCleared;
}
}
@@ -134,10 +134,12 @@ class ReconcileController extends Controller
'route', 'countCleared'
)
)->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::debug(sprintf('View error: %s', $e->getMessage()));
$view = 'Could not render accounts.reconcile.overview';
}
// @codeCoverageIgnoreEnd
$return = [
@@ -194,10 +196,12 @@ class ReconcileController extends Controller
$html = view(
'accounts.reconcile.transactions', compact('account', 'transactions', 'currency', 'start', 'end', 'selectionStart', 'selectionEnd')
)->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::debug(sprintf('Could not render: %s', $e->getMessage()));
$html = 'Could not render accounts.reconcile.transactions';
}
// @codeCoverageIgnoreEnd
return response()->json(['html' => $html, 'startBalance' => $startBalance, 'endBalance' => $endBalance]);
}

View File

@@ -103,10 +103,8 @@ class RecurrenceController extends Controller
$repetition->repetition_skip = (int)$request->get('skip');
$repetition->weekend = (int)$request->get('weekend');
$actualEnd = clone $end;
$occurrences = [];
switch ($endsAt) {
default:
throw new FireflyException(sprintf('Cannot generate events for type that ends at "%s".', $endsAt));
case 'forever':
// simply generate up until $end. No change from default behavior.
$occurrences = $this->recurring->getOccurrencesInRange($repetition, $actualStart, $actualEnd);