fix: add X-Api-Key header to API feature tests and register auth routes
This commit is contained in:
@@ -1,13 +1,25 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\Api\AuthController;
|
||||
use App\Http\Controllers\Api\PredictionController;
|
||||
use App\Http\Controllers\Api\StationController;
|
||||
use App\Http\Controllers\Api\StatsController;
|
||||
use App\Http\Middleware\VerifyApiKey;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
// Public endpoints (no API key required)
|
||||
Route::post('/auth/register', [AuthController::class, 'register']);
|
||||
Route::post('/auth/login', [AuthController::class, 'login']);
|
||||
|
||||
// Protected endpoints (API key required)
|
||||
Route::middleware(['throttle:60,1', VerifyApiKey::class])->group(function (): void {
|
||||
Route::get('/stations', [StationController::class, 'index']);
|
||||
Route::get('/stats/searches', [StatsController::class, 'searches']);
|
||||
Route::get('/prediction', [PredictionController::class, 'index']);
|
||||
});
|
||||
|
||||
// Sanctum-authenticated endpoints
|
||||
Route::middleware('auth:sanctum')->group(function (): void {
|
||||
Route::get('/auth/me', [AuthController::class, 'me']);
|
||||
Route::post('/auth/logout', [AuthController::class, 'logout']);
|
||||
});
|
||||
|
||||
@@ -5,6 +5,10 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->withHeaders(['X-Api-Key' => config('app.api_secret_key')]);
|
||||
});
|
||||
|
||||
it('registers a new user and returns a token', function () {
|
||||
$this->postJson('/api/auth/register', [
|
||||
'name' => 'Test User',
|
||||
|
||||
@@ -7,6 +7,10 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->withHeaders(['X-Api-Key' => config('app.api_secret_key')]);
|
||||
});
|
||||
|
||||
it('returns a prediction response for diesel', function () {
|
||||
$this->getJson('/api/prediction?fuel_type=diesel')
|
||||
->assertOk()
|
||||
|
||||
@@ -8,6 +8,10 @@ use Illuminate\Support\Facades\Http;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->withHeaders(['X-Api-Key' => config('app.api_secret_key')]);
|
||||
});
|
||||
|
||||
it('returns stations near coordinates filtered by fuel type', function () {
|
||||
$station = Station::factory()->create(['lat' => 52.555064, 'lng' => -0.256119]);
|
||||
StationPriceCurrent::factory()->create([
|
||||
|
||||
@@ -5,6 +5,10 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->withHeaders(['X-Api-Key' => config('app.api_secret_key')]);
|
||||
});
|
||||
|
||||
it('returns search stats for current week', function () {
|
||||
// 10 searches within the rolling 7 days (3 unique IPs)
|
||||
Search::factory()->count(5)->create([
|
||||
|
||||
Reference in New Issue
Block a user