127 lines
4.2 KiB
PHP
127 lines
4.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\OpenApi\V1\Employees;
|
|
|
|
use Database\ArcadiaReplicate\Factories\Refp\RuPersonneSirhFactory;
|
|
use Spectator\Spectator;
|
|
|
|
beforeEach(function (): void {
|
|
/** @var \Tests\TestCase $this */
|
|
Spectator::reset();
|
|
Spectator::using('openapi.yaml');
|
|
|
|
RuPersonneSirhFactory::truncate();
|
|
});
|
|
|
|
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;
|
|
|
|
RuPersonneSirhFactory::new()->create([
|
|
'MATRICULE_FIC' => '0115590',
|
|
'NOM_FIC' => 'DOE',
|
|
'PRENOM_FIC' => 'John',
|
|
'DATE_DEB_FIC' => '2024-01-15',
|
|
'ETAB_FIC' => '01',
|
|
'SITE_FIC' => 'LDCSER',
|
|
'SERVICE_FIC' => '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 list response with standard RFC repeated 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;
|
|
|
|
RuPersonneSirhFactory::new()->create([
|
|
'MATRICULE_FIC' => '0115591',
|
|
'NOM_FIC' => 'SMITH',
|
|
'PRENOM_FIC' => 'Jane',
|
|
'DATE_DEB_FIC' => '2024-02-01',
|
|
'ETAB_FIC' => '02',
|
|
'SITE_FIC' => 'SLELA',
|
|
'SERVICE_FIC' => '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);
|
|
});
|
|
});
|