ldc-arcadia-api/tests/Feature/Api/V1/Employees/EmployeesIndexTest.php
Jérémy Munsch 34b76cb397
test(feature): align feature and openapi tests with replicated Oracle tables
- Update tests to use factory static helpers and avoid hardcoded table/connection names
- Align test data columns with real replicated Oracle schema
- Remove obsolete duplicate IncoSheetsShowTest
2026-08-26 17:29:18 +02:00

150 lines
4.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Api\V1\Employees;
use Database\ArcadiaReplicate\Factories\Refp\RuPersonneSirhFactory;
describe('Employees Index Feature API', function (): void {
beforeEach(function (): void {
RuPersonneSirhFactory::truncate();
RuPersonneSirhFactory::new()->createMany(3);
});
it('returns 200 OK for default employees list request', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
// WHEN
$response = $test->getJson('/api/v1/employees');
// THEN
$response->assertStatus(200);
$response->assertJsonStructure([
'employees',
'pagination' => [
'page',
'pageSize',
'totalItems',
'totalPages',
'links',
],
]);
});
it('returns 200 OK for page and pageSize pagination query', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
// WHEN
$response = $test->getJson('/api/v1/employees?page=1&pageSize=2');
// THEN
$response->assertStatus(200);
$response->assertJsonPath('pagination.pageSize', 2);
});
it('returns 200 OK for offset and limit pagination query', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
// WHEN
$response = $test->getJson('/api/v1/employees?offset=0&limit=2');
// THEN
$response->assertStatus(200);
$response->assertJsonPath('pagination.pageSize', 2);
});
it('returns 200 OK for sorting query parameters', function (string $sortBy, string $direction): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
// WHEN
$response = $test->getJson("/api/v1/employees?sortBy={$sortBy}&sortDirection={$direction}");
// THEN
$response->assertStatus(200);
})->with([
['arcadiaId', 'Ascending'],
['startDate', 'Descending'],
['createdAt', 'Ascending'],
]);
it('returns 200 OK for date filtering with since parameter', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
// WHEN
$response = $test->getJson('/api/v1/employees?since=2024-01-01');
// THEN
$response->assertStatus(200);
});
it('returns 200 OK and filters results for establishment, site, and service query filters', function (): void {
// GIVEN
RuPersonneSirhFactory::truncate();
RuPersonneSirhFactory::new()->create([
'MATRICULE_FIC' => '01155902',
'ETAB_FIC' => '01',
'SITE_FIC' => 'LDCSER',
'SERVICE_FIC' => '097',
]);
RuPersonneSirhFactory::new()->create([
'MATRICULE_FIC' => '1234567',
'ETAB_FIC' => 'LY',
'SITE_FIC' => 'LDCSER',
'SERVICE_FIC' => '101',
]);
/** @var \Tests\TestCase $test */
$test = $this;
// WHEN
$response = $test->getJson('/api/v1/employees?establishment=01&siteId=LDCSER&serviceId=097');
// THEN
$response->assertStatus(200);
$response->assertJsonCount(1, 'employees');
$response->assertJsonPath('employees.0.id', '01155902');
});
it('returns 200 OK and filters results for siteIds array query filter', function (): void {
// GIVEN
RuPersonneSirhFactory::truncate();
RuPersonneSirhFactory::new()->create([
'MATRICULE_FIC' => '01155902',
'SITE_FIC' => 'LDCSER',
]);
RuPersonneSirhFactory::new()->create([
'MATRICULE_FIC' => '01155903',
'SITE_FIC' => 'SLELA',
]);
RuPersonneSirhFactory::new()->create([
'MATRICULE_FIC' => '01155904',
'SITE_FIC' => 'OTHER',
]);
/** @var \Tests\TestCase $test */
$test = $this;
// WHEN
$response = $test->getJson('/api/v1/employees?siteIds[]=LDCSER&siteIds[]=SLELA');
// THEN
$response->assertStatus(200);
$response->assertJsonCount(2, 'employees');
});
});