create(['default' => true]); $customer = new Customer(); $customer->email = new Email('slot.buyer@example.com'); $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->saveOrFail(); $employee = new Employee(); $employee->customer_id = $customer->id; $employee->matricule = new Matricule('1000303'); $employee->code = new Code('ABCDEF'); $employee->nom = 'Durand'; $employee->prenom = 'Sophie'; $employee->start_date = Carbon::parse('2025-01-01'); $employee->etablissement = new ShopperEstablishmentCode('01'); $employee->site = new ShopperSiteCode('SITE'); $employee->service = new ShopperServiceCode('01'); $employee->saveOrFail(); $productId = new ProductId(UuidHelper::v7()); $basket = new Basket(new BasketId(UuidHelper::v7()), [ $productId->value->toString() => new BasketProduct( id: $productId, name: 'Filet de Poulet', qty: 1, unitPriceHt: Money::EUR(1000), unitDiscount: Money::EUR(0), taxRate: TaxRate::TVA_5_5, weightGrams: 500, brand: ProductBrand::loue, incoId: new IncoId(654321), orderUnit: OrderUnit::PCE, slug: 'filet-de-poulet', picture: null, description: null, weightVariable: false, discountRate: DiscountRate::zero(), priceKgTtc: Money::EUR(1000), options: [], ), ]); /** @var \Illuminate\Contracts\Session\Session $session */ $session = Session::driver(); $builderManager = new SessionOrderBuilderManager($session, 'order_tunnel_builder_session'); $builderManager->save(OrderBuilder::fromBasket($basket, $customer->getId())); $shopRepo = new EloquentShopRepository(); $shopperRepo = new EloquentShopperRepository(); $orderRepo = new EloquentOrderRepository(); /** @var \Domain\Ports\Services\RegateService&\Mockery\MockInterface $regateService */ $regateService = \Mockery::mock(RegateService::class); $tunnelService = new OrderTunnelService( new LaravelDomainEventDispatcher(), new ShopperService($shopRepo, $shopperRepo), $builderManager, new PickupSchedulingService(new EloquentPickupExceptionRepository()), $orderRepo, new EloquentProductRepository(), new CustomerOrderLimitPolicy(20000, 20000, new Currency('EUR')), $shopRepo, $shopperRepo, new OrderService($orderRepo), new EloquentEmployeeStatisticsService(), $regateService, new DatabaseTunnelAttemptTrackerService($session, 'order_tunnel_attempt_id'), ); return [$customer, $shop, $builderManager, $tunnelService]; } it('matches an open pickup day and upgrades the session builder to OrderBuilderCompleted', function (): void { // GIVEN [$customer, $shop, $builderManager, $tunnelService] = makePickSlotEnvironment(); $action = new ApplyPickTimeSlot($tunnelService); // Friday of current week after Monday 10:00 cutoff -> open $targetFriday = CarbonImmutable::parse('2026-11-20', 'Europe/Paris'); // WHEN $output = $action(new ApplyPickTimeSlotInput($customer->getId(), $targetFriday)); // THEN expect($output->status)->toBe(ApplyPickTimeSlotStatus::MATCHED) ->and($output->timeSlot)->not->toBeNull() ->and($output->timeSlot?->getAt()->format('Y-m-d'))->toBe('2026-11-20'); $completed = $builderManager->get(); assert($completed instanceof OrderBuilderCompleted); expect($completed->getShopId()->equals($shop->getId()))->toBeTrue(); }); it('returns UNAVAILABLE when the requested date is blocked by a shop PickupException', function (): void { // GIVEN [$customer, $shop, $_, $tunnelService] = makePickSlotEnvironment(); $blockedException = PickupException::factory()->create([ 'date' => '2026-11-20', 'label' => 'Fermeture exceptionnelle', ]); $shop->pickupExceptions()->attach($blockedException->id, [ 'replacement_date' => null, 'order_deadline_at' => null, ]); $action = new ApplyPickTimeSlot($tunnelService); $targetFriday = CarbonImmutable::parse('2026-11-20', 'Europe/Paris'); // WHEN $output = $action(new ApplyPickTimeSlotInput($customer->getId(), $targetFriday)); // THEN expect($output->status)->toBe(ApplyPickTimeSlotStatus::UNAVAILABLE) ->and($output->timeSlot)->toBeNull(); }); });