ldc-arcadia-api/tests/Unit/Application/Arcadia/Usecase/IncoSheets/FindAllIncoSheetsTest.php

87 lines
3.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Application\Arcadia\Usecase\IncoSheets;
use Application\Arcadia\Usecase\IncoSheets\FindAll\FindAllIncoSheets;
use Application\Arcadia\Usecase\IncoSheets\FindAll\Input;
use Application\Arcadia\Usecase\IncoSheets\FindAll\Output;
use Application\Arcadia\Usecase\IncoSheets\FindAll\PaginatedIncoSheet;
use Application\Arcadia\Usecase\IncoSheets\FindAll\PaginatedShortIncoSheet;
use Domain\Models\Entities\Inco\IncoSheet;
use Domain\Models\ValueObjects\Brand\ArcadiaId;
use Domain\Models\ValueObjects\Brand\BrandCode;
use Domain\Models\ValueObjects\Brand\BrandName;
use Domain\Models\ValueObjects\Inco\Allegations;
use Domain\Models\ValueObjects\Inco\IncoBrand;
use Domain\Models\ValueObjects\Inco\IncoId;
use Domain\Models\ValueObjects\Inco\IncoSheetSortColumn;
use Domain\Models\ValueObjects\Inco\IncoSheetSorter;
use Domain\Models\ValueObjects\Inco\Ingredients;
use Infra\Adapters\Directories\InMemoryIncoSheetDirectory;
use Infra\Adapters\Directories\InMemoryIncoShortSheetDirectory;
use Shared\Pagination;
covers(
FindAllIncoSheets::class,
Input::class,
Output::class,
PaginatedIncoSheet::class,
PaginatedShortIncoSheet::class,
);
describe('FindAllIncoSheets Usecase Unit Tests', function (): void {
$directory = new InMemoryIncoSheetDirectory();
$shortDirectory = new InMemoryIncoShortSheetDirectory();
beforeEach(function () use ($directory, $shortDirectory): void {
$directory->clear();
$shortDirectory->clear();
});
it('executes successfully and returns paginated output DTO', function () use ($directory, $shortDirectory): void {
// GIVEN
$incoId = new IncoId('12345');
$incoSheet = IncoSheet::hydrate(
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 IncoBrand(new BrandName('Le Gaulois'), new BrandCode('LGL01'), new ArcadiaId('1')),
isSeasonal: true,
weight: null,
nutriscore: null,
storageCondition: null,
additives: [],
compo: null,
createdAt: null,
updatedAt: null,
);
$directory->add($incoSheet);
$usecase = new FindAllIncoSheets($directory, $shortDirectory);
$pagination = Pagination::ofPage(1, 10);
$sorter = new IncoSheetSorter(IncoSheetSortColumn::incoSheetId, \SortDirection::Ascending);
$input = new Input($pagination, $sorter);
// WHEN
$result = $usecase->execute($input);
// THEN
expect($result)->toBeInstanceOf(Output::class)
->and($result->total)->toBe(1)
->and($result->page)->toBe(1)
->and($result->perPage)->toBe(10)
->and($result->incoSheets)->toHaveCount(1)
->and($result->incoSheets[0]->name)->toBe('Poulet Rôti 1kg');
});
});