From a8c4c05c4d51269d7a2076c62e1552608d07eb6f Mon Sep 17 00:00:00 2001 From: fokosun Date: Wed, 23 Aug 2023 16:43:20 -0400 Subject: [PATCH] improve test coverage --- app/Http/Middleware/AuthorizationGuard.php | 51 ------------------- app/Http/Middleware/MustVerifyEmail.php | 30 ----------- .../Unit/Controllers/SearchControllerTest.php | 21 ++++++++ 3 files changed, 21 insertions(+), 81 deletions(-) delete mode 100755 app/Http/Middleware/AuthorizationGuard.php delete mode 100755 app/Http/Middleware/MustVerifyEmail.php diff --git a/app/Http/Middleware/AuthorizationGuard.php b/app/Http/Middleware/AuthorizationGuard.php deleted file mode 100755 index 9af45a6f..00000000 --- a/app/Http/Middleware/AuthorizationGuard.php +++ /dev/null @@ -1,51 +0,0 @@ -header('X-API-KEY')) { - // throw new UnauthorizedClientException(); - // } -// - // $client = AuthorizedClient::where(['api_key' => $request->header('X-API-KEY')]); -// - // if (!$client->get()->first()) { - // throw new UnauthorizedClientException(); - // } - - // try { - // $decrypted = Crypt::decrypt($client->get()->first()->client_secret); - // $payload = explode(".", $decrypted); -// - // if ($payload[0] !== $request->header('X-API-KEY') || $payload[1] !== $client->get()->first()->passphrase) { - // throw new UnauthorizedClientException(); - // } - // } catch (DecryptException $e) { - // throw new UnauthorizedClientException(); - // } - - // $token = JWTAuth::getToken(); -// - // $user_id = JWTAuth::getPayload($token)->toArray()["sub"]; -// - // $request->merge(["user_id" => $user_id]); - - return $next($request); - } -} diff --git a/app/Http/Middleware/MustVerifyEmail.php b/app/Http/Middleware/MustVerifyEmail.php deleted file mode 100755 index 1482c2a0..00000000 --- a/app/Http/Middleware/MustVerifyEmail.php +++ /dev/null @@ -1,30 +0,0 @@ -user()->hasVerifiedEmail()) { - return response([ - 'error' => 'You have not verified your email yet.', - ], Response::HTTP_UNAUTHORIZED); - } - - return $next($request); - } -} diff --git a/tests/Unit/Controllers/SearchControllerTest.php b/tests/Unit/Controllers/SearchControllerTest.php index bc7aacab..5156570c 100755 --- a/tests/Unit/Controllers/SearchControllerTest.php +++ b/tests/Unit/Controllers/SearchControllerTest.php @@ -13,6 +13,27 @@ class SearchControllerTest extends \TestCase { + /** + * @test + */ + public function it_validates_search_request_body() + { + $searchController = new SearchController(); + + $response = $searchController->getSearchResults(new SearchRequest([ + 'query' => null + ])); + + $decoded = json_decode($response->getContent(), true); + $this->assertSame([ + 'errors' => [ + 'query' => [ + 'The query field is required.' + ] + ] + ], $decoded); + } + public function test_it_is_instantiable() { $searchController = new SearchController();