76 lines
2.6 KiB
PHP
76 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Actions\PickupExceptions\UpdatePickupExceptionInput;
|
|
use App\Models\PickupException;
|
|
use Domain\Enums\RepeatFrequency;
|
|
|
|
describe('UpdatePickupExceptionInput', function () {
|
|
test('it can be instantiated with valid data', function () {
|
|
// GIVEN
|
|
$pickupException = new PickupException();
|
|
$date = '2026-05-08';
|
|
$label = 'Victoire 1945';
|
|
$repeatable = true;
|
|
$repeatFrequency = RepeatFrequency::YEARLY;
|
|
|
|
// WHEN
|
|
$input = new UpdatePickupExceptionInput(
|
|
pickupException: $pickupException,
|
|
date: $date,
|
|
label: $label,
|
|
repeatable: $repeatable,
|
|
repeat_frequency: $repeatFrequency,
|
|
);
|
|
|
|
// THEN
|
|
expect($input->pickupException)->toBe($pickupException)
|
|
->and($input->date)->toBe('2026-05-08')
|
|
->and($input->label)->toBe('Victoire 1945')
|
|
->and($input->repeatable)->toBeTrue()
|
|
->and($input->repeat_frequency)->toBe(RepeatFrequency::YEARLY);
|
|
});
|
|
|
|
test('it throws when date is invalid format', function () {
|
|
// GIVEN
|
|
$pickupException = new PickupException();
|
|
|
|
// WHEN & THEN
|
|
expect(fn () => new UpdatePickupExceptionInput(
|
|
pickupException: $pickupException,
|
|
date: '08/05/2026',
|
|
label: 'Victoire 1945',
|
|
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
|
|
$pickupException = new PickupException();
|
|
|
|
// WHEN & THEN
|
|
expect(fn () => new UpdatePickupExceptionInput(
|
|
pickupException: $pickupException,
|
|
date: '2026-05-08',
|
|
label: ' ',
|
|
repeatable: true,
|
|
repeat_frequency: RepeatFrequency::YEARLY,
|
|
))->toThrow(\InvalidArgumentException::class, 'Label cannot be empty.');
|
|
});
|
|
|
|
test('it throws when label exceeds 255 characters', function () {
|
|
// GIVEN
|
|
$pickupException = new PickupException();
|
|
|
|
// WHEN & THEN
|
|
expect(fn () => new UpdatePickupExceptionInput(
|
|
pickupException: $pickupException,
|
|
date: '2026-05-08',
|
|
label: str_repeat('a', 256),
|
|
repeatable: true,
|
|
repeat_frequency: RepeatFrequency::YEARLY,
|
|
))->toThrow(\InvalidArgumentException::class, 'Label cannot exceed 255 characters.');
|
|
});
|
|
});
|