- Add methods to convert OrderLine and DeliveryAddress to DTOs. - Introduce toPlacedEvent method in Order to generate domain event. - Enhance OrderUnit with Regate code mapping. - Implement tests for new functionality and ensure correctness.
105 lines
3.5 KiB
PHP
105 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects;
|
|
|
|
use Carbon\CarbonImmutable;
|
|
use Domain\Enums\RepeatFrequency;
|
|
use Domain\Models\Entities\PickupExceptionOnDate;
|
|
use Domain\Models\ValueObjects\Entities\PickupExceptionId;
|
|
use Domain\Models\ValueObjects\ShopPickupOverride;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
describe('ShopPickupOverride', function (): void {
|
|
it('can instantiate correctly', function (): void {
|
|
// GIVEN
|
|
$exception = new PickupExceptionOnDate(
|
|
new PickupExceptionId(Uuid::uuid7()),
|
|
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(
|
|
new PickupExceptionId(Uuid::uuid7()),
|
|
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');
|
|
});
|
|
|
|
it('correctly handles replacement and deadlines', function (): void {
|
|
// GIVEN
|
|
$exception = new PickupExceptionOnDate(
|
|
new PickupExceptionId(Uuid::uuid7()),
|
|
CarbonImmutable::create(2025, 5, 1),
|
|
'Labour Day',
|
|
false,
|
|
RepeatFrequency::YEARLY,
|
|
false
|
|
);
|
|
|
|
$defaultDeadline = CarbonImmutable::create(2025, 4, 28, 14, 0, 0);
|
|
|
|
$blockedOverride = new ShopPickupOverride(
|
|
exception: $exception,
|
|
replacementDate: null,
|
|
orderDeadlineAt: null
|
|
);
|
|
|
|
$customDeadline = CarbonImmutable::create(2025, 4, 29, 12, 0, 0);
|
|
$activeOverride = new ShopPickupOverride(
|
|
exception: $exception,
|
|
replacementDate: CarbonImmutable::create(2025, 5, 2),
|
|
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();
|
|
|
|
$beforeCustom = CarbonImmutable::create(2025, 4, 29, 10, 0, 0);
|
|
$afterCustom = CarbonImmutable::create(2025, 4, 29, 15, 0, 0);
|
|
|
|
expect($activeOverride->isDeadlinePassed($beforeCustom, $defaultDeadline))->toBeFalse()
|
|
->and($activeOverride->isDeadlinePassed($afterCustom, $defaultDeadline))->toBeTrue();
|
|
});
|
|
});
|