Skip to content

Commit 4bf36ff

Browse files
committed
Add first api tests
1 parent 3e85a63 commit 4bf36ff

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/**
4+
* HealthPingTest.php
5+
*
6+
* Tests for the v1 liveness (ping) and health-check endpoints.
7+
*/
8+
9+
namespace LibreNMS\Tests\Feature\Api\V1;
10+
11+
use App\Models\User;
12+
use Illuminate\Foundation\Testing\DatabaseTransactions;
13+
use Laravel\Sanctum\Sanctum;
14+
use LibreNMS\Tests\DBTestCase;
15+
16+
final class HealthPingTest extends DBTestCase
17+
{
18+
use DatabaseTransactions;
19+
20+
public function testPingIsPublicAndReturnsOk(): void
21+
{
22+
$this->getJson('/api/v1/ping')
23+
->assertOk()
24+
->assertExactJson(['status' => 'ok']);
25+
}
26+
27+
public function testHealthRequiresAuthentication(): void
28+
{
29+
$this->getJson('/api/v1/health')
30+
->assertUnauthorized();
31+
}
32+
33+
public function testHealthReturnsOkWhenSubsystemsAreUp(): void
34+
{
35+
/** @var User $user */
36+
$user = User::factory()->create();
37+
Sanctum::actingAs($user);
38+
39+
$this->getJson('/api/v1/health')
40+
->assertOk()
41+
->assertJson([
42+
'status' => 'ok',
43+
'checks' => [
44+
'database' => ['ok' => true],
45+
'cache' => ['ok' => true],
46+
],
47+
])
48+
->assertJsonStructure([
49+
'status',
50+
'checks' => [
51+
'database' => ['ok'],
52+
'cache' => ['ok'],
53+
],
54+
]);
55+
}
56+
}

0 commit comments

Comments
 (0)