125 lines
3.9 KiB
PHP
125 lines
3.9 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.');
|
||
|
|
});
|
||
|
|
});
|