Skip to content

Commit

Permalink
update endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
swoorr committed Jul 28, 2023
1 parent 6665c3a commit f05b540
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
9 changes: 5 additions & 4 deletions app/Http/Controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\JsonResponse;

class ApiController extends Controller
{
Expand All @@ -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()]);
}
}
12 changes: 3 additions & 9 deletions tests/Feature/ApiAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}


Expand All @@ -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();

}

Expand Down Expand Up @@ -84,7 +79,6 @@ public function test_error_handling(): void
$response
->assertStatus(401)
->assertJson([
'status' => false,
'message' => 'APIKEY and SECRETKEY required!',
]);
}
Expand Down

0 comments on commit f05b540

Please sign in to comment.