60 lines
2.1 KiB
PHP
60 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Actions\PickupExceptions\CreatePickupExceptionInput;
|
|
use Domain\Enums\RepeatFrequency;
|
|
|
|
describe('CreatePickupExceptionInput', function () {
|
|
test('it can be instantiated with valid data', function () {
|
|
// GIVEN
|
|
$date = '2026-05-01';
|
|
$label = 'Fête du Travail';
|
|
$repeatable = true;
|
|
$repeatFrequency = RepeatFrequency::YEARLY;
|
|
|
|
// WHEN
|
|
$input = new CreatePickupExceptionInput(
|
|
date: $date,
|
|
label: $label,
|
|
repeatable: $repeatable,
|
|
repeat_frequency: $repeatFrequency,
|
|
);
|
|
|
|
// THEN
|
|
expect($input->date)->toBe('2026-05-01')
|
|
->and($input->label)->toBe('Fête du Travail')
|
|
->and($input->repeatable)->toBeTrue()
|
|
->and($input->repeat_frequency)->toBe(RepeatFrequency::YEARLY);
|
|
});
|
|
|
|
test('it throws when date is invalid format', function () {
|
|
// GIVEN & WHEN & THEN
|
|
expect(fn () => new CreatePickupExceptionInput(
|
|
date: '01/05/2026',
|
|
label: 'Fête du Travail',
|
|
repeatable: true,
|
|
repeat_frequency: RepeatFrequency::YEARLY,
|
|
))->toThrow(\InvalidArgumentException::class, 'Date must be in Y-m-d format.');
|
|
});
|
|
|
|
test('it throws when label is empty', function () {
|
|
// GIVEN & WHEN & THEN
|
|
expect(fn () => new CreatePickupExceptionInput(
|
|
date: '2026-05-01',
|
|
label: ' ',
|
|
repeatable: true,
|
|
repeat_frequency: RepeatFrequency::YEARLY,
|
|
))->toThrow(\InvalidArgumentException::class, 'Label cannot be empty.');
|
|
});
|
|
|
|
test('it throws when label exceeds 255 characters', function () {
|
|
// GIVEN & WHEN & THEN
|
|
expect(fn () => new CreatePickupExceptionInput(
|
|
date: '2026-05-01',
|
|
label: str_repeat('a', 256),
|
|
repeatable: true,
|
|
repeat_frequency: RepeatFrequency::YEARLY,
|
|
))->toThrow(\InvalidArgumentException::class, 'Label cannot exceed 255 characters.');
|
|
});
|
|
});
|