refactor(tunnel): migrate Fo\TunnelController to CQS pattern
This commit is contained in:
parent
35feddfb3d
commit
aad9586ca9
40 changed files with 1879 additions and 95 deletions
42
app/Actions/Orders/ApplyPickTimeSlot.php
Normal file
42
app/Actions/Orders/ApplyPickTimeSlot.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Actions\Orders;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use Domain\Models\ValueObjects\PickupTimeSlot;
|
||||
use Domain\Services\OrderTunnelService;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Actions\Orders\ApplyPickTimeSlotInput, ?\Domain\Models\ValueObjects\PickupTimeSlot>
|
||||
*/
|
||||
final class ApplyPickTimeSlot implements Action
|
||||
{
|
||||
public function __construct(
|
||||
private readonly OrderTunnelService $orderTunnelService,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Actions\Orders\ApplyPickTimeSlotInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): ?PickupTimeSlot
|
||||
{
|
||||
Assert::isInstanceOf($input, ApplyPickTimeSlotInput::class);
|
||||
|
||||
$builder = $this->orderTunnelService->getBuilderFromBasketOrFail();
|
||||
$shop = $this->orderTunnelService->getShopForCustomer($input->shopperId);
|
||||
$timeSlots = $this->orderTunnelService->getAvailableTimeSlots($shop);
|
||||
|
||||
return $this->orderTunnelService->applyTimeSlot(
|
||||
$builder,
|
||||
$shop,
|
||||
$input->timeslot,
|
||||
$timeSlots
|
||||
);
|
||||
}
|
||||
}
|
||||
18
app/Actions/Orders/ApplyPickTimeSlotInput.php
Normal file
18
app/Actions/Orders/ApplyPickTimeSlotInput.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Actions\Orders;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use Carbon\CarbonInterface;
|
||||
use Domain\Models\ValueObjects\Entities\ShopperId;
|
||||
|
||||
final readonly class ApplyPickTimeSlotInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public ShopperId $shopperId,
|
||||
public CarbonInterface $timeslot,
|
||||
) {
|
||||
}
|
||||
}
|
||||
36
app/Actions/Orders/FinalizeOrder.php
Normal file
36
app/Actions/Orders/FinalizeOrder.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Actions\Orders;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use Domain\Models\ValueObjects\OrderReference;
|
||||
use Domain\Services\OrderTunnelService;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Actions\Orders\FinalizeOrderInput, \Domain\Models\ValueObjects\OrderReference>
|
||||
*/
|
||||
final class FinalizeOrder implements Action
|
||||
{
|
||||
public function __construct(
|
||||
private readonly OrderTunnelService $orderTunnelService,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Actions\Orders\FinalizeOrderInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): OrderReference
|
||||
{
|
||||
Assert::isInstanceOf($input, FinalizeOrderInput::class);
|
||||
|
||||
$builder = $this->orderTunnelService->getBuilderCompletedOrFail();
|
||||
$order = $this->orderTunnelService->finalizeOrder($builder);
|
||||
|
||||
return $order->reference;
|
||||
}
|
||||
}
|
||||
16
app/Actions/Orders/FinalizeOrderInput.php
Normal file
16
app/Actions/Orders/FinalizeOrderInput.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Actions\Orders;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use Domain\Models\ValueObjects\Entities\ShopperId;
|
||||
|
||||
final readonly class FinalizeOrderInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public ?ShopperId $shopperId = null,
|
||||
) {
|
||||
}
|
||||
}
|
||||
35
app/Actions/Orders/InitializeOrderTunnel.php
Normal file
35
app/Actions/Orders/InitializeOrderTunnel.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Actions\Orders;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use Domain\Services\OrderTunnelService;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Actions\Orders\InitializeOrderTunnelInput, void>
|
||||
*/
|
||||
final class InitializeOrderTunnel implements Action
|
||||
{
|
||||
public function __construct(
|
||||
private readonly OrderTunnelService $orderTunnelService,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Actions\Orders\InitializeOrderTunnelInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): void
|
||||
{
|
||||
Assert::isInstanceOf($input, InitializeOrderTunnelInput::class);
|
||||
|
||||
$this->orderTunnelService->initializeFromBasket(
|
||||
$input->basket,
|
||||
$input->shopperId
|
||||
);
|
||||
}
|
||||
}
|
||||
18
app/Actions/Orders/InitializeOrderTunnelInput.php
Normal file
18
app/Actions/Orders/InitializeOrderTunnelInput.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Actions\Orders;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use Domain\Models\Entities\Basket;
|
||||
use Domain\Models\ValueObjects\Entities\ShopperId;
|
||||
|
||||
final readonly class InitializeOrderTunnelInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public Basket $basket,
|
||||
public ShopperId $shopperId,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ namespace App\Dto;
|
|||
|
||||
use App\Models\PickupException;
|
||||
use App\Models\Shop;
|
||||
use Domain\Models\Entities\Shop as DomainShop;
|
||||
use Illuminate\Contracts\Routing\UrlRoutable;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Support\Collection;
|
||||
|
|
@ -55,6 +56,21 @@ final readonly class ShopDto implements Arrayable, UrlRoutable
|
|||
);
|
||||
}
|
||||
|
||||
public static function fromDomain(DomainShop $shop): self
|
||||
{
|
||||
return new self(
|
||||
id: $shop->id->value->toString(),
|
||||
name: $shop->name,
|
||||
address: $shop->address,
|
||||
postcode: $shop->postcode,
|
||||
city: $shop->city,
|
||||
phone: $shop->phone,
|
||||
latitude: $shop->latitude,
|
||||
longitude: $shop->longitude,
|
||||
default: $shop->isDefault,
|
||||
);
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function getRouteKey(): mixed
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,58 +4,64 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Controllers\Fo;
|
||||
|
||||
use App\Actions\Orders\ApplyPickTimeSlot;
|
||||
use App\Actions\Orders\FinalizeOrder;
|
||||
use App\Actions\Orders\InitializeOrderTunnel;
|
||||
use App\Contracts\Executor;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Fo\Orders\ConfirmOrderRequest;
|
||||
use App\Http\Requests\Fo\Orders\PickTimeSlotRequest;
|
||||
use App\Http\Requests\Fo\Orders\ValidateSummaryRequest;
|
||||
use App\Models\Order;
|
||||
use App\Services\MapUrlService;
|
||||
use App\Queries\Orders\GetBasketSummaryQuery;
|
||||
use App\Queries\Orders\GetBasketSummaryQueryInput;
|
||||
use App\Queries\Orders\GetOrderConfirmationQuery;
|
||||
use App\Queries\Orders\GetOrderConfirmationQueryInput;
|
||||
use App\Queries\Orders\GetPickTimeSlotQuery;
|
||||
use App\Queries\Orders\GetPickTimeSlotQueryInput;
|
||||
use App\Queries\Orders\GetTunnelOrderConfirmedQuery;
|
||||
use App\Queries\Orders\GetTunnelOrderConfirmedQueryInput;
|
||||
use Domain\Enums\OrderTunnelStep;
|
||||
use Domain\Exceptions\OrderTunnel\OrderLimitExceededException;
|
||||
use Domain\Exceptions\OrderTunnel\WeeklyLimitExceededException;
|
||||
use Domain\Ports\Repositories\ShopRepository;
|
||||
use Domain\Services\BasketService;
|
||||
use Domain\Services\OrderTunnelService;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Infrastructure\Adapters\Services\AppCustomerAuthService;
|
||||
|
||||
class TunnelController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AppCustomerAuthService $authService,
|
||||
private readonly BasketService $basketService,
|
||||
private readonly OrderTunnelService $orderTunnelService,
|
||||
private readonly MapUrlService $mapUrlService,
|
||||
private readonly ShopRepository $shopRepository,
|
||||
private readonly Executor $executor,
|
||||
) {
|
||||
}
|
||||
|
||||
// * -- STEP 1 -- *
|
||||
|
||||
public function basketSummary(BasketService $basketService): View
|
||||
public function basketSummary(GetBasketSummaryQuery $query): View
|
||||
{
|
||||
$this->authorize('canReviewBasketSummary', OrderTunnelStep::class);
|
||||
|
||||
$step = OrderTunnelStep::REVIEW;
|
||||
$basket = $basketService->getBasket();
|
||||
$output = $this->executor->execute(
|
||||
$query,
|
||||
new GetBasketSummaryQueryInput()
|
||||
);
|
||||
|
||||
return view('fo.tunnel.basket-summary', compact(
|
||||
'step',
|
||||
'basket'
|
||||
));
|
||||
return view('fo.tunnel.basket-summary', [
|
||||
'step' => $output->step,
|
||||
'basket' => $output->basket,
|
||||
]);
|
||||
}
|
||||
|
||||
public function basketSummarySubmit(ValidateSummaryRequest $request): RedirectResponse
|
||||
{
|
||||
public function basketSummarySubmit(
|
||||
ValidateSummaryRequest $request,
|
||||
InitializeOrderTunnel $action
|
||||
): RedirectResponse {
|
||||
$this->authorize('canReviewBasketSummary', OrderTunnelStep::class);
|
||||
|
||||
$customer = $this->authService->getCustomerAsMandatory();
|
||||
$basket = $this->basketService->getBasket();
|
||||
|
||||
$this->orderTunnelService->initializeFromBasket(
|
||||
$basket,
|
||||
$customer->getId()
|
||||
$this->executor->execute(
|
||||
$action,
|
||||
$request->toInitializeOrderTunnelInput()
|
||||
);
|
||||
|
||||
return to_route('fo.sales.pick-time-slot');
|
||||
|
|
@ -63,40 +69,34 @@ class TunnelController extends Controller
|
|||
|
||||
// * -- STEP 2 -- *
|
||||
|
||||
public function pickTimeSlot(): View
|
||||
{
|
||||
$this->authorize('canPickTimeSlot', OrderTunnelStep::class);
|
||||
|
||||
$customer = $this->authService->getCustomerAsMandatory();
|
||||
$shop = $this->orderTunnelService->getShopForCustomer($customer->getId());
|
||||
$timeSlots = $this->orderTunnelService->getAvailableTimeSlots($shop);
|
||||
$step = OrderTunnelStep::BOOKING;
|
||||
|
||||
$mapUrl = $this->mapUrlService->generateUrl($shop);
|
||||
|
||||
return view('fo.tunnel.pick-time-slot', compact(
|
||||
'step',
|
||||
'shop',
|
||||
'mapUrl',
|
||||
'timeSlots'
|
||||
));
|
||||
}
|
||||
|
||||
public function pickTimeSlotSubmit(PickTimeSlotRequest $request): RedirectResponse
|
||||
public function pickTimeSlot(GetPickTimeSlotQuery $query): View
|
||||
{
|
||||
$this->authorize('canPickTimeSlot', OrderTunnelStep::class);
|
||||
|
||||
$customer = $this->authService->getCustomerAsMandatory();
|
||||
$builder = $this->orderTunnelService->getBuilderFromBasketOrFail();
|
||||
|
||||
$shop = $this->orderTunnelService->getShopForCustomer($customer->getId());
|
||||
$timeSlots = $this->orderTunnelService->getAvailableTimeSlots($shop);
|
||||
$output = $this->executor->execute(
|
||||
$query,
|
||||
new GetPickTimeSlotQueryInput($customer->getId())
|
||||
);
|
||||
|
||||
$matchedSlot = $this->orderTunnelService->applyTimeSlot(
|
||||
$builder,
|
||||
$shop,
|
||||
$request->getTimeslot(),
|
||||
$timeSlots
|
||||
return view('fo.tunnel.pick-time-slot', [
|
||||
'step' => $output->step,
|
||||
'shop' => $output->shop,
|
||||
'mapUrl' => $output->mapUrl,
|
||||
'timeSlots' => $output->timeSlots,
|
||||
]);
|
||||
}
|
||||
|
||||
public function pickTimeSlotSubmit(
|
||||
PickTimeSlotRequest $request,
|
||||
ApplyPickTimeSlot $action
|
||||
): RedirectResponse {
|
||||
$this->authorize('canPickTimeSlot', OrderTunnelStep::class);
|
||||
|
||||
$matchedSlot = $this->executor->execute(
|
||||
$action,
|
||||
$request->toApplyPickTimeSlotInput()
|
||||
);
|
||||
|
||||
if ($matchedSlot === null) {
|
||||
|
|
@ -110,67 +110,60 @@ class TunnelController extends Controller
|
|||
|
||||
// * -- STEP 3 -- *
|
||||
|
||||
public function confirmation(): View
|
||||
public function confirmation(GetOrderConfirmationQuery $query): View
|
||||
{
|
||||
$this->authorize('canFinalizeOrder', OrderTunnelStep::class);
|
||||
|
||||
$step = OrderTunnelStep::CONFIRMATION;
|
||||
$builder = $this->orderTunnelService->getBuilderCompletedOrFail();
|
||||
$basket = $builder->getBasket();
|
||||
$output = $this->executor->execute(
|
||||
$query,
|
||||
new GetOrderConfirmationQueryInput()
|
||||
);
|
||||
|
||||
$shop = $this->shopRepository->find($builder->getShopId());
|
||||
|
||||
if (! $shop) {
|
||||
abort(404, 'Shop not found');
|
||||
}
|
||||
|
||||
return view('fo.tunnel.confirmation', compact(
|
||||
'step',
|
||||
'basket',
|
||||
'builder',
|
||||
'shop'
|
||||
));
|
||||
return view('fo.tunnel.confirmation', [
|
||||
'step' => $output->step,
|
||||
'basket' => $output->basket,
|
||||
'builder' => $output->builder,
|
||||
'shop' => $output->shop,
|
||||
]);
|
||||
}
|
||||
|
||||
public function confirmationSubmit(Request $request): RedirectResponse
|
||||
{
|
||||
public function confirmationSubmit(
|
||||
ConfirmOrderRequest $request,
|
||||
FinalizeOrder $action
|
||||
): RedirectResponse {
|
||||
$this->authorize('canFinalizeOrder', OrderTunnelStep::class);
|
||||
|
||||
$request->validate([
|
||||
'ok_cgv' => ['accepted'],
|
||||
]);
|
||||
|
||||
$builder = $this->orderTunnelService->getBuilderCompletedOrFail();
|
||||
|
||||
try {
|
||||
$order = $this->orderTunnelService->finalizeOrder($builder);
|
||||
/** @var \Domain\Models\ValueObjects\OrderReference $orderReference */
|
||||
$orderReference = $this->executor->execute(
|
||||
$action,
|
||||
$request->toFinalizeOrderInput()
|
||||
);
|
||||
} catch (WeeklyLimitExceededException | OrderLimitExceededException $e) {
|
||||
return back()->with('message', $e->getMessage());
|
||||
}
|
||||
|
||||
return to_route('fo.sales.confirmation.show-confirmed', $order->reference->value);
|
||||
return to_route('fo.sales.confirmation.show-confirmed', $orderReference->value);
|
||||
}
|
||||
|
||||
// * -- CONFIRMATION -- *
|
||||
|
||||
public function confirmed(Order $order): View
|
||||
{
|
||||
public function confirmed(
|
||||
Order $order,
|
||||
GetTunnelOrderConfirmedQuery $query
|
||||
): View {
|
||||
$this->authorize('viewOwn', $order);
|
||||
|
||||
$step = OrderTunnelStep::CONFIRMATION;
|
||||
$shop = $order->shop;
|
||||
$output = $this->executor->execute(
|
||||
$query,
|
||||
new GetTunnelOrderConfirmedQueryInput($order)
|
||||
);
|
||||
|
||||
if (! $shop) {
|
||||
throw new \UnexpectedValueException('Shop not found for order ' . $order->getId());
|
||||
}
|
||||
|
||||
$mapUrl = $this->mapUrlService->generateUrl($shop);
|
||||
|
||||
return view('fo.tunnel.confirmed', compact(
|
||||
'step',
|
||||
'order',
|
||||
'shop',
|
||||
'mapUrl'
|
||||
));
|
||||
return view('fo.tunnel.confirmed', [
|
||||
'step' => $output->step,
|
||||
'order' => $output->order,
|
||||
'shop' => $output->shop,
|
||||
'mapUrl' => $output->mapUrl,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
41
app/Http/Requests/Fo/Orders/ConfirmOrderRequest.php
Normal file
41
app/Http/Requests/Fo/Orders/ConfirmOrderRequest.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Fo\Orders;
|
||||
|
||||
use App\Actions\Orders\FinalizeOrderInput;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Infrastructure\Adapters\Services\AppCustomerAuthService;
|
||||
|
||||
class ConfirmOrderRequest extends FormRequest
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AppCustomerAuthService $authService,
|
||||
) {
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->authService->check();
|
||||
}
|
||||
|
||||
public function toFinalizeOrderInput(): FinalizeOrderInput
|
||||
{
|
||||
$customer = $this->authService->getCustomerAsMandatory();
|
||||
|
||||
return new FinalizeOrderInput(
|
||||
shopperId: $customer->getId(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'ok_cgv' => ['accepted'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Fo\Orders;
|
||||
|
||||
use App\Actions\Orders\ApplyPickTimeSlotInput;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Carbon\CarbonInterface;
|
||||
use Domain\Exceptions\OrderTunnel\WeeklyLimitExceededException;
|
||||
|
|
@ -23,6 +24,16 @@ class PickTimeSlotRequest extends FormRequest
|
|||
) {
|
||||
}
|
||||
|
||||
public function toApplyPickTimeSlotInput(): ApplyPickTimeSlotInput
|
||||
{
|
||||
$customer = $this->authService->getCustomerAsMandatory();
|
||||
|
||||
return new ApplyPickTimeSlotInput(
|
||||
shopperId: $customer->getId(),
|
||||
timeslot: $this->getTimeslot(),
|
||||
);
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->authService->check();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Fo\Orders;
|
||||
|
||||
use App\Actions\Orders\InitializeOrderTunnelInput;
|
||||
use Domain\Exceptions\OrderTunnel\OrderLimitExceededException;
|
||||
use Domain\Services\BasketService;
|
||||
use Domain\Services\OrderTunnelService;
|
||||
|
|
@ -19,6 +20,17 @@ class ValidateSummaryRequest extends FormRequest
|
|||
) {
|
||||
}
|
||||
|
||||
public function toInitializeOrderTunnelInput(): InitializeOrderTunnelInput
|
||||
{
|
||||
$customer = $this->authService->getCustomerAsMandatory();
|
||||
$basket = $this->basketService->getBasket();
|
||||
|
||||
return new InitializeOrderTunnelInput(
|
||||
basket: $basket,
|
||||
shopperId: $customer->getId(),
|
||||
);
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->authService->check();
|
||||
|
|
|
|||
36
app/Queries/Orders/GetBasketSummaryQuery.php
Normal file
36
app/Queries/Orders/GetBasketSummaryQuery.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Queries\Orders;
|
||||
|
||||
use App\Contracts\Query;
|
||||
use App\Contracts\QueryInput;
|
||||
use Domain\Enums\OrderTunnelStep;
|
||||
use Domain\Services\BasketService;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Query<\App\Queries\Orders\GetBasketSummaryQueryInput, \App\Queries\Orders\GetBasketSummaryQueryOutput>
|
||||
*/
|
||||
final readonly class GetBasketSummaryQuery implements Query
|
||||
{
|
||||
public function __construct(
|
||||
private BasketService $basketService,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Queries\Orders\GetBasketSummaryQueryInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(QueryInput $input): GetBasketSummaryQueryOutput
|
||||
{
|
||||
Assert::isInstanceOf($input, GetBasketSummaryQueryInput::class);
|
||||
|
||||
return new GetBasketSummaryQueryOutput(
|
||||
step: OrderTunnelStep::REVIEW,
|
||||
basket: $this->basketService->getBasket(),
|
||||
);
|
||||
}
|
||||
}
|
||||
14
app/Queries/Orders/GetBasketSummaryQueryInput.php
Normal file
14
app/Queries/Orders/GetBasketSummaryQueryInput.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Queries\Orders;
|
||||
|
||||
use App\Contracts\QueryInput;
|
||||
|
||||
final readonly class GetBasketSummaryQueryInput implements QueryInput
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
}
|
||||
17
app/Queries/Orders/GetBasketSummaryQueryOutput.php
Normal file
17
app/Queries/Orders/GetBasketSummaryQueryOutput.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Queries\Orders;
|
||||
|
||||
use Domain\Enums\OrderTunnelStep;
|
||||
use Domain\Models\Entities\Basket;
|
||||
|
||||
final readonly class GetBasketSummaryQueryOutput
|
||||
{
|
||||
public function __construct(
|
||||
public OrderTunnelStep $step,
|
||||
public Basket $basket,
|
||||
) {
|
||||
}
|
||||
}
|
||||
53
app/Queries/Orders/GetOrderConfirmationQuery.php
Normal file
53
app/Queries/Orders/GetOrderConfirmationQuery.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Queries\Orders;
|
||||
|
||||
use App\Contracts\Query;
|
||||
use App\Contracts\QueryInput;
|
||||
use App\Dto\ShopDto;
|
||||
use Domain\Enums\OrderTunnelStep;
|
||||
use Domain\Ports\Repositories\ShopRepository;
|
||||
use Domain\Services\OrderTunnelService;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Query<\App\Queries\Orders\GetOrderConfirmationQueryInput, \App\Queries\Orders\GetOrderConfirmationQueryOutput>
|
||||
*/
|
||||
final readonly class GetOrderConfirmationQuery implements Query
|
||||
{
|
||||
public function __construct(
|
||||
private OrderTunnelService $orderTunnelService,
|
||||
private ShopRepository $shopRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Queries\Orders\GetOrderConfirmationQueryInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(QueryInput $input): GetOrderConfirmationQueryOutput
|
||||
{
|
||||
Assert::isInstanceOf($input, GetOrderConfirmationQueryInput::class);
|
||||
|
||||
$builder = $this->orderTunnelService->getBuilderCompletedOrFail();
|
||||
$basket = $builder->getBasket();
|
||||
|
||||
$shop = $this->shopRepository->find($builder->getShopId());
|
||||
|
||||
if (! $shop) {
|
||||
throw new NotFoundHttpException('Shop not found');
|
||||
}
|
||||
|
||||
$shopDto = ShopDto::fromDomain($shop);
|
||||
|
||||
return new GetOrderConfirmationQueryOutput(
|
||||
step: OrderTunnelStep::CONFIRMATION,
|
||||
basket: $basket,
|
||||
builder: $builder,
|
||||
shop: $shopDto,
|
||||
);
|
||||
}
|
||||
}
|
||||
14
app/Queries/Orders/GetOrderConfirmationQueryInput.php
Normal file
14
app/Queries/Orders/GetOrderConfirmationQueryInput.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Queries\Orders;
|
||||
|
||||
use App\Contracts\QueryInput;
|
||||
|
||||
final readonly class GetOrderConfirmationQueryInput implements QueryInput
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
}
|
||||
21
app/Queries/Orders/GetOrderConfirmationQueryOutput.php
Normal file
21
app/Queries/Orders/GetOrderConfirmationQueryOutput.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Queries\Orders;
|
||||
|
||||
use App\Dto\ShopDto;
|
||||
use Domain\Builders\OrderBuilderCompleted;
|
||||
use Domain\Enums\OrderTunnelStep;
|
||||
use Domain\Models\Entities\Basket;
|
||||
|
||||
final readonly class GetOrderConfirmationQueryOutput
|
||||
{
|
||||
public function __construct(
|
||||
public OrderTunnelStep $step,
|
||||
public Basket $basket,
|
||||
public OrderBuilderCompleted $builder,
|
||||
public ShopDto $shop,
|
||||
) {
|
||||
}
|
||||
}
|
||||
46
app/Queries/Orders/GetPickTimeSlotQuery.php
Normal file
46
app/Queries/Orders/GetPickTimeSlotQuery.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Queries\Orders;
|
||||
|
||||
use App\Contracts\Query;
|
||||
use App\Contracts\QueryInput;
|
||||
use App\Dto\ShopDto;
|
||||
use App\Services\MapUrlService;
|
||||
use Domain\Enums\OrderTunnelStep;
|
||||
use Domain\Services\OrderTunnelService;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Query<\App\Queries\Orders\GetPickTimeSlotQueryInput, \App\Queries\Orders\GetPickTimeSlotQueryOutput>
|
||||
*/
|
||||
final readonly class GetPickTimeSlotQuery implements Query
|
||||
{
|
||||
public function __construct(
|
||||
private OrderTunnelService $orderTunnelService,
|
||||
private MapUrlService $mapUrlService,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Queries\Orders\GetPickTimeSlotQueryInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(QueryInput $input): GetPickTimeSlotQueryOutput
|
||||
{
|
||||
Assert::isInstanceOf($input, GetPickTimeSlotQueryInput::class);
|
||||
|
||||
$shop = $this->orderTunnelService->getShopForCustomer($input->shopperId);
|
||||
$timeSlots = $this->orderTunnelService->getAvailableTimeSlots($shop);
|
||||
$shopDto = ShopDto::fromDomain($shop);
|
||||
$mapUrl = $this->mapUrlService->generateUrl($shopDto);
|
||||
|
||||
return new GetPickTimeSlotQueryOutput(
|
||||
step: OrderTunnelStep::BOOKING,
|
||||
shop: $shopDto,
|
||||
timeSlots: $timeSlots,
|
||||
mapUrl: $mapUrl,
|
||||
);
|
||||
}
|
||||
}
|
||||
16
app/Queries/Orders/GetPickTimeSlotQueryInput.php
Normal file
16
app/Queries/Orders/GetPickTimeSlotQueryInput.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Queries\Orders;
|
||||
|
||||
use App\Contracts\QueryInput;
|
||||
use Domain\Models\ValueObjects\Entities\ShopperId;
|
||||
|
||||
final readonly class GetPickTimeSlotQueryInput implements QueryInput
|
||||
{
|
||||
public function __construct(
|
||||
public ShopperId $shopperId,
|
||||
) {
|
||||
}
|
||||
}
|
||||
23
app/Queries/Orders/GetPickTimeSlotQueryOutput.php
Normal file
23
app/Queries/Orders/GetPickTimeSlotQueryOutput.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Queries\Orders;
|
||||
|
||||
use App\Dto\ShopDto;
|
||||
use Domain\Enums\OrderTunnelStep;
|
||||
use Domain\Models\ValueObjects\PickupTimeSlot;
|
||||
|
||||
final readonly class GetPickTimeSlotQueryOutput
|
||||
{
|
||||
/**
|
||||
* @param array<int, PickupTimeSlot> $timeSlots
|
||||
*/
|
||||
public function __construct(
|
||||
public OrderTunnelStep $step,
|
||||
public ShopDto $shop,
|
||||
public array $timeSlots,
|
||||
public string $mapUrl,
|
||||
) {
|
||||
}
|
||||
}
|
||||
52
app/Queries/Orders/GetTunnelOrderConfirmedQuery.php
Normal file
52
app/Queries/Orders/GetTunnelOrderConfirmedQuery.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Queries\Orders;
|
||||
|
||||
use App\Contracts\Query;
|
||||
use App\Contracts\QueryInput;
|
||||
use App\Dto\OrderDto;
|
||||
use App\Dto\ShopDto;
|
||||
use App\Services\MapUrlService;
|
||||
use Domain\Enums\OrderTunnelStep;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Query<\App\Queries\Orders\GetTunnelOrderConfirmedQueryInput, \App\Queries\Orders\GetTunnelOrderConfirmedQueryOutput>
|
||||
*/
|
||||
final readonly class GetTunnelOrderConfirmedQuery implements Query
|
||||
{
|
||||
public function __construct(
|
||||
private MapUrlService $mapUrlService,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Queries\Orders\GetTunnelOrderConfirmedQueryInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(QueryInput $input): GetTunnelOrderConfirmedQueryOutput
|
||||
{
|
||||
Assert::isInstanceOf($input, GetTunnelOrderConfirmedQueryInput::class);
|
||||
|
||||
$order = $input->order;
|
||||
$order->loadMissing(['shop', 'lines']);
|
||||
|
||||
$shop = $order->shop;
|
||||
if (! $shop) {
|
||||
throw new \UnexpectedValueException('Shop not found for order ' . $order->getId());
|
||||
}
|
||||
|
||||
$shopDto = ShopDto::fromModel($shop);
|
||||
$mapUrl = $this->mapUrlService->generateUrl($shopDto);
|
||||
$orderDto = OrderDto::fromModel($order);
|
||||
|
||||
return new GetTunnelOrderConfirmedQueryOutput(
|
||||
step: OrderTunnelStep::CONFIRMATION,
|
||||
order: $orderDto,
|
||||
shop: $shopDto,
|
||||
mapUrl: $mapUrl,
|
||||
);
|
||||
}
|
||||
}
|
||||
16
app/Queries/Orders/GetTunnelOrderConfirmedQueryInput.php
Normal file
16
app/Queries/Orders/GetTunnelOrderConfirmedQueryInput.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Queries\Orders;
|
||||
|
||||
use App\Contracts\QueryInput;
|
||||
use App\Models\Order;
|
||||
|
||||
final readonly class GetTunnelOrderConfirmedQueryInput implements QueryInput
|
||||
{
|
||||
public function __construct(
|
||||
public Order $order,
|
||||
) {
|
||||
}
|
||||
}
|
||||
20
app/Queries/Orders/GetTunnelOrderConfirmedQueryOutput.php
Normal file
20
app/Queries/Orders/GetTunnelOrderConfirmedQueryOutput.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Queries\Orders;
|
||||
|
||||
use App\Dto\OrderDto;
|
||||
use App\Dto\ShopDto;
|
||||
use Domain\Enums\OrderTunnelStep;
|
||||
|
||||
final readonly class GetTunnelOrderConfirmedQueryOutput
|
||||
{
|
||||
public function __construct(
|
||||
public OrderTunnelStep $step,
|
||||
public OrderDto $order,
|
||||
public ShopDto $shop,
|
||||
public string $mapUrl,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
@ -4,13 +4,14 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Dto\ShopDto;
|
||||
use App\Models\Shop;
|
||||
use Domain\Models\Entities\Shop as EntitiesShop;
|
||||
use Domain\Models\ValueObjects\DeliveryAddress;
|
||||
|
||||
class MapUrlService
|
||||
{
|
||||
public function generateUrl(Shop | EntitiesShop | DeliveryAddress $addressable): string
|
||||
public function generateUrl(Shop | EntitiesShop | DeliveryAddress | ShopDto $addressable): string
|
||||
{
|
||||
$query = urlencode("{$addressable->name} {$addressable->address} {$addressable->postcode} {$addressable->city}");
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,43 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Contracts\Executor;
|
||||
use App\Dto\ShopDto;
|
||||
use App\Http\Middleware\CustomerIsEmployed;
|
||||
use App\Http\Middleware\EnsureCustomerEmailIsVerified;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Order;
|
||||
use App\Models\Page;
|
||||
use App\Models\Shop;
|
||||
use App\Queries\Orders\GetBasketSummaryQueryOutput;
|
||||
use App\Queries\Orders\GetOrderConfirmationQueryOutput;
|
||||
use App\Queries\Orders\GetPickTimeSlotQueryOutput;
|
||||
use Database\Seeders\ContentSeeder;
|
||||
use Domain\Builders\OrderBuilderCompleted;
|
||||
use Domain\Enums\OrderStatus;
|
||||
use Domain\Enums\OrderTunnelStep;
|
||||
use Domain\Exceptions\OrderTunnel\WeeklyLimitExceededException;
|
||||
use Domain\Models\Entities\Basket;
|
||||
use Domain\Models\Entities\Shopper;
|
||||
use Domain\Models\ValueObjects\DeliveryAddress;
|
||||
use Domain\Models\ValueObjects\Email;
|
||||
use Domain\Models\ValueObjects\Entities\BasketId;
|
||||
use Domain\Models\ValueObjects\Matricule;
|
||||
use Domain\Models\ValueObjects\OrderEmployee;
|
||||
use Domain\Models\ValueObjects\OrderReference;
|
||||
use Domain\Models\ValueObjects\PickupTimeSlot;
|
||||
use Domain\Ports\Repositories\ShopperRepository;
|
||||
use Domain\Services\OrderTunnelService;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Money\Money;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Shared\ValueObjects\CrmHashcode;
|
||||
|
||||
describe('TunnelController', function (): void {
|
||||
it('redirects unauthenticated guest accessing basket summary to login', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
|
|
@ -25,6 +55,7 @@ describe('TunnelController', function (): void {
|
|||
});
|
||||
|
||||
it('redirects unauthenticated guest submitting basket summary to login', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
|
|
@ -41,6 +72,7 @@ describe('TunnelController', function (): void {
|
|||
});
|
||||
|
||||
it('redirects unauthenticated guest accessing pick time slot to login', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
|
|
@ -57,6 +89,7 @@ describe('TunnelController', function (): void {
|
|||
});
|
||||
|
||||
it('redirects unauthenticated guest submitting pick time slot to login', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
|
|
@ -73,6 +106,7 @@ describe('TunnelController', function (): void {
|
|||
});
|
||||
|
||||
it('redirects unauthenticated guest accessing confirmation to login', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
|
|
@ -89,6 +123,7 @@ describe('TunnelController', function (): void {
|
|||
});
|
||||
|
||||
it('redirects unauthenticated guest submitting confirmation to login', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
|
|
@ -105,6 +140,7 @@ describe('TunnelController', function (): void {
|
|||
});
|
||||
|
||||
it('redirects unauthenticated guest accessing confirmed order to login', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
|
|
@ -119,4 +155,452 @@ describe('TunnelController', function (): void {
|
|||
// THEN
|
||||
$response->assertRedirectToRoute('fo.auth.connexion');
|
||||
});
|
||||
|
||||
it('displays basket summary when customer is authorized', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
->mapWithKeys(fn ($page) => [
|
||||
$page->slug->value() => $page,
|
||||
]));
|
||||
Cache::flush();
|
||||
|
||||
$customer = new Customer();
|
||||
$customer->email = new Email('test@example.com');
|
||||
$customer->hashcode = new CrmHashcode(Uuid::uuid4());
|
||||
$customer->save();
|
||||
$this->actingAs($customer, 'frontend');
|
||||
|
||||
$this->withoutMiddleware([
|
||||
CustomerIsEmployed::class,
|
||||
EnsureCustomerEmailIsVerified::class,
|
||||
]);
|
||||
Gate::before(fn () => true);
|
||||
|
||||
$basket = new Basket(new BasketId(Uuid::uuid7()));
|
||||
$this->mock(Executor::class, function ($mock) use ($basket): void {
|
||||
$mock->shouldReceive('execute')
|
||||
->once()
|
||||
->andReturn(new GetBasketSummaryQueryOutput(
|
||||
step: OrderTunnelStep::REVIEW,
|
||||
basket: $basket,
|
||||
));
|
||||
});
|
||||
|
||||
// WHEN
|
||||
$response = $this->get('/commande/panier');
|
||||
|
||||
// THEN
|
||||
$response->assertOk()
|
||||
->assertViewIs('fo.tunnel.basket-summary')
|
||||
->assertViewHas('step', OrderTunnelStep::REVIEW)
|
||||
->assertViewHas('basket', $basket);
|
||||
});
|
||||
|
||||
it('submits basket summary and redirects to pick time slot', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
->mapWithKeys(fn ($page) => [
|
||||
$page->slug->value() => $page,
|
||||
]));
|
||||
Cache::flush();
|
||||
|
||||
$customer = new Customer();
|
||||
$customer->email = new Email('test@example.com');
|
||||
$customer->hashcode = new CrmHashcode(Uuid::uuid4());
|
||||
$customer->save();
|
||||
$this->actingAs($customer, 'frontend');
|
||||
|
||||
$this->withoutMiddleware([
|
||||
CustomerIsEmployed::class,
|
||||
EnsureCustomerEmailIsVerified::class,
|
||||
]);
|
||||
Gate::before(fn () => true);
|
||||
|
||||
$this->mock(Executor::class, function ($mock): void {
|
||||
$mock->shouldReceive('execute')
|
||||
->once();
|
||||
});
|
||||
|
||||
// WHEN
|
||||
$response = $this->post('/commande/panier', []);
|
||||
|
||||
// THEN
|
||||
$response->assertRedirectToRoute('fo.sales.pick-time-slot');
|
||||
});
|
||||
|
||||
it('displays pick time slot when customer is authorized', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
->mapWithKeys(fn ($page) => [
|
||||
$page->slug->value() => $page,
|
||||
]));
|
||||
Cache::flush();
|
||||
|
||||
$customer = new Customer();
|
||||
$customer->email = new Email('test@example.com');
|
||||
$customer->hashcode = new CrmHashcode(Uuid::uuid4());
|
||||
$customer->save();
|
||||
$this->actingAs($customer, 'frontend');
|
||||
|
||||
$this->withoutMiddleware([
|
||||
CustomerIsEmployed::class,
|
||||
EnsureCustomerEmailIsVerified::class,
|
||||
]);
|
||||
Gate::before(fn () => true);
|
||||
|
||||
$shopDto = new ShopDto(
|
||||
id: 'test-shop',
|
||||
name: 'Test Shop',
|
||||
address: '1 rue Test',
|
||||
postcode: '75001',
|
||||
city: 'Paris',
|
||||
phone: null,
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
default: true,
|
||||
);
|
||||
|
||||
$this->mock(Executor::class, function ($mock) use ($shopDto): void {
|
||||
$mock->shouldReceive('execute')
|
||||
->once()
|
||||
->andReturn(new GetPickTimeSlotQueryOutput(
|
||||
step: OrderTunnelStep::BOOKING,
|
||||
shop: $shopDto,
|
||||
timeSlots: [],
|
||||
mapUrl: 'https://maps.example.com',
|
||||
));
|
||||
});
|
||||
|
||||
// WHEN
|
||||
$response = $this->get('/commande/creneaux');
|
||||
|
||||
// THEN
|
||||
$response->assertOk()
|
||||
->assertViewIs('fo.tunnel.pick-time-slot')
|
||||
->assertViewHas('step', OrderTunnelStep::BOOKING)
|
||||
->assertViewHas('shop', $shopDto)
|
||||
->assertViewHas('mapUrl', 'https://maps.example.com');
|
||||
});
|
||||
|
||||
it('submits pick time slot and redirects to confirmation when slot is valid', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
->mapWithKeys(fn ($page) => [
|
||||
$page->slug->value() => $page,
|
||||
]));
|
||||
Cache::flush();
|
||||
|
||||
$customer = new Customer();
|
||||
$customer->email = new Email('test@example.com');
|
||||
$customer->hashcode = new CrmHashcode(Uuid::uuid4());
|
||||
$customer->save();
|
||||
$this->actingAs($customer, 'frontend');
|
||||
|
||||
$this->withoutMiddleware([
|
||||
CustomerIsEmployed::class,
|
||||
EnsureCustomerEmailIsVerified::class,
|
||||
]);
|
||||
Gate::before(fn () => true);
|
||||
|
||||
$shopper = new Shopper(
|
||||
id: $customer->getId(),
|
||||
email: new Email('test@example.com'),
|
||||
matricule: new Matricule('1234567'),
|
||||
nom: 'Dupont',
|
||||
prenom: 'Jean',
|
||||
startDate: now()->subMonth(),
|
||||
endDate: null,
|
||||
etablissement: 'Fac',
|
||||
site: 'Site',
|
||||
service: 'Service',
|
||||
);
|
||||
$this->mock(ShopperRepository::class, function ($mock) use ($shopper): void {
|
||||
$mock->shouldReceive('getByIdOrFail')->andReturn($shopper);
|
||||
});
|
||||
$this->mock(OrderTunnelService::class, function ($mock): void {
|
||||
$mock->shouldReceive('assertBasketWeeklyAmountWithinLimitFor');
|
||||
});
|
||||
|
||||
$slot = new PickupTimeSlot(now(), new \DateInterval('PT1H'));
|
||||
$this->mock(Executor::class, function ($mock) use ($slot): void {
|
||||
$mock->shouldReceive('execute')
|
||||
->once()
|
||||
->andReturn($slot);
|
||||
});
|
||||
|
||||
// WHEN
|
||||
$response = $this->post('/commande/creneaux', [
|
||||
'timeslot' => now()->format('Y-m-d'),
|
||||
]);
|
||||
|
||||
// THEN
|
||||
$response->assertRedirectToRoute('fo.sales.confirmation');
|
||||
});
|
||||
|
||||
it('submits pick time slot and redirects back with error when slot is invalid', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
->mapWithKeys(fn ($page) => [
|
||||
$page->slug->value() => $page,
|
||||
]));
|
||||
Cache::flush();
|
||||
|
||||
$customer = new Customer();
|
||||
$customer->email = new Email('test@example.com');
|
||||
$customer->hashcode = new CrmHashcode(Uuid::uuid4());
|
||||
$customer->save();
|
||||
$this->actingAs($customer, 'frontend');
|
||||
|
||||
$this->withoutMiddleware([
|
||||
CustomerIsEmployed::class,
|
||||
EnsureCustomerEmailIsVerified::class,
|
||||
]);
|
||||
Gate::before(fn () => true);
|
||||
|
||||
$shopper = new Shopper(
|
||||
id: $customer->getId(),
|
||||
email: new Email('test@example.com'),
|
||||
matricule: new Matricule('1234567'),
|
||||
nom: 'Dupont',
|
||||
prenom: 'Jean',
|
||||
startDate: now()->subMonth(),
|
||||
endDate: null,
|
||||
etablissement: 'Fac',
|
||||
site: 'Site',
|
||||
service: 'Service',
|
||||
);
|
||||
$this->mock(ShopperRepository::class, function ($mock) use ($shopper): void {
|
||||
$mock->shouldReceive('getByIdOrFail')->andReturn($shopper);
|
||||
});
|
||||
$this->mock(OrderTunnelService::class, function ($mock): void {
|
||||
$mock->shouldReceive('assertBasketWeeklyAmountWithinLimitFor');
|
||||
});
|
||||
|
||||
$this->mock(Executor::class, function ($mock): void {
|
||||
$mock->shouldReceive('execute')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
});
|
||||
|
||||
// WHEN
|
||||
$response = $this->from('/commande/creneaux')->post('/commande/creneaux', [
|
||||
'timeslot' => now()->format('Y-m-d'),
|
||||
]);
|
||||
|
||||
// THEN
|
||||
$response->assertRedirect('/commande/creneaux')
|
||||
->assertSessionHasErrors('timeslot');
|
||||
});
|
||||
|
||||
it('displays order confirmation when customer is authorized', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
->mapWithKeys(fn ($page) => [
|
||||
$page->slug->value() => $page,
|
||||
]));
|
||||
Cache::flush();
|
||||
|
||||
$customer = new Customer();
|
||||
$customer->email = new Email('test@example.com');
|
||||
$customer->hashcode = new CrmHashcode(Uuid::uuid4());
|
||||
$customer->save();
|
||||
$this->actingAs($customer, 'frontend');
|
||||
|
||||
$this->withoutMiddleware([
|
||||
CustomerIsEmployed::class,
|
||||
EnsureCustomerEmailIsVerified::class,
|
||||
]);
|
||||
Gate::before(fn () => true);
|
||||
|
||||
$basket = new Basket(new BasketId(Uuid::uuid7()));
|
||||
$builder = \Mockery::mock(OrderBuilderCompleted::class);
|
||||
$slot = new PickupTimeSlot(now(), new \DateInterval('PT1H'));
|
||||
$builder->shouldReceive('getPickupTimeSlot')->andReturn($slot);
|
||||
|
||||
$shopDto = new ShopDto(
|
||||
id: 'test-shop',
|
||||
name: 'Test Shop',
|
||||
address: '1 rue Test',
|
||||
postcode: '75001',
|
||||
city: 'Paris',
|
||||
phone: null,
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
default: true,
|
||||
);
|
||||
|
||||
$this->mock(Executor::class, function ($mock) use ($basket, $builder, $shopDto): void {
|
||||
$mock->shouldReceive('execute')
|
||||
->once()
|
||||
->andReturn(new GetOrderConfirmationQueryOutput(
|
||||
step: OrderTunnelStep::CONFIRMATION,
|
||||
basket: $basket,
|
||||
builder: $builder,
|
||||
shop: $shopDto,
|
||||
));
|
||||
});
|
||||
|
||||
// WHEN
|
||||
$response = $this->get('/commande/confirmation');
|
||||
|
||||
// THEN
|
||||
$response->assertOk()
|
||||
->assertViewIs('fo.tunnel.confirmation')
|
||||
->assertViewHas('step', OrderTunnelStep::CONFIRMATION)
|
||||
->assertViewHas('basket', $basket)
|
||||
->assertViewHas('shop', $shopDto);
|
||||
});
|
||||
|
||||
it('submits confirmation and redirects to confirmed view when cgv accepted', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
->mapWithKeys(fn ($page) => [
|
||||
$page->slug->value() => $page,
|
||||
]));
|
||||
Cache::flush();
|
||||
|
||||
$customer = new Customer();
|
||||
$customer->email = new Email('test@example.com');
|
||||
$customer->hashcode = new CrmHashcode(Uuid::uuid4());
|
||||
$customer->save();
|
||||
$this->actingAs($customer, 'frontend');
|
||||
|
||||
$this->withoutMiddleware([
|
||||
CustomerIsEmployed::class,
|
||||
EnsureCustomerEmailIsVerified::class,
|
||||
]);
|
||||
Gate::before(fn () => true);
|
||||
|
||||
$orderReference = new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58());
|
||||
$this->mock(Executor::class, function ($mock) use ($orderReference): void {
|
||||
$mock->shouldReceive('execute')
|
||||
->once()
|
||||
->andReturn($orderReference);
|
||||
});
|
||||
|
||||
// WHEN
|
||||
$response = $this->post('/commande/confirmation', [
|
||||
'ok_cgv' => '1',
|
||||
]);
|
||||
|
||||
// THEN
|
||||
$response->assertRedirectToRoute('fo.sales.confirmation.show-confirmed', $orderReference->value);
|
||||
});
|
||||
|
||||
it('redirects back with message when limit exception occurs on confirmation submit', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
->mapWithKeys(fn ($page) => [
|
||||
$page->slug->value() => $page,
|
||||
]));
|
||||
Cache::flush();
|
||||
|
||||
$customer = new Customer();
|
||||
$customer->email = new Email('test@example.com');
|
||||
$customer->hashcode = new CrmHashcode(Uuid::uuid4());
|
||||
$customer->save();
|
||||
$this->actingAs($customer, 'frontend');
|
||||
|
||||
$this->withoutMiddleware([
|
||||
CustomerIsEmployed::class,
|
||||
EnsureCustomerEmailIsVerified::class,
|
||||
]);
|
||||
Gate::before(fn () => true);
|
||||
|
||||
$this->mock(Executor::class, function ($mock): void {
|
||||
$mock->shouldReceive('execute')
|
||||
->once()
|
||||
->andThrow(new WeeklyLimitExceededException());
|
||||
});
|
||||
|
||||
// WHEN
|
||||
$response = $this->from('/commande/confirmation')->post('/commande/confirmation', [
|
||||
'ok_cgv' => '1',
|
||||
]);
|
||||
|
||||
// THEN
|
||||
$response->assertRedirect('/commande/confirmation')
|
||||
->assertSessionHas('message');
|
||||
});
|
||||
|
||||
it('displays confirmed order view when customer is authorized', function (): void {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$this->seed(ContentSeeder::class);
|
||||
View::share('PageList', Page::getCached()
|
||||
->mapWithKeys(fn ($page) => [
|
||||
$page->slug->value() => $page,
|
||||
]));
|
||||
Cache::flush();
|
||||
|
||||
$customer = new Customer();
|
||||
$customer->email = new Email('test@example.com');
|
||||
$customer->hashcode = new CrmHashcode(Uuid::uuid4());
|
||||
$customer->save();
|
||||
$this->actingAs($customer, 'frontend');
|
||||
|
||||
$this->withoutMiddleware([
|
||||
CustomerIsEmployed::class,
|
||||
EnsureCustomerEmailIsVerified::class,
|
||||
]);
|
||||
Gate::before(fn () => true);
|
||||
|
||||
$shop = new Shop();
|
||||
$shop->name = 'Boutique Test';
|
||||
$shop->address = '1 rue Test';
|
||||
$shop->postcode = '75001';
|
||||
$shop->city = 'Paris';
|
||||
$shop->default = true;
|
||||
$shop->save();
|
||||
|
||||
$orderReference = new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58());
|
||||
$order = new Order();
|
||||
$order->reference = $orderReference;
|
||||
$order->total = Money::EUR(3000);
|
||||
$order->status = OrderStatus::WAITING;
|
||||
$order->pickup_day = now()->addDays(2);
|
||||
$order->shop_id = $shop->id;
|
||||
$order->employee = new OrderEmployee(
|
||||
firstname: 'Jean',
|
||||
lastname: 'Dupont',
|
||||
matricule: new Matricule('1234567'),
|
||||
facility: 'Fac',
|
||||
site: 'Site',
|
||||
service: 'Service',
|
||||
);
|
||||
$order->delivery_address = new DeliveryAddress(
|
||||
name: $shop->name,
|
||||
address: $shop->address,
|
||||
postcode: $shop->postcode,
|
||||
city: $shop->city,
|
||||
);
|
||||
$order->save();
|
||||
|
||||
// WHEN
|
||||
$response = $this->get('/commande/confirmation/' . $orderReference->value);
|
||||
|
||||
// THEN
|
||||
$response->assertOk()
|
||||
->assertViewIs('fo.tunnel.confirmed')
|
||||
->assertViewHas('step', OrderTunnelStep::CONFIRMATION)
|
||||
->assertViewHas('order')
|
||||
->assertViewHas('shop')
|
||||
->assertViewHas('mapUrl');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Actions\Orders\FinalizeOrderInput;
|
||||
use App\Http\Requests\Fo\Orders\ConfirmOrderRequest;
|
||||
use App\Models\Customer;
|
||||
use Domain\Models\ValueObjects\Entities\ShopperId;
|
||||
use Infrastructure\Adapters\Services\AppCustomerAuthService;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
describe('ConfirmOrderRequest', function () {
|
||||
it('authorizes when user is logged in', function () {
|
||||
// GIVEN
|
||||
$authService = \Mockery::mock(AppCustomerAuthService::class);
|
||||
$authService->shouldReceive('check')->once()->andReturn(true);
|
||||
|
||||
$request = new ConfirmOrderRequest($authService);
|
||||
|
||||
// WHEN
|
||||
$request->initialize();
|
||||
|
||||
// THEN
|
||||
expect($request->authorize())->toBeTrue();
|
||||
});
|
||||
|
||||
it('does not authorize when user is not logged in', function () {
|
||||
// GIVEN
|
||||
$authService = \Mockery::mock(AppCustomerAuthService::class);
|
||||
$authService->shouldReceive('check')->once()->andReturn(false);
|
||||
|
||||
$request = new ConfirmOrderRequest($authService);
|
||||
|
||||
// WHEN
|
||||
$request->initialize();
|
||||
|
||||
// THEN
|
||||
expect($request->authorize())->toBeFalse();
|
||||
});
|
||||
|
||||
it('has required rules for cgv acceptance', function () {
|
||||
// GIVEN
|
||||
$authService = \Mockery::mock(AppCustomerAuthService::class);
|
||||
$request = new ConfirmOrderRequest($authService);
|
||||
|
||||
// WHEN
|
||||
$rules = $request->rules();
|
||||
|
||||
// THEN
|
||||
expect($rules)->toHaveKey('ok_cgv')
|
||||
->and($rules['ok_cgv'])->toContain('accepted');
|
||||
});
|
||||
|
||||
it('maps to FinalizeOrderInput', function () {
|
||||
// GIVEN
|
||||
$shopperId = new ShopperId(Uuid::uuid7());
|
||||
$customer = \Mockery::mock(Customer::class);
|
||||
$customer->shouldReceive('getId')->once()->andReturn($shopperId);
|
||||
|
||||
$authService = \Mockery::mock(AppCustomerAuthService::class);
|
||||
$authService->shouldReceive('getCustomerAsMandatory')->once()->andReturn($customer);
|
||||
|
||||
$request = new ConfirmOrderRequest($authService);
|
||||
$request->initialize();
|
||||
|
||||
// WHEN
|
||||
$input = $request->toFinalizeOrderInput();
|
||||
|
||||
// THEN
|
||||
expect($input)->toBeInstanceOf(FinalizeOrderInput::class)
|
||||
->and($input->shopperId)->toBe($shopperId);
|
||||
});
|
||||
});
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Actions\Orders\ApplyPickTimeSlotInput;
|
||||
use App\Http\Requests\Fo\Orders\PickTimeSlotRequest;
|
||||
use App\Models\Customer;
|
||||
use Carbon\CarbonInterface;
|
||||
|
|
@ -193,4 +194,31 @@ describe('PickTimeSlotRequest', function () {
|
|||
->and($failMessages[0])
|
||||
->toBe(trans('You will reach the maximum weekly order limit with this basket.'));
|
||||
});
|
||||
|
||||
it('maps to ApplyPickTimeSlotInput', function () {
|
||||
// GIVEN
|
||||
$shopperId = new ShopperId(Uuid::uuid7());
|
||||
$customer = \Mockery::mock(Customer::class);
|
||||
$customer->shouldReceive('getId')->once()->andReturn($shopperId);
|
||||
|
||||
$authService = \Mockery::mock(AppCustomerAuthService::class);
|
||||
$authService->shouldReceive('getCustomerAsMandatory')->once()->andReturn($customer);
|
||||
|
||||
$request = new PickTimeSlotRequest(
|
||||
$authService,
|
||||
\Mockery::mock(BasketService::class),
|
||||
\Mockery::mock(ShopperRepository::class),
|
||||
\Mockery::mock(OrderTunnelService::class),
|
||||
);
|
||||
$request->initialize();
|
||||
$request->merge(['timeslot' => VALID_TIMESLOT_DATE]);
|
||||
|
||||
// WHEN
|
||||
$input = $request->toApplyPickTimeSlotInput();
|
||||
|
||||
// THEN
|
||||
expect($input)->toBeInstanceOf(ApplyPickTimeSlotInput::class)
|
||||
->and($input->shopperId)->toBe($shopperId)
|
||||
->and($input->timeslot->format('Y-m-d'))->toBe(VALID_TIMESLOT_DATE);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,10 +2,13 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Actions\Orders\InitializeOrderTunnelInput;
|
||||
use App\Http\Requests\Fo\Orders\ValidateSummaryRequest;
|
||||
use App\Models\Customer;
|
||||
use Domain\Exceptions\OrderTunnel\OrderLimitExceededException;
|
||||
use Domain\Models\Entities\Basket;
|
||||
use Domain\Models\ValueObjects\Entities\BasketId;
|
||||
use Domain\Models\ValueObjects\Entities\ShopperId;
|
||||
use Domain\Services\BasketService;
|
||||
use Domain\Services\OrderTunnelService;
|
||||
use Infrastructure\Adapters\Services\AppCustomerAuthService;
|
||||
|
|
@ -82,4 +85,33 @@ describe('ValidateSummaryRequest', function () {
|
|||
expect($failMessages)->toHaveCount(1)
|
||||
->and($failMessages[0])->toBe(trans('You have reached the maximum order limit for this basket.'));
|
||||
});
|
||||
|
||||
it('maps to InitializeOrderTunnelInput', function () {
|
||||
// GIVEN
|
||||
$shopperId = new ShopperId(Uuid::uuid7());
|
||||
$customer = \Mockery::mock(Customer::class);
|
||||
$customer->shouldReceive('getId')->once()->andReturn($shopperId);
|
||||
|
||||
$basket = new Basket(new BasketId(Uuid::uuid7()), []);
|
||||
$authService = \Mockery::mock(AppCustomerAuthService::class);
|
||||
$authService->shouldReceive('getCustomerAsMandatory')->once()->andReturn($customer);
|
||||
|
||||
$basketService = \Mockery::mock(BasketService::class);
|
||||
$basketService->shouldReceive('getBasket')->once()->andReturn($basket);
|
||||
|
||||
$request = new ValidateSummaryRequest(
|
||||
$authService,
|
||||
$basketService,
|
||||
\Mockery::mock(OrderTunnelService::class),
|
||||
);
|
||||
$request->initialize();
|
||||
|
||||
// WHEN
|
||||
$input = $request->toInitializeOrderTunnelInput();
|
||||
|
||||
// THEN
|
||||
expect($input)->toBeInstanceOf(InitializeOrderTunnelInput::class)
|
||||
->and($input->basket)->toBe($basket)
|
||||
->and($input->shopperId)->toBe($shopperId);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Integration\WithApp\App\Queries\Orders;
|
||||
|
||||
use App\Dto\OrderDto;
|
||||
use App\Dto\ShopDto;
|
||||
use App\Models\Order;
|
||||
use App\Models\Shop;
|
||||
use App\Queries\Orders\GetTunnelOrderConfirmedQuery;
|
||||
use App\Queries\Orders\GetTunnelOrderConfirmedQueryInput;
|
||||
use App\Queries\Orders\GetTunnelOrderConfirmedQueryOutput;
|
||||
use Domain\Enums\OrderStatus;
|
||||
use Domain\Enums\OrderTunnelStep;
|
||||
use Domain\Models\ValueObjects\DeliveryAddress;
|
||||
use Domain\Models\ValueObjects\Matricule;
|
||||
use Domain\Models\ValueObjects\OrderEmployee;
|
||||
use Domain\Models\ValueObjects\OrderReference;
|
||||
use Money\Money;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
use UnexpectedValueException;
|
||||
|
||||
describe('GetTunnelOrderConfirmedQuery', function (): void {
|
||||
it('returns order confirmed output with step, orderDto, shopDto and mapUrl', function (): void {
|
||||
// GIVEN
|
||||
$shop = new Shop();
|
||||
$shop->name = 'Boutique Retrait';
|
||||
$shop->address = '10 rue Principale';
|
||||
$shop->postcode = '75001';
|
||||
$shop->city = 'Paris';
|
||||
$shop->default = true;
|
||||
$shop->save();
|
||||
|
||||
$reference = new OrderReference(Uuid::v7()->toBase58());
|
||||
|
||||
$order = new Order();
|
||||
$order->reference = $reference;
|
||||
$order->total = Money::EUR(2500);
|
||||
$order->status = OrderStatus::WAITING;
|
||||
$order->pickup_day = now()->addDays(2);
|
||||
$order->shop_id = $shop->id;
|
||||
$order->delivery_address = new DeliveryAddress(
|
||||
name: $shop->name,
|
||||
address: $shop->address,
|
||||
postcode: $shop->postcode,
|
||||
city: $shop->city,
|
||||
);
|
||||
$order->employee = new OrderEmployee(
|
||||
firstname: 'Jean',
|
||||
lastname: 'Dupont',
|
||||
matricule: new Matricule('1234567'),
|
||||
facility: 'Fac',
|
||||
site: 'Site',
|
||||
service: 'Service',
|
||||
);
|
||||
$order->save();
|
||||
|
||||
/** @var GetTunnelOrderConfirmedQuery $query */
|
||||
$query = app(GetTunnelOrderConfirmedQuery::class);
|
||||
$input = new GetTunnelOrderConfirmedQueryInput($order);
|
||||
|
||||
// WHEN
|
||||
$output = $query($input);
|
||||
|
||||
// THEN
|
||||
expect($output)->toBeInstanceOf(GetTunnelOrderConfirmedQueryOutput::class)
|
||||
->and($output->step)->toBe(OrderTunnelStep::CONFIRMATION)
|
||||
->and($output->order)->toBeInstanceOf(OrderDto::class)
|
||||
->and((string) $output->order->reference)->toBe($reference->value)
|
||||
->and($output->shop)->toBeInstanceOf(ShopDto::class)
|
||||
->and($output->shop->name)->toBe('Boutique Retrait')
|
||||
->and($output->mapUrl)->toBeString();
|
||||
});
|
||||
|
||||
it('throws UnexpectedValueException when order has no shop', function (): void {
|
||||
// GIVEN
|
||||
$reference = new OrderReference(Uuid::v7()->toBase58());
|
||||
|
||||
$order = new Order();
|
||||
$order->reference = $reference;
|
||||
$order->total = Money::EUR(2500);
|
||||
$order->status = OrderStatus::WAITING;
|
||||
$order->pickup_day = now()->addDays(2);
|
||||
$order->shop_id = null;
|
||||
$order->employee = new OrderEmployee(
|
||||
firstname: 'Jean',
|
||||
lastname: 'Dupont',
|
||||
matricule: new Matricule('1234567'),
|
||||
facility: 'Fac',
|
||||
site: 'Site',
|
||||
service: 'Service',
|
||||
);
|
||||
$order->delivery_address = new DeliveryAddress(
|
||||
name: 'Nom',
|
||||
address: '1 rue Test',
|
||||
postcode: '75001',
|
||||
city: 'Paris',
|
||||
);
|
||||
$order->save();
|
||||
|
||||
/** @var GetTunnelOrderConfirmedQuery $query */
|
||||
$query = app(GetTunnelOrderConfirmedQuery::class);
|
||||
$input = new GetTunnelOrderConfirmedQueryInput($order);
|
||||
|
||||
// WHEN & THEN
|
||||
expect(fn () => $query($input))->toThrow(UnexpectedValueException::class);
|
||||
});
|
||||
});
|
||||
26
tests/Unit/App/Actions/Orders/ApplyPickTimeSlotInputTest.php
Normal file
26
tests/Unit/App/Actions/Orders/ApplyPickTimeSlotInputTest.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Actions\Orders\ApplyPickTimeSlotInput;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Domain\Models\ValueObjects\Entities\ShopperId;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
describe('ApplyPickTimeSlotInput', function (): void {
|
||||
it('can be instantiated with valid data', function (): void {
|
||||
// GIVEN
|
||||
$shopperId = new ShopperId(Uuid::uuid7());
|
||||
$timeslot = CarbonImmutable::parse('2026-10-15');
|
||||
|
||||
// WHEN
|
||||
$input = new ApplyPickTimeSlotInput(
|
||||
shopperId: $shopperId,
|
||||
timeslot: $timeslot,
|
||||
);
|
||||
|
||||
// THEN
|
||||
expect($input->shopperId)->toBe($shopperId)
|
||||
->and($input->timeslot)->toBe($timeslot);
|
||||
});
|
||||
});
|
||||
62
tests/Unit/App/Actions/Orders/ApplyPickTimeSlotTest.php
Normal file
62
tests/Unit/App/Actions/Orders/ApplyPickTimeSlotTest.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?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);
|
||||
});
|
||||
});
|
||||
28
tests/Unit/App/Actions/Orders/FinalizeOrderInputTest.php
Normal file
28
tests/Unit/App/Actions/Orders/FinalizeOrderInputTest.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Actions\Orders\FinalizeOrderInput;
|
||||
use Domain\Models\ValueObjects\Entities\ShopperId;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
describe('FinalizeOrderInput', function (): void {
|
||||
it('can be instantiated with null shopperId', function (): void {
|
||||
// GIVEN & WHEN
|
||||
$input = new FinalizeOrderInput();
|
||||
|
||||
// THEN
|
||||
expect($input->shopperId)->toBeNull();
|
||||
});
|
||||
|
||||
it('can be instantiated with valid shopperId', function (): void {
|
||||
// GIVEN
|
||||
$shopperId = new ShopperId(Uuid::uuid7());
|
||||
|
||||
// WHEN
|
||||
$input = new FinalizeOrderInput(shopperId: $shopperId);
|
||||
|
||||
// THEN
|
||||
expect($input->shopperId)->toBe($shopperId);
|
||||
});
|
||||
});
|
||||
70
tests/Unit/App/Actions/Orders/FinalizeOrderTest.php
Normal file
70
tests/Unit/App/Actions/Orders/FinalizeOrderTest.php
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Actions\Orders\FinalizeOrder;
|
||||
use App\Actions\Orders\FinalizeOrderInput;
|
||||
use Domain\Builders\OrderBuilderCompleted;
|
||||
use Domain\Enums\OrderStatus;
|
||||
use Domain\Models\Entities\Order;
|
||||
use Domain\Models\ValueObjects\DeliveryAddress;
|
||||
use Domain\Models\ValueObjects\Entities\OrderId;
|
||||
use Domain\Models\ValueObjects\Entities\ShopId;
|
||||
use Domain\Models\ValueObjects\Matricule;
|
||||
use Domain\Models\ValueObjects\OrderEmployee;
|
||||
use Domain\Models\ValueObjects\OrderReference;
|
||||
use Domain\Models\ValueObjects\PickupTimeSlot;
|
||||
use Domain\Services\OrderTunnelService;
|
||||
use Money\Money;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
describe('FinalizeOrder', function (): void {
|
||||
it('finalizes order and returns reference via OrderTunnelService', function (): void {
|
||||
// GIVEN
|
||||
$input = new FinalizeOrderInput();
|
||||
|
||||
$orderReference = new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58());
|
||||
$builder = \Mockery::mock(OrderBuilderCompleted::class);
|
||||
$order = new Order(
|
||||
id: new OrderId(Uuid::uuid7()),
|
||||
shopId: new ShopId(Uuid::uuid7()),
|
||||
reference: $orderReference,
|
||||
employee: new OrderEmployee(
|
||||
firstname: 'Jean',
|
||||
lastname: 'Dupont',
|
||||
matricule: new Matricule('1234567'),
|
||||
facility: 'Fac',
|
||||
site: 'Site',
|
||||
service: 'Service',
|
||||
),
|
||||
deliveryAddress: new DeliveryAddress(
|
||||
name: 'Shop',
|
||||
address: '1 rue Test',
|
||||
postcode: '75001',
|
||||
city: 'Paris',
|
||||
),
|
||||
pickupTimeSlot: new PickupTimeSlot(now(), new \DateInterval('PT1H')),
|
||||
status: OrderStatus::WAITING,
|
||||
total: Money::EUR(1000),
|
||||
lines: [],
|
||||
);
|
||||
|
||||
$orderTunnelService = \Mockery::mock(OrderTunnelService::class);
|
||||
$orderTunnelService->shouldReceive('getBuilderCompletedOrFail')
|
||||
->once()
|
||||
->andReturn($builder);
|
||||
$orderTunnelService->shouldReceive('finalizeOrder')
|
||||
->once()
|
||||
->with($builder)
|
||||
->andReturn($order);
|
||||
|
||||
$action = new FinalizeOrder($orderTunnelService);
|
||||
|
||||
// WHEN
|
||||
$result = $action($input);
|
||||
|
||||
// THEN
|
||||
expect($result)->toBeInstanceOf(OrderReference::class)
|
||||
->and($result->value)->toBe($orderReference->value);
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Actions\Orders\InitializeOrderTunnelInput;
|
||||
use Domain\Models\Entities\Basket;
|
||||
use Domain\Models\ValueObjects\Entities\BasketId;
|
||||
use Domain\Models\ValueObjects\Entities\ShopperId;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
describe('InitializeOrderTunnelInput', function (): void {
|
||||
it('can be instantiated with valid data', function (): void {
|
||||
// GIVEN
|
||||
$basket = new Basket(new BasketId(Uuid::uuid7()));
|
||||
$shopperId = new ShopperId(Uuid::uuid7());
|
||||
|
||||
// WHEN
|
||||
$input = new InitializeOrderTunnelInput(
|
||||
basket: $basket,
|
||||
shopperId: $shopperId,
|
||||
);
|
||||
|
||||
// THEN
|
||||
expect($input->basket)->toBe($basket)
|
||||
->and($input->shopperId)->toBe($shopperId);
|
||||
});
|
||||
});
|
||||
36
tests/Unit/App/Actions/Orders/InitializeOrderTunnelTest.php
Normal file
36
tests/Unit/App/Actions/Orders/InitializeOrderTunnelTest.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Actions\Orders\InitializeOrderTunnel;
|
||||
use App\Actions\Orders\InitializeOrderTunnelInput;
|
||||
use Domain\Models\Entities\Basket;
|
||||
use Domain\Models\ValueObjects\Entities\BasketId;
|
||||
use Domain\Models\ValueObjects\Entities\ShopperId;
|
||||
use Domain\Services\OrderTunnelService;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
describe('InitializeOrderTunnel', function (): void {
|
||||
it('initializes the tunnel from basket via OrderTunnelService', function (): void {
|
||||
// GIVEN
|
||||
$basket = new Basket(new BasketId(Uuid::uuid7()));
|
||||
$shopperId = new ShopperId(Uuid::uuid7());
|
||||
$input = new InitializeOrderTunnelInput(
|
||||
basket: $basket,
|
||||
shopperId: $shopperId,
|
||||
);
|
||||
|
||||
$orderTunnelService = \Mockery::mock(OrderTunnelService::class);
|
||||
$orderTunnelService->shouldReceive('initializeFromBasket')
|
||||
->once()
|
||||
->with($basket, $shopperId);
|
||||
|
||||
$action = new InitializeOrderTunnel($orderTunnelService);
|
||||
|
||||
// WHEN
|
||||
$action($input);
|
||||
|
||||
// THEN
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
});
|
||||
|
|
@ -3,6 +3,9 @@
|
|||
declare(strict_types=1);
|
||||
|
||||
use App\Dto\ShopDto;
|
||||
use Domain\Models\Entities\Shop;
|
||||
use Domain\Models\ValueObjects\Entities\ShopId;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
describe('ShopDto', function () {
|
||||
test('it can be instantiated directly and converts to array', function () {
|
||||
|
|
@ -37,4 +40,35 @@ describe('ShopDto', function () {
|
|||
'default' => true,
|
||||
]);
|
||||
});
|
||||
|
||||
test('it can be created from domain Shop entity', function () {
|
||||
// GIVEN
|
||||
$uuid = Uuid::uuid7();
|
||||
$shopId = new ShopId($uuid);
|
||||
$domainShop = new Shop(
|
||||
id: $shopId,
|
||||
name: 'Boutique Domain',
|
||||
address: '10 avenue de la Gare',
|
||||
postcode: '69001',
|
||||
city: 'Lyon',
|
||||
phone: '0478000000',
|
||||
latitude: '45.75',
|
||||
longitude: '4.85',
|
||||
isDefault: true,
|
||||
);
|
||||
|
||||
// WHEN
|
||||
$dto = ShopDto::fromDomain($domainShop);
|
||||
|
||||
// THEN
|
||||
expect($dto->id)->toBe($uuid->toString())
|
||||
->and($dto->name)->toBe('Boutique Domain')
|
||||
->and($dto->address)->toBe('10 avenue de la Gare')
|
||||
->and($dto->postcode)->toBe('69001')
|
||||
->and($dto->city)->toBe('Lyon')
|
||||
->and($dto->phone)->toBe('0478000000')
|
||||
->and($dto->latitude)->toBe('45.75')
|
||||
->and($dto->longitude)->toBe('4.85')
|
||||
->and($dto->default)->toBeTrue();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
34
tests/Unit/App/Queries/Orders/GetBasketSummaryQueryTest.php
Normal file
34
tests/Unit/App/Queries/Orders/GetBasketSummaryQueryTest.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Queries\Orders\GetBasketSummaryQuery;
|
||||
use App\Queries\Orders\GetBasketSummaryQueryInput;
|
||||
use App\Queries\Orders\GetBasketSummaryQueryOutput;
|
||||
use Domain\Enums\OrderTunnelStep;
|
||||
use Domain\Models\Entities\Basket;
|
||||
use Domain\Models\ValueObjects\Entities\BasketId;
|
||||
use Domain\Services\BasketService;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
describe('GetBasketSummaryQuery', function (): void {
|
||||
it('returns basket summary output with step REVIEW and basket', function (): void {
|
||||
// GIVEN
|
||||
$basket = new Basket(new BasketId(Uuid::uuid7()));
|
||||
$basketService = \Mockery::mock(BasketService::class);
|
||||
$basketService->shouldReceive('getBasket')
|
||||
->once()
|
||||
->andReturn($basket);
|
||||
|
||||
$query = new GetBasketSummaryQuery($basketService);
|
||||
$input = new GetBasketSummaryQueryInput();
|
||||
|
||||
// WHEN
|
||||
$output = $query($input);
|
||||
|
||||
// THEN
|
||||
expect($output)->toBeInstanceOf(GetBasketSummaryQueryOutput::class)
|
||||
->and($output->step)->toBe(OrderTunnelStep::REVIEW)
|
||||
->and($output->basket)->toBe($basket);
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Dto\ShopDto;
|
||||
use App\Queries\Orders\GetOrderConfirmationQuery;
|
||||
use App\Queries\Orders\GetOrderConfirmationQueryInput;
|
||||
use App\Queries\Orders\GetOrderConfirmationQueryOutput;
|
||||
use Domain\Builders\OrderBuilderCompleted;
|
||||
use Domain\Enums\OrderTunnelStep;
|
||||
use Domain\Models\Entities\Basket;
|
||||
use Domain\Models\Entities\Shop;
|
||||
use Domain\Models\ValueObjects\Entities\BasketId;
|
||||
use Domain\Models\ValueObjects\Entities\ShopId;
|
||||
use Domain\Ports\Repositories\ShopRepository;
|
||||
use Domain\Services\OrderTunnelService;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
describe('GetOrderConfirmationQuery', function (): void {
|
||||
it('returns order confirmation output with step, basket, builder and shop', function (): void {
|
||||
// GIVEN
|
||||
$shopId = new ShopId(Uuid::uuid7());
|
||||
$basket = new Basket(new BasketId(Uuid::uuid7()));
|
||||
$builder = \Mockery::mock(OrderBuilderCompleted::class);
|
||||
$builder->shouldReceive('getBasket')->once()->andReturn($basket);
|
||||
$builder->shouldReceive('getShopId')->once()->andReturn($shopId);
|
||||
|
||||
$shop = new Shop(
|
||||
id: $shopId,
|
||||
name: 'Shop 1',
|
||||
address: '1 rue Test',
|
||||
postcode: '75001',
|
||||
city: 'Paris',
|
||||
);
|
||||
|
||||
$orderTunnelService = \Mockery::mock(OrderTunnelService::class);
|
||||
$orderTunnelService->shouldReceive('getBuilderCompletedOrFail')
|
||||
->once()
|
||||
->andReturn($builder);
|
||||
|
||||
$shopRepository = \Mockery::mock(ShopRepository::class);
|
||||
$shopRepository->shouldReceive('find')
|
||||
->once()
|
||||
->with($shopId)
|
||||
->andReturn($shop);
|
||||
|
||||
$query = new GetOrderConfirmationQuery($orderTunnelService, $shopRepository);
|
||||
$input = new GetOrderConfirmationQueryInput();
|
||||
|
||||
// WHEN
|
||||
$output = $query($input);
|
||||
|
||||
// THEN
|
||||
expect($output)->toBeInstanceOf(GetOrderConfirmationQueryOutput::class)
|
||||
->and($output->step)->toBe(OrderTunnelStep::CONFIRMATION)
|
||||
->and($output->basket)->toBe($basket)
|
||||
->and($output->builder)->toBe($builder)
|
||||
->and($output->shop)->toBeInstanceOf(ShopDto::class)
|
||||
->and($output->shop->name)->toBe('Shop 1');
|
||||
});
|
||||
|
||||
it('throws NotFoundHttpException when shop is not found', function (): void {
|
||||
// GIVEN
|
||||
$shopId = new ShopId(Uuid::uuid7());
|
||||
$basket = new Basket(new BasketId(Uuid::uuid7()));
|
||||
$builder = \Mockery::mock(OrderBuilderCompleted::class);
|
||||
$builder->shouldReceive('getBasket')->once()->andReturn($basket);
|
||||
$builder->shouldReceive('getShopId')->once()->andReturn($shopId);
|
||||
|
||||
$orderTunnelService = \Mockery::mock(OrderTunnelService::class);
|
||||
$orderTunnelService->shouldReceive('getBuilderCompletedOrFail')
|
||||
->once()
|
||||
->andReturn($builder);
|
||||
|
||||
$shopRepository = \Mockery::mock(ShopRepository::class);
|
||||
$shopRepository->shouldReceive('find')
|
||||
->once()
|
||||
->with($shopId)
|
||||
->andReturn(null);
|
||||
|
||||
$query = new GetOrderConfirmationQuery($orderTunnelService, $shopRepository);
|
||||
$input = new GetOrderConfirmationQueryInput();
|
||||
|
||||
// WHEN & THEN
|
||||
expect(fn () => $query($input))->toThrow(NotFoundHttpException::class, 'Shop not found');
|
||||
});
|
||||
});
|
||||
63
tests/Unit/App/Queries/Orders/GetPickTimeSlotQueryTest.php
Normal file
63
tests/Unit/App/Queries/Orders/GetPickTimeSlotQueryTest.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?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);
|
||||
});
|
||||
});
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Dto\ShopDto;
|
||||
use App\Services\MapUrlService;
|
||||
use Domain\Models\ValueObjects\DeliveryAddress;
|
||||
|
||||
|
|
@ -48,4 +49,26 @@ describe('MapUrlService', function () {
|
|||
$query = urlencode('My Shop 123 Test St 12345 Test City');
|
||||
expect($url)->toBe("https://maps.google.com/?q={$query}");
|
||||
});
|
||||
|
||||
it('generates an OpenStreetMap URL for a ShopDto', function () {
|
||||
// GIVEN
|
||||
$service = new MapUrlService();
|
||||
$shopDto = new ShopDto(
|
||||
id: 'test-id',
|
||||
name: 'DTO Shop',
|
||||
address: '456 DTO St',
|
||||
postcode: '69001',
|
||||
city: 'Lyon',
|
||||
phone: null,
|
||||
latitude: '45.75',
|
||||
longitude: '4.85',
|
||||
default: false,
|
||||
);
|
||||
|
||||
// WHEN
|
||||
$url = $service->generateUrl($shopDto);
|
||||
|
||||
// THEN
|
||||
expect($url)->toBe('https://www.openstreetmap.org/?mlat=45.75&mlon=4.85#map=16/45.75/4.85');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue