mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-19 19:01:39 +00:00
First step in improving test coverage.
This commit is contained in:
@@ -36,6 +36,7 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class AmountController
|
||||
@@ -160,6 +161,8 @@ class AmountController extends Controller
|
||||
$average = $this->repository->getAverageAvailable($start, $end);
|
||||
$available = bcmul($average, (string)$daysInPeriod);
|
||||
|
||||
Log::debug(sprintf('Average is %s, so total available is %s because days is %d.', $average, $available, $daysInPeriod));
|
||||
|
||||
// amount earned in this period:
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
@@ -169,6 +172,8 @@ class AmountController extends Controller
|
||||
// This is multiplied by the number of days in the current period, showing you the average.
|
||||
$earnedAverage = bcmul(bcdiv($earned, (string)$daysInSearchPeriod), (string)$daysInPeriod);
|
||||
|
||||
Log::debug(sprintf('Earned is %s, earned average is %s', $earned, $earnedAverage));
|
||||
|
||||
// amount spent in period
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
@@ -176,11 +181,16 @@ class AmountController extends Controller
|
||||
$spent = (string)$collector->getTransactions()->sum('transaction_amount');
|
||||
$spentAverage = app('steam')->positive(bcmul(bcdiv($spent, (string)$daysInSearchPeriod), (string)$daysInPeriod));
|
||||
|
||||
Log::debug(sprintf('Spent is %s, spent average is %s', $earned, $earnedAverage));
|
||||
|
||||
// the default suggestion is the money the user has spent, on average, over this period.
|
||||
$suggested = $spentAverage;
|
||||
|
||||
Log::debug(sprintf('Suggested is now %s (spent average)',$suggested));
|
||||
|
||||
// if the user makes less per period, suggest that amount instead.
|
||||
if (1 === bccomp($spentAverage, $earnedAverage)) {
|
||||
Log::debug(sprintf('Because earned average (%s) is less than spent average (%s) will suggest earned average instead.', $earnedAverage, $spentAverage));
|
||||
$suggested = $earnedAverage;
|
||||
}
|
||||
|
||||
|
@@ -48,10 +48,13 @@ class CallbackController extends Controller
|
||||
{
|
||||
$code = (string)$request->get('code');
|
||||
$jobKey = (string)$request->get('state');
|
||||
$importJob = $repository->findByKey($jobKey);
|
||||
|
||||
if ('' === $code) {
|
||||
return view('error')->with('message', 'You Need A Budget did not reply with a valid authorization code. Firefly III cannot continue.');
|
||||
}
|
||||
|
||||
$importJob = $repository->findByKey($jobKey);
|
||||
|
||||
if ('' === $jobKey || null === $importJob) {
|
||||
return view('error')->with('message', 'You Need A Budget did not reply with the correct state identifier. Firefly III cannot continue.');
|
||||
}
|
||||
|
@@ -49,10 +49,12 @@ class JsonController extends Controller
|
||||
}
|
||||
try {
|
||||
$view = view('rules.partials.action', compact('actions', 'count'))->render();
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Cannot render rules.partials.action: %s', $e->getMessage()));
|
||||
$view = 'Could not render view.';
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return response()->json(['html' => $view]);
|
||||
}
|
||||
@@ -78,10 +80,12 @@ class JsonController extends Controller
|
||||
|
||||
try {
|
||||
$view = view('rules.partials.trigger', compact('triggers', 'count'))->render();
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Cannot render rules.partials.trigger: %s', $e->getMessage()));
|
||||
$view = 'Could not render view.';
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return response()->json(['html' => $view]);
|
||||
}
|
||||
|
@@ -190,17 +190,10 @@ class ProfileController extends Controller
|
||||
/**
|
||||
* Enable 2FA screen.
|
||||
*
|
||||
* @param UserRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function enable2FA(UserRepositoryInterface $repository)
|
||||
public function enable2FA()
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
if ($repository->hasRole($user, 'demo')) {
|
||||
return redirect(route('profile.index'));
|
||||
}
|
||||
$hasSecret = (null !== app('preferences')->get('twoFactorAuthSecret'));
|
||||
|
||||
// if we don't have a valid secret yet, redirect to the code page to get one.
|
||||
|
@@ -102,10 +102,12 @@ class SearchController extends Controller
|
||||
}
|
||||
try {
|
||||
$html = view('search.search', compact('transactions'))->render();
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Cannot render search.search: %s', $e->getMessage()));
|
||||
$html = 'Could not render view.';
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return response()->json(['count' => $transactions->count(), 'html' => $html]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user