2026-09-30 11:20:39 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-10 14:28:00 +01:00
|
|
|
use App\Cqs\Actions\Shops\UpdateShopPickupExceptionsInput;
|
2026-09-30 11:20:39 +02:00
|
|
|
use App\Models\Shop;
|
|
|
|
|
|
|
|
|
|
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))
|
2026-10-02 10:53:21 +02:00
|
|
|
->toThrow(\InvalidArgumentException::class, 'Each sync item must be an array.');
|
2026-09-30 11:20:39 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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))
|
2026-10-02 10:53:21 +02:00
|
|
|
->toThrow(\InvalidArgumentException::class, 'Sync item must contain replacement_date key.');
|
2026-09-30 11:20:39 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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))
|
2026-10-02 10:53:21 +02:00
|
|
|
->toThrow(\InvalidArgumentException::class, 'Sync item must contain order_deadline_at key.');
|
2026-09-30 11:20:39 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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))
|
2026-10-02 10:53:21 +02:00
|
|
|
->toThrow(\InvalidArgumentException::class, 'replacement_date must be a string or null.');
|
2026-09-30 11:20:39 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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))
|
2026-10-02 10:53:21 +02:00
|
|
|
->toThrow(\InvalidArgumentException::class, 'order_deadline_at must be a string or null.');
|
2026-09-30 11:20:39 +02:00
|
|
|
});
|
2026-09-30 12:31:38 +02:00
|
|
|
|
|
|
|
|
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))
|
2026-10-02 10:53:21 +02:00
|
|
|
->toThrow(\InvalidArgumentException::class, 'A replacement date is required when an order deadline is set.');
|
2026-09-30 12:31:38 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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))
|
2026-10-02 10:53:21 +02:00
|
|
|
->toThrow(\InvalidArgumentException::class, 'Order deadline must be strictly before the replacement date.');
|
2026-09-30 12:31:38 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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))
|
2026-10-02 10:53:21 +02:00
|
|
|
->toThrow(\InvalidArgumentException::class, 'Order deadline must be strictly before the replacement date.');
|
2026-09-30 12:31:38 +02:00
|
|
|
});
|
2026-09-30 11:20:39 +02:00
|
|
|
});
|