2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects;
|
|
|
|
|
|
2026-11-16 15:49:48 +01:00
|
|
|
use Carbon\Carbon;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Carbon\CarbonImmutable;
|
|
|
|
|
use Domain\Enums\RepeatFrequency;
|
|
|
|
|
use Domain\Models\Entities\PickupExceptionOnDate;
|
|
|
|
|
use Domain\Models\ValueObjects\Entities\PickupExceptionId;
|
|
|
|
|
use Domain\Models\ValueObjects\ShopPickupOverride;
|
2026-11-17 12:15:39 +01:00
|
|
|
use Shared\Helpers\UuidHelper;
|
2026-06-14 21:32:07 +02:00
|
|
|
|
2026-11-16 15:49:48 +01:00
|
|
|
beforeEach(function (): void {
|
|
|
|
|
$now = CarbonImmutable::parse('2026-06-15 10:00:00', 'Europe/Paris');
|
|
|
|
|
CarbonImmutable::setTestNow($now);
|
|
|
|
|
Carbon::setTestNow($now);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(function (): void {
|
|
|
|
|
CarbonImmutable::setTestNow();
|
|
|
|
|
Carbon::setTestNow();
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-14 21:32:07 +02:00
|
|
|
describe('ShopPickupOverride', function (): void {
|
|
|
|
|
it('can instantiate correctly', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$exception = new PickupExceptionOnDate(
|
2026-11-17 12:15:39 +01:00
|
|
|
new PickupExceptionId(UuidHelper::v7()),
|
2026-06-14 21:32:07 +02:00
|
|
|
CarbonImmutable::now(),
|
|
|
|
|
'Label',
|
|
|
|
|
true,
|
|
|
|
|
RepeatFrequency::YEARLY,
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$replacement = CarbonImmutable::now()->addDay();
|
|
|
|
|
$deadline = CarbonImmutable::now()->subDay();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$shopPickup = new ShopPickupOverride(
|
|
|
|
|
$exception,
|
|
|
|
|
$replacement,
|
|
|
|
|
$deadline
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($shopPickup->exception)->toBe($exception)
|
|
|
|
|
->and($shopPickup->replacementDate)->toBe($replacement)
|
|
|
|
|
->and($shopPickup->orderDeadlineAt)->toBe($deadline);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws exception if orderDeadlineAt is not strictly before replacementDate', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$exception = new PickupExceptionOnDate(
|
2026-11-17 12:15:39 +01:00
|
|
|
new PickupExceptionId(UuidHelper::v7()),
|
2026-06-14 21:32:07 +02:00
|
|
|
CarbonImmutable::now(),
|
|
|
|
|
'Label',
|
|
|
|
|
true,
|
|
|
|
|
RepeatFrequency::YEARLY,
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$replacement = CarbonImmutable::now();
|
|
|
|
|
$deadline = CarbonImmutable::now()->addDay();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$action = fn () => new ShopPickupOverride(
|
|
|
|
|
$exception,
|
|
|
|
|
$replacement,
|
|
|
|
|
$deadline
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($action)->toThrow(\DomainException::class, 'Order deadline must be strictly before the replacement date');
|
|
|
|
|
});
|
2026-10-29 20:35:13 +01:00
|
|
|
|
|
|
|
|
it('correctly handles replacement and deadlines', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$exception = new PickupExceptionOnDate(
|
2026-11-17 12:15:39 +01:00
|
|
|
new PickupExceptionId(UuidHelper::v7()),
|
2026-11-16 16:13:14 +01:00
|
|
|
CarbonImmutable::parse('2025-05-01'),
|
2026-10-29 20:35:13 +01:00
|
|
|
'Labour Day',
|
|
|
|
|
false,
|
|
|
|
|
RepeatFrequency::YEARLY,
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
|
2026-11-16 16:13:14 +01:00
|
|
|
$defaultDeadline = CarbonImmutable::parse('2025-04-28 14:00:00');
|
2026-10-29 20:35:13 +01:00
|
|
|
|
|
|
|
|
$blockedOverride = new ShopPickupOverride(
|
|
|
|
|
exception: $exception,
|
|
|
|
|
replacementDate: null,
|
|
|
|
|
orderDeadlineAt: null
|
|
|
|
|
);
|
|
|
|
|
|
2026-11-16 16:13:14 +01:00
|
|
|
$customDeadline = CarbonImmutable::parse('2025-04-29 12:00:00');
|
2026-10-29 20:35:13 +01:00
|
|
|
$activeOverride = new ShopPickupOverride(
|
|
|
|
|
exception: $exception,
|
2026-11-16 16:13:14 +01:00
|
|
|
replacementDate: CarbonImmutable::parse('2025-05-02'),
|
2026-10-29 20:35:13 +01:00
|
|
|
orderDeadlineAt: $customDeadline
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect($blockedOverride->hasReplacement())->toBeFalse()
|
|
|
|
|
->and($blockedOverride->effectiveDeadline($defaultDeadline)->equalTo($defaultDeadline))->toBeTrue()
|
|
|
|
|
->and($activeOverride->hasReplacement())->toBeTrue()
|
|
|
|
|
->and($activeOverride->effectiveDeadline($defaultDeadline)->equalTo($customDeadline))->toBeTrue();
|
|
|
|
|
|
2026-11-16 16:13:14 +01:00
|
|
|
$beforeCustom = CarbonImmutable::parse('2025-04-29 10:00:00');
|
|
|
|
|
$afterCustom = CarbonImmutable::parse('2025-04-29 15:00:00');
|
2026-10-29 20:35:13 +01:00
|
|
|
|
|
|
|
|
expect($activeOverride->isDeadlinePassed($beforeCustom, $defaultDeadline))->toBeFalse()
|
|
|
|
|
->and($activeOverride->isDeadlinePassed($afterCustom, $defaultDeadline))->toBeTrue();
|
|
|
|
|
});
|
2026-06-14 21:32:07 +02:00
|
|
|
});
|