Intégration reservations et mock lavage
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
class CorsTest extends TestCase
|
||||
{
|
||||
public function test_preflight_options_on_api_returns_cors_headers(): void
|
||||
{
|
||||
$response = $this->call(
|
||||
'OPTIONS',
|
||||
'/api/v1/health',
|
||||
server: [
|
||||
'HTTP_ORIGIN' => 'http://localhost:5173',
|
||||
'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'GET',
|
||||
'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'Authorization, Content-Type',
|
||||
],
|
||||
);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertHeader('Access-Control-Allow-Origin', '*');
|
||||
$response->assertHeader('Access-Control-Allow-Methods');
|
||||
}
|
||||
|
||||
public function test_get_request_includes_cors_headers_for_browser_origin(): void
|
||||
{
|
||||
$response = $this->getJson('/api/v1/health', [
|
||||
'Origin' => 'http://localhost:5173',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertHeader('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class HealthTest extends TestCase
|
||||
{
|
||||
public function test_health_endpoint_returns_api_status(): void
|
||||
{
|
||||
$response = $this->getJson('/api/v1/health');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'status' => 'ok',
|
||||
'service' => 'laverie-api',
|
||||
],
|
||||
])
|
||||
->assertJsonStructure([
|
||||
'data' => ['timestamp'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_database_health_endpoint_returns_ok_when_connected(): void
|
||||
{
|
||||
$response = $this->getJson('/api/v1/health/db');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'status' => 'ok',
|
||||
'database' => 'sqlite',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_database_health_endpoint_returns_service_unavailable_when_disconnected(): void
|
||||
{
|
||||
DB::shouldReceive('select')
|
||||
->once()
|
||||
->with('SELECT 1')
|
||||
->andThrow(new \RuntimeException('Connection refused'));
|
||||
|
||||
$response = $this->getJson('/api/v1/health/db');
|
||||
|
||||
$response->assertStatus(503)
|
||||
->assertJson([
|
||||
'success' => false,
|
||||
'message' => 'Database connection failed',
|
||||
'errors' => [
|
||||
'database' => ['Connection unavailable'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user