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!', ]); }