ldc-arcadia-api/tests/Unit/Application/Usecase/Incosheets/FindAllIncoSheetsDtoTest.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

107 lines
3.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Application\Usecase\IncoSheets;
use Application\Usecase\IncoSheets\FindAll\Filter;
use Application\Usecase\IncoSheets\FindAll\Input;
use Application\Usecase\IncoSheets\FindAll\Output;
use Application\Usecase\IncoSheets\FindAll\PaginatedIncoSheet;
use Application\Usecase\IncoSheets\FindAll\PaginatedShortIncoSheet;
use Application\Usecase\IncoSheets\FindAll\SortColumn;
use Application\Usecase\IncoSheets\FindAll\Sorter;
use Domain\Models\Entities\IncoSheet;
use Domain\Models\ValueObjects\Entities\IncoId;
use Domain\Models\ValueObjects\IncoSheets\Allegations;
use Domain\Models\ValueObjects\IncoSheets\Brand;
use Domain\Models\ValueObjects\IncoSheets\Ingredients;
use Shared\Pagination;
covers(
Filter::class,
Input::class,
Output::class,
PaginatedIncoSheet::class,
PaginatedShortIncoSheet::class,
SortColumn::class,
Sorter::class
);
describe('FindAllIncoSheets DTOs Instantiation & Logic', function (): void {
it('instantiates Filter correctly', function (): void {
// GIVEN
$since = new \DateTimeImmutable('2024-01-01');
// WHEN
$filter = new Filter($since, 'M01', 'M02');
// THEN
expect($filter->since)->toBe($since)
->and($filter->brands)->toBe(['M01', 'M02']);
});
it('throws InvalidArgumentException for empty brand string in Filter', function (): void {
expect(fn () => new Filter(null, ' '))
->toThrow(\InvalidArgumentException::class);
});
it('throws InvalidArgumentException for empty Filter parameters', function (): void {
expect(fn () => new Filter(null))
->toThrow(\InvalidArgumentException::class);
});
it('instantiates Input DTO', function (): void {
// GIVEN
$pagination = Pagination::ofPage(1, 10);
$sorter = new Sorter(SortColumn::incoSheetId, \SortDirection::Ascending);
// WHEN
$input = new Input($pagination, $sorter);
// THEN
expect($input->pagination)->toBe($pagination)
->and($input->sorter)->toBe($sorter);
});
it('creates PaginatedIncoSheet and PaginatedShortIncoSheet from domain entity and instantiates Output DTO', function (): void {
// GIVEN
$incoId = new IncoId('12345');
$incoSheet = new IncoSheet(
id: $incoId,
name: 'Poulet Rôti 1kg',
label: 'Poulet Rôti Classe A',
description: 'Poulet prêt à cuire',
allegations: new Allegations(['Volaille française']),
sellArguments: 'Délicieux',
preparationAdvices: 'Cuire 45min',
tips: null,
sellFamilly: 'Boucherie',
ingredients: new Ingredients(['main' => ['Viande']]),
portions: null,
allergens: [],
brand: new Brand('M01', 'Le Gaulois'),
isSeasonal: true,
weight: null,
nutriscore: null,
storageCondition: null,
additives: [],
compo: null,
createdAt: null,
updatedAt: null,
);
// WHEN
$full = PaginatedIncoSheet::fromDomain($incoSheet);
$short = PaginatedShortIncoSheet::fromDomain($incoSheet);
$output = new Output([$full, $short], 1, 1, 10);
// THEN
expect($full->id)->toBe($incoId)
->and($full->name)->toBe('Poulet Rôti 1kg')
->and($short->id)->toBe($incoId)
->and($short->label)->toBe('Poulet Rôti Classe A')
->and($output->total)->toBe(1)
->and($output->incoSheets)->toHaveCount(2);
});
});