ldc-boutique-cnc-sable/tests/Unit/App/Actions/Orders/ApplyPickTimeSlotTest.php

62 lines
2 KiB
PHP

<?php
declare(strict_types=1);
use App\Actions\Orders\ApplyPickTimeSlot;
use App\Actions\Orders\ApplyPickTimeSlotInput;
use Carbon\CarbonImmutable;
use Domain\Builders\OrderBuilderWithBasket;
use Domain\Models\Entities\Shop;
use Domain\Models\ValueObjects\Entities\ShopId;
use Domain\Models\ValueObjects\Entities\ShopperId;
use Domain\Models\ValueObjects\PickupTimeSlot;
use Domain\Services\OrderTunnelService;
use Ramsey\Uuid\Uuid;
describe('ApplyPickTimeSlot', function (): void {
it('applies time slot to order builder via OrderTunnelService', function (): void {
// GIVEN
$shopperId = new ShopperId(Uuid::uuid7());
$timeslot = CarbonImmutable::parse('2026-10-15');
$input = new ApplyPickTimeSlotInput(
shopperId: $shopperId,
timeslot: $timeslot,
);
$builder = \Mockery::mock(OrderBuilderWithBasket::class);
$shop = new Shop(
id: new ShopId(Uuid::uuid7()),
name: 'Shop 1',
address: '1 rue Test',
postcode: '75001',
city: 'Paris',
);
$slot = new PickupTimeSlot($timeslot, new \DateInterval('PT1H'));
$timeSlots = [$slot];
$orderTunnelService = \Mockery::mock(OrderTunnelService::class);
$orderTunnelService->shouldReceive('getBuilderFromBasketOrFail')
->once()
->andReturn($builder);
$orderTunnelService->shouldReceive('getShopForCustomer')
->once()
->with($shopperId)
->andReturn($shop);
$orderTunnelService->shouldReceive('getAvailableTimeSlots')
->once()
->with($shop)
->andReturn($timeSlots);
$orderTunnelService->shouldReceive('applyTimeSlot')
->once()
->with($builder, $shop, $timeslot, $timeSlots)
->andReturn($slot);
$action = new ApplyPickTimeSlot($orderTunnelService);
// WHEN
$result = $action($input);
// THEN
expect($result)->toBe($slot);
});
});