103 lines
3.7 KiB
PHP
103 lines
3.7 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\Models\Order;
|
|
use App\Models\Shop;
|
|
use App\Services\MapUrlService;
|
|
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 Shared\Helpers\UuidHelper;
|
|
|
|
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(UuidHelper::v7());
|
|
|
|
$order = new Order();
|
|
$order->reference = $reference;
|
|
$order->total = Money::EUR(2500);
|
|
$order->status = OrderStatus::VALIDATED;
|
|
$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();
|
|
|
|
$query = new GetTunnelOrderConfirmedQuery(new MapUrlService());
|
|
$input = new GetTunnelOrderConfirmedQueryInput($order);
|
|
|
|
// WHEN
|
|
$output = $query($input);
|
|
|
|
// THEN
|
|
expect($output->step)->toBe(OrderTunnelStep::CONFIRMATION)
|
|
->and((string) $output->order->reference)->toBe((string) $reference)
|
|
->and($output->shop->name)->toBe('Boutique Retrait');
|
|
});
|
|
|
|
it('throws UnexpectedValueException when order has no shop', function (): void {
|
|
// GIVEN
|
|
$reference = new OrderReference(UuidHelper::v7());
|
|
|
|
$order = new Order();
|
|
$order->reference = $reference;
|
|
$order->total = Money::EUR(2500);
|
|
$order->status = OrderStatus::VALIDATED;
|
|
$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();
|
|
|
|
$query = new GetTunnelOrderConfirmedQuery(new MapUrlService());
|
|
$input = new GetTunnelOrderConfirmedQueryInput($order);
|
|
|
|
// WHEN & THEN
|
|
expect(fn () => $query($input))->toThrow(\UnexpectedValueException::class);
|
|
});
|
|
});
|