ldc-arcadia-api/tests/Feature/Api/V1/IncoSheets/IncoSheetsIndexTest.php
Jérémy Munsch 152ee2b5a2
feat(api): add IncoSheets feature with DDD clean architecture, tests & OpenAPI spec
- Use cases: FindAllIncoSheets & FindIncoSheet (filters, pagination, short projection)
- Presentation: controllers, FormRequests with scalar validation, DTOs (camelCase)
- Ports & Adapters: IncoSheetDirectory & EloquentIncoSheetDirectory
- Tests: Pest 4 unit, integration, OpenAPI spectator conformance, dynamic arch tests
- Docs: updated Bruno collection and OpenAPI spec
2026-08-14 11:33:05 +02:00

98 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Api\V1\IncoSheets;
use Infra\Database\Models\IncoSheet;
describe('IncoSheets Index Feature API', function (): void {
beforeEach(function (): void {
IncoSheet::factory()->count(3)->create();
});
it('returns 200 OK for default inco-sheets list request', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
// WHEN
$response = $test->getJson('/api/v1/inco-sheets');
// THEN
$response->assertStatus(200);
$response->assertJsonStructure([
'incoSheets',
'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/inco-sheets?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/inco-sheets?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/inco-sheets?sortBy={$sortBy}&sortDirection={$direction}");
// THEN
$response->assertStatus(200);
})->with([
['incoSheetId', 'Ascending'],
['createdAt', 'Descending'],
['updatedAt', 'Ascending'],
]);
it('returns 200 OK for short projection query', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
// WHEN
$response = $test->getJson('/api/v1/inco-sheets?short=true');
// THEN
$response->assertStatus(200);
$response->assertJsonStructure([
'incoSheets' => [
'*' => [
'id',
'name',
'label',
],
],
]);
});
});