ldc-boutique-cnc-sable/tests/Unit/App/Queries/Orders/GetPickTimeSlotQueryTest.php

64 lines
2.3 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
use App\Dto\ShopDto;
use App\Queries\Orders\GetPickTimeSlotQuery;
use App\Queries\Orders\GetPickTimeSlotQueryInput;
use App\Queries\Orders\GetPickTimeSlotQueryOutput;
use App\Services\MapUrlService;
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 Ramsey\Uuid\Uuid;
describe('GetPickTimeSlotQuery', function (): void {
it('returns pick time slot output with step BOOKING, shop, mapUrl and timeslots', function (): void {
// GIVEN
$shopperId = new ShopperId(Uuid::uuid7());
$input = new GetPickTimeSlotQueryInput($shopperId);
$shop = new Shop(
id: new ShopId(Uuid::uuid7()),
name: 'Shop 1',
address: '1 rue Test',
postcode: '75001',
city: 'Paris',
);
$slot = new PickupTimeSlot(now(), 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)->toBeInstanceOf(GetPickTimeSlotQueryOutput::class)
->and($output->step)->toBe(OrderTunnelStep::BOOKING)
->and($output->shop)->toBeInstanceOf(ShopDto::class)
->and($output->shop->name)->toBe('Shop 1')
->and($output->mapUrl)->toBe('https://maps.example.com')
->and($output->timeSlots)->toBe($timeSlots);
});
});