From 632d50a0d0bdfb574489aed598413ab19471f136 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 17 Feb 2018 14:14:26 +0100 Subject: [PATCH] Fix all tests. --- app/Exceptions/Handler.php | 9 ++++++++- tests/Feature/Controllers/PiggyBankControllerTest.php | 1 + tests/Unit/Middleware/AuthenticateTest.php | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 79bd4dceab..ba0f1a30d3 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -25,10 +25,12 @@ namespace FireflyIII\Exceptions; use ErrorException; use Exception; use FireflyIII\Jobs\MailError; +use Illuminate\Auth\AuthenticationException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Illuminate\Validation\ValidationException; use Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Illuminate\Validation\ValidationException; + /** * Class Handler */ @@ -70,6 +72,11 @@ class Handler extends ExceptionHandler if ($exception instanceof NotFoundHttpException && $request->expectsJson()) { return response()->json(['message' => 'Resource not found', 'exception' => 'NotFoundHttpException'], 404); } + + if ($exception instanceof AuthenticationException && $request->expectsJson()) { + return response()->json(['message' => 'Unauthenticated', 'exception' => 'AuthenticationException'], 401); + } + if ($request->expectsJson()) { $isDebug = env('APP_DEBUG', false); if ($isDebug) { diff --git a/tests/Feature/Controllers/PiggyBankControllerTest.php b/tests/Feature/Controllers/PiggyBankControllerTest.php index 3377d69413..da636a3e9c 100644 --- a/tests/Feature/Controllers/PiggyBankControllerTest.php +++ b/tests/Feature/Controllers/PiggyBankControllerTest.php @@ -177,6 +177,7 @@ class PiggyBankControllerTest extends TestCase $two->account_id = $one->account_id; $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $repository->shouldReceive('getPiggyBanks')->andReturn(new Collection([$one, $two])); + $repository->shouldReceive('getCurrentAmount')->andReturn('10'); Steam::shouldReceive('balanceIgnoreVirtual')->twice()->andReturn('1'); diff --git a/tests/Unit/Middleware/AuthenticateTest.php b/tests/Unit/Middleware/AuthenticateTest.php index b50017132b..ee4b45738f 100644 --- a/tests/Unit/Middleware/AuthenticateTest.php +++ b/tests/Unit/Middleware/AuthenticateTest.php @@ -47,6 +47,7 @@ class AuthenticateTest extends TestCase */ public function testMiddlewareAjax() { + //$this->withoutExceptionHandling(); $server = ['HTTP_X-Requested-With' => 'XMLHttpRequest']; $response = $this->get('/_test/authenticate', $server); $this->assertEquals(Response::HTTP_UNAUTHORIZED, $response->getStatusCode());