Refactored the codebase to change the namespaces of various actions and queries from `App\Actions` to `App\Cqs\Actions` and `App\Queries` to `App\Cqs\Queries`. This restructuring improves organization and clarity in the codebase.
111 lines
4.1 KiB
PHP
111 lines
4.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Integration\WithApp\App\Cqs\Queries\Orders;
|
|
|
|
use App\Cqs\Queries\Orders\GetTunnelOrderConfirmedQuery;
|
|
use App\Cqs\Queries\Orders\GetTunnelOrderConfirmedQueryInput;
|
|
use App\Cqs\Queries\Orders\GetTunnelOrderConfirmedQueryOutput;
|
|
use App\Dto\OrderDto;
|
|
use App\Dto\ShopDto;
|
|
use App\Models\Order;
|
|
use App\Models\Shop;
|
|
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 Domain\Models\ValueObjects\ShopperEstablishmentCode;
|
|
use Domain\Models\ValueObjects\ShopperServiceCode;
|
|
use Domain\Models\ValueObjects\ShopperSiteCode;
|
|
use Money\Money;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
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::uuid7());
|
|
|
|
$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(
|
|
matricule: new Matricule('1234567'),
|
|
firstname: 'Jean',
|
|
lastname: 'Dupont',
|
|
facility: new ShopperEstablishmentCode('FAC01'),
|
|
site: new ShopperSiteCode('SITE'),
|
|
service: new ShopperServiceCode('101'),
|
|
);
|
|
$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((string) $reference)
|
|
->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::uuid7());
|
|
|
|
$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(
|
|
matricule: new Matricule('1234567'),
|
|
firstname: 'Jean',
|
|
lastname: 'Dupont',
|
|
facility: new ShopperEstablishmentCode('FAC01'),
|
|
site: new ShopperSiteCode('SITE'),
|
|
service: new ShopperServiceCode('101'),
|
|
);
|
|
$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);
|
|
});
|
|
});
|