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

97 lines
3.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Application\Arcadia\Usecase\IncoSheets;
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\Entities\Inco\IncoShortSheet;
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 Shared\Pagination;
use Shared\Pagination\PageNumber;
use Shared\Pagination\PageSize;
covers(
Input::class,
Output::class,
PaginatedIncoSheet::class,
PaginatedShortIncoSheet::class
);
describe('FindAllIncoSheets DTOs Instantiation & Logic', function (): void {
it('instantiates Input DTO', function (): void {
// GIVEN
$pagination = Pagination::ofPage(new PageNumber(1), new PageSize(10));
$sorter = new IncoSheetSorter(IncoSheetSortColumn::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 = 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',
tips: null,
sellFamilly: 'Boucherie',
ingredients: new Ingredients(['main' => ['Viande']]),
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,
);
$shortSheet = IncoShortSheet::hydrate(
id: $incoId,
name: 'Poulet Rôti 1kg',
label: 'Poulet Rôti Classe A',
description: 'Poulet prêt à cuire',
createdAt: null,
updatedAt: null,
);
// WHEN
$full = PaginatedIncoSheet::fromDomain($incoSheet);
$short = PaginatedShortIncoSheet::fromDomain($shortSheet);
$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($short->description)->toBe('Poulet prêt à cuire')
->and($output->total)->toBe(1)
->and($output->incoSheets)->toHaveCount(2);
});
});