ldc-cocotte/tests/Unit/App/Actions/Shops/UpdateShopPickupExceptionsInputTest.php

169 lines
5.7 KiB
PHP

<?php
declare(strict_types=1);
use App\Actions\Shops\UpdateShopPickupExceptionsInput;
use App\Models\Shop;
use InvalidArgumentException;
describe('UpdateShopPickupExceptionsInput', function () {
test('it can be instantiated with shop and valid sync data', function () {
// GIVEN
$shop = new Shop();
$syncData = [
'018f6c40-1234-7123-8123-123456789012' => [
'replacement_date' => '2026-06-01',
'order_deadline_at' => '2026-05-31 18:00:00',
],
123 => [
'replacement_date' => null,
'order_deadline_at' => null,
],
];
// WHEN
$input = new UpdateShopPickupExceptionsInput(
shop: $shop,
syncData: $syncData,
);
// THEN
expect($input->shop)->toBe($shop)
->and($input->syncData)->toBe($syncData);
});
test('it can be instantiated with empty sync data', function () {
// GIVEN
$shop = new Shop();
// WHEN
$input = new UpdateShopPickupExceptionsInput(
shop: $shop,
syncData: [],
);
// THEN
expect($input->shop)->toBe($shop)
->and($input->syncData)->toBe([]);
});
test('it throws when sync item is not an array', function () {
// GIVEN
$shop = new Shop();
$invalidSyncData = [
'key1' => 'invalid-not-array',
];
// WHEN & THEN
/** @phpstan-ignore-next-line */
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
->toThrow(InvalidArgumentException::class, 'Each sync item must be an array.');
});
test('it throws when replacement_date key is missing', function () {
// GIVEN
$shop = new Shop();
$invalidSyncData = [
'key1' => [
'order_deadline_at' => '2026-05-31 18:00:00',
],
];
// WHEN & THEN
/** @phpstan-ignore-next-line */
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
->toThrow(InvalidArgumentException::class, 'Sync item must contain replacement_date key.');
});
test('it throws when order_deadline_at key is missing', function () {
// GIVEN
$shop = new Shop();
$invalidSyncData = [
'key1' => [
'replacement_date' => '2026-06-01',
],
];
// WHEN & THEN
/** @phpstan-ignore-next-line */
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
->toThrow(InvalidArgumentException::class, 'Sync item must contain order_deadline_at key.');
});
test('it throws when replacement_date is not string or null', function () {
// GIVEN
$shop = new Shop();
$invalidSyncData = [
'key1' => [
'replacement_date' => 12345,
'order_deadline_at' => null,
],
];
// WHEN & THEN
/** @phpstan-ignore-next-line */
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
->toThrow(InvalidArgumentException::class, 'replacement_date must be a string or null.');
});
test('it throws when order_deadline_at is not string or null', function () {
// GIVEN
$shop = new Shop();
$invalidSyncData = [
'key1' => [
'replacement_date' => null,
'order_deadline_at' => ['invalid'],
],
];
// WHEN & THEN
/** @phpstan-ignore-next-line */
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
->toThrow(InvalidArgumentException::class, 'order_deadline_at must be a string or null.');
});
test('it throws when order_deadline_at is set but replacement_date is null', function () {
// GIVEN
$shop = new Shop();
$invalidSyncData = [
'key1' => [
'replacement_date' => null,
'order_deadline_at' => '2026-06-01 10:00:00',
],
];
// WHEN & THEN
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
->toThrow(InvalidArgumentException::class, 'A replacement date is required when an order deadline is set.');
});
test('it throws when order_deadline_at is after replacement_date', function () {
// GIVEN
$shop = new Shop();
$invalidSyncData = [
'key1' => [
'replacement_date' => '2026-10-02',
'order_deadline_at' => '2026-10-11 14:53:00',
],
];
// WHEN & THEN
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
->toThrow(InvalidArgumentException::class, 'Order deadline must be strictly before the replacement date.');
});
test('it throws when order_deadline_at is equal to replacement_date', function () {
// GIVEN
$shop = new Shop();
$invalidSyncData = [
'key1' => [
'replacement_date' => '2026-10-02',
'order_deadline_at' => '2026-10-02 00:00:00',
],
];
// WHEN & THEN
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
->toThrow(InvalidArgumentException::class, 'Order deadline must be strictly before the replacement date.');
});
});