ldc-arcadia-api/tests/Feature/OpenApi/V1/IncoSheets/IncoSheetOpenApiTest.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

92 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\OpenApi\V1\IncoSheets;
use Infra\Database\Models\IncoSheet;
use Spectator\Spectator;
beforeEach(function (): void {
/** @var \Tests\TestCase $this */
Spectator::reset();
Spectator::using('openapi.yaml');
});
describe('IncoSheet OpenAPI Conformance', function (): void {
it('validates GET /api/v1/inco-sheets list response against openapi spec', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
IncoSheet::factory()->create([
'id' => '10001',
'name' => 'Poulet Rôti 1kg',
]);
// WHEN
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
$response = $test->getJson('/api/v1/inco-sheets');
// THEN
$response->assertStatus(200);
$response->assertValidRequest();
$response->assertValidResponse(200);
});
it('validates GET /api/v1/inco-sheets list response with short projection against openapi spec', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
IncoSheet::factory()->create([
'id' => '10002',
'name' => 'Salade Niçoise 300g',
]);
// WHEN
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
$response = $test->getJson('/api/v1/inco-sheets?short=true');
// THEN
$response->assertStatus(200);
$response->assertValidRequest();
$response->assertValidResponse(200);
});
it('validates GET /api/v1/inco-sheets/{incoId} detail response against openapi spec', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
IncoSheet::factory()->create([
'id' => '10003',
'name' => 'Lasagnes Bolognaise 400g',
]);
// WHEN
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
$response = $test->getJson('/api/v1/inco-sheets/10003');
// THEN
$response->assertStatus(200);
$response->assertValidRequest();
$response->assertValidResponse(200);
});
it('validates GET /api/v1/inco-sheets/{incoId} 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/inco-sheets/{$unexistingId}");
// THEN
$response->assertStatus(404);
$response->assertValidRequest();
$response->assertValidResponse(404);
});
});