ldc-boutique-cnc-sable/tests/Unit/Domain/Events/AnOrderHasBeenPlacedTest.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

64 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Events;
use Domain\Enums\Units\OrderUnit;
use Domain\Events\AnOrderHasBeenPlaced;
use Domain\Events\Dto\OrderPlacedLine;
use Domain\Events\Dto\OrderPlacedShop;
use Domain\Models\ValueObjects\Entities\OrderId;
use Domain\Models\ValueObjects\IncoId;
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\Currency;
use Money\Money;
use Ramsey\Uuid\Uuid;
describe('AnOrderHasBeenPlaced', function () {
it('creates an event when valid', function () {
// GIVEN
$uuid = Uuid::uuid7();
$orderId = new OrderId($uuid);
$reference = new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58());
$totalTtc = new Money(1000, new Currency('EUR'));
$matricule = new Matricule('1234567');
$employee = new OrderEmployee($matricule, 'John', 'Doe', new ShopperEstablishmentCode('ETAB01'), new ShopperSiteCode('SITEA'), new ShopperServiceCode('101'));
$shop = new OrderPlacedShop('Shop', 'Address', '12345', 'City');
$pickupDay = new \DateTimeImmutable();
$lines = [
new OrderPlacedLine('Product', new IncoId(123), false, null, OrderUnit::PCE, 1, new Money(1000, new Currency('EUR'))),
];
// WHEN
$event = new AnOrderHasBeenPlaced($orderId, $reference, $totalTtc, $matricule, $employee, $shop, $pickupDay, $lines);
// THEN
expect($event->orderId)->toBe($orderId)
->and($event->reference)->toBe($reference);
});
it('throws exception if lines are empty', function () {
// GIVEN
$uuid = Uuid::uuid7();
$orderId = new OrderId($uuid);
$reference = new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58());
$totalTtc = new Money(1000, new Currency('EUR'));
$matricule = new Matricule('1234567');
$employee = new OrderEmployee($matricule, 'John', 'Doe', new ShopperEstablishmentCode('ETAB01'), new ShopperSiteCode('SITEA'), new ShopperServiceCode('101'));
$shop = new OrderPlacedShop('Shop', 'Address', '12345', 'City');
$pickupDay = new \DateTimeImmutable();
$lines = [];
// WHEN
$action = fn () => new AnOrderHasBeenPlaced($orderId, $reference, $totalTtc, $matricule, $employee, $shop, $pickupDay, $lines);
// THEN
expect($action)->toThrow(\DomainException::class, 'An order must have at least one line');
});
});