79 lines
2.5 KiB
PHP
79 lines
2.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Actions\ProductIncos\CreateProductIncoInput;
|
||
|
|
use App\Models\Product;
|
||
|
|
use Domain\Enums\Nutriscore;
|
||
|
|
use Domain\Models\ValueObjects\NutritionalValues;
|
||
|
|
|
||
|
|
describe('CreateProductIncoInput', function () {
|
||
|
|
test('it can be instantiated with valid data', function () {
|
||
|
|
// GIVEN
|
||
|
|
$product = new Product();
|
||
|
|
$nutrition = new NutritionalValues(refWeightG: 100.0);
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$input = new CreateProductIncoInput(
|
||
|
|
product: $product,
|
||
|
|
no_art: 12,
|
||
|
|
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->product)->toBe($product)
|
||
|
|
->and($input->no_art)->toBe(12)
|
||
|
|
->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 defaults nutrition to empty NutritionalValues', function () {
|
||
|
|
// GIVEN
|
||
|
|
$product = new Product();
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$input = new CreateProductIncoInput(
|
||
|
|
product: $product,
|
||
|
|
);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($input->nutrition)->toBeInstanceOf(NutritionalValues::class)
|
||
|
|
->and($input->no_art)->toBeNull();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('it throws when no_art is less than 1', function () {
|
||
|
|
// GIVEN
|
||
|
|
$product = new Product();
|
||
|
|
|
||
|
|
// WHEN & THEN
|
||
|
|
expect(fn () => new CreateProductIncoInput(
|
||
|
|
product: $product,
|
||
|
|
no_art: 0,
|
||
|
|
))->toThrow(\InvalidArgumentException::class, 'Article number must be greater than or equal to 1.');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('it throws when servings exceeds 20 characters', function () {
|
||
|
|
// GIVEN
|
||
|
|
$product = new Product();
|
||
|
|
|
||
|
|
// WHEN & THEN
|
||
|
|
expect(fn () => new CreateProductIncoInput(
|
||
|
|
product: $product,
|
||
|
|
servings: str_repeat('a', 21),
|
||
|
|
))->toThrow(\InvalidArgumentException::class, 'Servings cannot exceed 20 characters.');
|
||
|
|
});
|
||
|
|
});
|