ldc-arcadia-api/tests/Unit/Application/Arcadia/Usecase/Incosheets/SearchIncoSheetsTest.php

113 lines
3.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Application\Arcadia\Usecase\IncoSheets;
use Application\Arcadia\Usecase\IncoSheets\Search\Input;
use Application\Arcadia\Usecase\IncoSheets\Search\Output;
use Application\Arcadia\Usecase\IncoSheets\Search\PaginatedIncoSheet;
use Application\Arcadia\Usecase\IncoSheets\Search\PaginatedShortIncoSheet;
use Application\Arcadia\Usecase\IncoSheets\Search\SearchIncoSheets;
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\IncoIdQuery;
use Domain\Models\ValueObjects\Inco\Ingredients;
use Infra\Adapters\Directories\InMemoryIncoSheetDirectory;
use Infra\Adapters\Directories\InMemoryIncoShortSheetDirectory;
use Shared\Pagination;
covers(
SearchIncoSheets::class,
Input::class,
Output::class,
PaginatedIncoSheet::class,
PaginatedShortIncoSheet::class,
);
describe('SearchIncoSheets Usecase Unit Tests', function (): void {
$directory = new InMemoryIncoSheetDirectory();
$shortDirectory = new InMemoryIncoShortSheetDirectory();
beforeEach(function () use ($directory, $shortDirectory): void {
$directory->clear();
$shortDirectory->clear();
});
it('searches full inco sheets matching query and brands', function () use ($directory, $shortDirectory): void {
// GIVEN
$incoSheet = IncoSheet::hydrate(
id: new IncoId('12345'),
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 SearchIncoSheets($directory, $shortDirectory);
$input = new Input(
query: new IncoIdQuery('12%'),
short: false,
pagination: Pagination::ofPage(1, 10),
brands: new BrandCode('LGL01'),
);
// WHEN
$result = $usecase->execute($input);
// THEN
expect($result)->toBeInstanceOf(Output::class)
->and($result->total)->toBe(1)
->and($result->incoSheets)->toHaveCount(1);
});
it('searches short inco sheets when short option is true', function () use ($directory, $shortDirectory): void {
// GIVEN
$shortSheet = IncoShortSheet::hydrate(
id: new IncoId('12345'),
name: 'Poulet Rôti 1kg',
label: 'Poulet Rôti Classe A',
createdAt: null,
updatedAt: null,
);
$shortDirectory->add($shortSheet);
$usecase = new SearchIncoSheets($directory, $shortDirectory);
$input = new Input(
query: new IncoIdQuery('12%'),
short: true,
pagination: Pagination::ofPage(1, 10),
);
// WHEN
$result = $usecase->execute($input);
// THEN
expect($result)->toBeInstanceOf(Output::class)
->and($result->total)->toBe(1)
->and($result->incoSheets)->toHaveCount(1);
});
});