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&siteIds=LDCSER&serviceId=097'); // THEN $response->assertStatus(200); $response->assertJsonCount(1, 'employees'); $response->assertJsonPath('employees.0.matricule', '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'); }); it('returns 200 OK and filters results for siteIds scalar query filter without brackets', function (): void { // GIVEN RuPersonneSirhFactory::truncate(); RuPersonneSirhFactory::new()->create([ 'MATRICULE_FIC' => '01155902', 'SITE_FIC' => 'LDCSER', ]); RuPersonneSirhFactory::new()->create([ 'MATRICULE_FIC' => '01155903', 'SITE_FIC' => 'SLELA', ]); /** @var \Tests\TestCase $test */ $test = $this; // WHEN $response = $test->getJson('/api/v1/employees?siteIds=LDCSER'); // THEN $response->assertStatus(200); $response->assertJsonCount(1, 'employees'); $response->assertJsonPath('employees.0.matricule', '01155902'); }); it('ignores database rows with invalid matricules like comments or alphanumeric strings', function (): void { // GIVEN RuPersonneSirhFactory::truncate(); // Valid employee RuPersonneSirhFactory::new()->create([ 'MATRICULE_FIC' => '01155902', 'NOM_FIC' => 'DOE', 'PRENOM_FIC' => 'John', ]); // Invalid employees / comments in prod database RuPersonneSirhFactory::new()->create([ 'MATRICULE_FIC' => '# s996008', 'NOM_FIC' => 'ARRIVE SAINT FULGENT', 'PRENOM_FIC' => 'Baie de stockage', ]); RuPersonneSirhFactory::new()->create([ 'MATRICULE_FIC' => 'd05600013', 'NOM_FIC' => 'PYPOPS', 'PRENOM_FIC' => 'Diana', ]); RuPersonneSirhFactory::new()->create([ 'MATRICULE_FIC' => 'P99900029', 'NOM_FIC' => 'DPE BEL', 'PRENOM_FIC' => 'Bel', ]); /** @var \Tests\TestCase $test */ $test = $this; // WHEN $response = $test->getJson('/api/v1/employees'); // THEN $response->assertStatus(200); $response->assertJsonCount(1, 'employees'); $response->assertJsonPath('employees.0.matricule', '01155902'); $response->assertJsonPath('pagination.totalItems', 1); }); });