From f05b540265aaf16b60c5d034cea4b3d245b76784 Mon Sep 17 00:00:00 2001 From: Furkan Sahin Date: Fri, 28 Jul 2023 15:43:24 +0300 Subject: [PATCH] update endpoint --- app/Http/Controllers/ApiController.php | 9 +++++---- tests/Feature/ApiAuthenticationTest.php | 12 +++--------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/ApiController.php b/app/Http/Controllers/ApiController.php index 88ff036..30b27eb 100644 --- a/app/Http/Controllers/ApiController.php +++ b/app/Http/Controllers/ApiController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Models\User; +use Illuminate\Http\JsonResponse; class ApiController extends Controller { @@ -27,14 +28,14 @@ public function authenticate(): \Illuminate\Http\JsonResponse if ($attempt) { auth()->login($attempt); - - return response()->json(['status' => true, 'message' => 'Authenticated']); + return new JsonResponse(['message' => 'Authenticated']); } - return response()->json(['status' => false, 'message' => 'Invalid credentials']); + + return new JsonResponse(['message' => 'Unauthenticated'], 401); } public function users(): \Illuminate\Http\JsonResponse { - return response()->json(['status' => true, 'message' => 'Authenticated', 'data' => User::all()]); + return new JsonResponse(['message' => 'Authenticated', 'data' => User::all()]); } } diff --git a/tests/Feature/ApiAuthenticationTest.php b/tests/Feature/ApiAuthenticationTest.php index 0160810..8ca031d 100644 --- a/tests/Feature/ApiAuthenticationTest.php +++ b/tests/Feature/ApiAuthenticationTest.php @@ -31,10 +31,8 @@ public function test_auth(): void $response = $this->postJson('/api/authenticate', ['api_key' => $this->apiKey, 'secret_key' => $this->secretKey]); $response - ->assertSuccessful() - ->assertJson([ - 'status' => true, - ]); + ->assertSuccessful(); + } @@ -43,10 +41,7 @@ public function test_users(): void $response = $this->postJson('/api/app/users', data: [], headers: ['api_key' => $this->apiKey, 'secret_key' => $this->secretKey]); $response - ->assertSuccessful() - ->assertJson([ - 'status' => true, - ]); + ->assertSuccessful(); } @@ -84,7 +79,6 @@ public function test_error_handling(): void $response ->assertStatus(401) ->assertJson([ - 'status' => false, 'message' => 'APIKEY and SECRETKEY required!', ]); }