52 lines
1.7 KiB
PHP
52 lines
1.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Actions\ProductIncos\UpdateProductIncoInput;
|
||
|
|
use App\Models\ProductInco;
|
||
|
|
use Domain\Enums\Nutriscore;
|
||
|
|
use Domain\Models\ValueObjects\NutritionalValues;
|
||
|
|
|
||
|
|
describe('UpdateProductIncoInput', function () {
|
||
|
|
test('it can be instantiated with valid data', function () {
|
||
|
|
// GIVEN
|
||
|
|
$inco = new ProductInco();
|
||
|
|
$nutrition = new NutritionalValues(refWeightG: 100.0);
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$input = new UpdateProductIncoInput(
|
||
|
|
inco: $inco,
|
||
|
|
ingredients: 'Poulet, sel',
|
||
|
|
preparation: 'Au four',
|
||
|
|
servings: '4 pers',
|
||
|
|
allergens: 'Aucun',
|
||
|
|
selling_argument: 'Top qualité',
|
||
|
|
nutriscore: Nutriscore::B,
|
||
|
|
nutriscore_args: 'Faible teneur en sel',
|
||
|
|
nutrition: $nutrition,
|
||
|
|
);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($input->inco)->toBe($inco)
|
||
|
|
->and($input->ingredients)->toBe('Poulet, sel')
|
||
|
|
->and($input->preparation)->toBe('Au four')
|
||
|
|
->and($input->servings)->toBe('4 pers')
|
||
|
|
->and($input->allergens)->toBe('Aucun')
|
||
|
|
->and($input->selling_argument)->toBe('Top qualité')
|
||
|
|
->and($input->nutriscore)->toBe(Nutriscore::B)
|
||
|
|
->and($input->nutriscore_args)->toBe('Faible teneur en sel')
|
||
|
|
->and($input->nutrition)->toBe($nutrition);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('it throws when servings exceeds 20 characters', function () {
|
||
|
|
// GIVEN
|
||
|
|
$inco = new ProductInco();
|
||
|
|
|
||
|
|
// WHEN & THEN
|
||
|
|
expect(fn () => new UpdateProductIncoInput(
|
||
|
|
inco: $inco,
|
||
|
|
servings: str_repeat('a', 21),
|
||
|
|
))->toThrow(\InvalidArgumentException::class, 'Servings cannot exceed 20 characters.');
|
||
|
|
});
|
||
|
|
});
|