ldc-arcadia-api/tests/Feature/OpenApi/V1/Employees/EmployeeOpenApiTest.php
Jérémy Munsch 3080c5dcfe
test(employees): add feature tests for employee retrieval and filtering
- Implement tests for employee show and index endpoints.
- Validate responses against OpenAPI specifications.
2026-08-14 09:59:24 +02:00

110 lines
3.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\OpenApi\V1\Employees;
use Infra\Database\Models\Employee;
use Spectator\Spectator;
beforeEach(function (): void {
/** @var \Tests\TestCase $this */
Spectator::reset();
Spectator::using('openapi.yaml');
});
describe('Employee OpenAPI Conformance', function (): void {
it('validates GET /api/v1/employees list response against openapi spec', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
Employee::factory()->create([
'public_employee_number' => '0115590',
'last_name' => 'DOE',
'first_name' => 'John',
'start_date' => '2024-01-15',
'establishment' => '01',
'site' => 'LDCSER',
'service' => '097',
]);
// WHEN
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
$response = $test->getJson('/api/v1/employees');
// THEN
$response->assertStatus(200);
$response->assertValidRequest();
$response->assertValidResponse(200);
});
it('validates GET /api/v1/employees list response with siteIds filter against openapi spec', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
// WHEN
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
$response = $test->getJson('/api/v1/employees?siteIds[]=LDCSER&siteIds[]=SLELA');
// THEN
$response->assertStatus(200);
$response->assertValidRequest();
$response->assertValidResponse(200);
});
it('validates GET /api/v1/employees/{id} detail response against openapi spec', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
Employee::factory()->create([
'public_employee_number' => '0115591',
'last_name' => 'SMITH',
'first_name' => 'Jane',
'start_date' => '2024-02-01',
'establishment' => '02',
'site' => 'SLELA',
'service' => '098',
]);
// WHEN
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
$response = $test->getJson('/api/v1/employees/0115591');
// THEN
$response->assertValidRequest();
$response->assertValidResponse(200);
});
it('validates GET /api/v1/employees/{id} not found response against openapi spec', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
$unexistingId = '9999999';
// WHEN
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
$response = $test->getJson("/api/v1/employees/{$unexistingId}");
// THEN
$response->assertValidRequest();
$response->assertValidResponse(404);
});
it('validates GET /api/v1/employees/{id} validation error for invalid matricule', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
$invalidId = 'invalid';
// WHEN
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
$response = $test->getJson("/api/v1/employees/{$invalidId}");
// THEN
$response->assertStatus(422);
$response->assertValidResponse(422);
});
});