63 lines
2.2 KiB
PHP
63 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\App\Cqs\Queries\Orders;
|
|
|
|
use App\Cqs\Queries\Orders\GetPickTimeSlotQuery;
|
|
use App\Cqs\Queries\Orders\GetPickTimeSlotQueryInput;
|
|
use App\Dto\ShopDto;
|
|
use App\Services\MapUrlService;
|
|
use Carbon\CarbonImmutable;
|
|
use Domain\Enums\OrderTunnelStep;
|
|
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 Shared\Helpers\UuidHelper;
|
|
|
|
describe('GetPickTimeSlotQuery', function (): void {
|
|
it('returns pick time slot output with step BOOKING, shop, mapUrl and timeslots', function (): void {
|
|
// GIVEN
|
|
$shopperId = new ShopperId(UuidHelper::v7());
|
|
$input = new GetPickTimeSlotQueryInput($shopperId);
|
|
|
|
$shop = new Shop(
|
|
id: new ShopId(UuidHelper::v7()),
|
|
name: 'Shop 1',
|
|
address: '1 rue Test',
|
|
postcode: '75001',
|
|
city: 'Paris',
|
|
);
|
|
$slot = new PickupTimeSlot(CarbonImmutable::parse('2026-10-15 10:00:00'), new \DateInterval('PT1H'));
|
|
$timeSlots = [$slot];
|
|
|
|
$orderTunnelService = \Mockery::mock(OrderTunnelService::class);
|
|
$orderTunnelService->shouldReceive('getShopForCustomer')
|
|
->once()
|
|
->with($shopperId)
|
|
->andReturn($shop);
|
|
$orderTunnelService->shouldReceive('getAvailableTimeSlots')
|
|
->once()
|
|
->with($shop)
|
|
->andReturn($timeSlots);
|
|
|
|
$mapUrlService = \Mockery::mock(MapUrlService::class);
|
|
$mapUrlService->shouldReceive('generateUrl')
|
|
->once()
|
|
->withArgs(fn ($arg) => $arg instanceof ShopDto && $arg->name === 'Shop 1')
|
|
->andReturn('https://maps.example.com');
|
|
|
|
$query = new GetPickTimeSlotQuery($orderTunnelService, $mapUrlService);
|
|
|
|
// WHEN
|
|
$output = $query($input);
|
|
|
|
// THEN
|
|
expect($output->step)->toBe(OrderTunnelStep::BOOKING)
|
|
->and($output->shop->name)->toBe('Shop 1')
|
|
->and($output->mapUrl)->toBe('https://maps.example.com')
|
|
->and($output->timeSlots)->toBe($timeSlots);
|
|
});
|
|
});
|