ldc-cocotte/tests/Integration/WithApp/App/Queries/Orders/GetTunnelOrderConfirmedQueryTest.php
Jérémy Munsch 8b96ce90be
test(casts): add tests for EmployeeSitesCast functionality
test(casts): add tests for ShopperEstablishmentCodeCast functionality

test(casts): add tests for ShopperServiceCodeCast functionality

test(casts): add tests for ShopperSiteCodeCast functionality

test(dto): update ProductDtoTest to include additional fields

test(dto): update SettingDtoTest to remove arcadiaSites assertions

test(events): update AnOrderHasBeenPlacedTest to use value objects

test(entities): update OrderTest to use value objects for employee details

test(value-objects): update EmployeeUpsertDataTest to use value objects

test(pagination): update PaginationTest to access value properties

test(services): update AppCustomerAuthServiceTest to use CrmHashcode

test(services): update CrmServiceTest to use CrmHashcode for customer retrieval
2026-10-27 09:58:45 +01:00

111 lines
4.1 KiB
PHP

<?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 Domain\Models\ValueObjects\ShopperEstablishmentCode;
use Domain\Models\ValueObjects\ShopperServiceCode;
use Domain\Models\ValueObjects\ShopperSiteCode;
use Money\Money;
use Symfony\Component\Uid\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::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(
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($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(
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);
});
});