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

85 lines
3 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Application\Usecase\IncoSheets;
use Application\Exceptions\NotFoundException;
use Application\Usecase\IncoSheets\Find\FindIncoSheet;
use Application\Usecase\IncoSheets\Find\Input;
use Application\Usecase\IncoSheets\Find\Output;
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 Domain\Ports\Directories\IncoSheetDirectory;
covers(FindIncoSheet::class);
describe('FindIncoSheet Usecase Unit Tests', function (): void {
it('executes successfully and returns Output when inco sheet exists', function (): void {
// GIVEN
$incoId = new IncoId('12345');
$input = new Input($incoId);
$incoDirectory = \Mockery::mock(IncoSheetDirectory::class);
$usecase = new FindIncoSheet($incoDirectory);
$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 à 180°C',
tips: null,
sellFamilly: 'Boucherie',
ingredients: new Ingredients(['Ingrédients' => ['Viande de dinde (66%)']]),
portions: null,
allergens: [],
brand: new Brand('M01', 'Le Gaulois'),
isSeasonal: true,
weight: null,
nutriscore: null,
storageCondition: null,
additives: [],
compo: null,
createdAt: null,
updatedAt: null,
);
$incoDirectory->shouldReceive('find')
->once()
->with($incoId)
->andReturn($incoSheet);
// WHEN
$result = $usecase->execute($input);
// THEN
expect($result)->toBeInstanceOf(Output::class)
->and($result->id)->toBe($incoId)
->and($result->name)->toBe('Poulet Rôti 1kg')
->and($result->label)->toBe('Poulet Rôti Classe A')
->and($result->brand->label)->toBe('Le Gaulois')
->and($result->isSeasonal)->toBeTrue();
});
it('throws NotFoundException when inco sheet does not exist', function (): void {
// GIVEN
$incoId = new IncoId('99999');
$input = new Input($incoId);
$incoDirectory = \Mockery::mock(IncoSheetDirectory::class);
$usecase = new FindIncoSheet($incoDirectory);
$incoDirectory->shouldReceive('find')
->once()
->with($incoId)
->andReturnNull();
// WHEN & THEN
expect(fn () => $usecase->execute($input))
->toThrow(NotFoundException::class, "IncoSheet '99999' not found.");
});
});