ldc-arcadia-api/tests/Feature/Api/V1/Employee/EmployeesIndexTest.php
Jérémy Munsch 39d394b7fb
test(Employee): add feature tests for employee endpoints
- Implement tests for retrieving employee details and listing employees.
- Validate responses against OpenAPI specifications.
2026-08-13 12:55:38 +02:00

101 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Api\V1\Employee;
use Infra\Database\Models\Employee;
describe('Employees Index Feature API', function (): void {
beforeEach(function (): void {
Employee::factory()->count(3)->create();
});
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 for establishment, site, and service query filters', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
// WHEN
$response = $test->getJson('/api/v1/employees?establishment=01&siteId=LDCSER&serviceId=097');
// THEN
$response->assertStatus(200);
});
});