60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?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'],
|
|
],
|
|
]);
|
|
}
|
|
}
|