ldc-boutique-cnc-sable/tests/Unit/Domain/Events/DtoTest.php
Jérémy Munsch 3b3997d547
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- Implement automated synchronization of employees via Arcadia API (EmployeeSyncService, SynchronizeEmployeesWithArcadiaApi, FetchAndUpsertArcadiaEmployees)
- Add Back-Office application settings for employee sites (Setting singleton, GetSettingsQuery, UpdateSettings, SettingsController, EmployeeSitesInputComponent.vue)
- Strongly type Employee attributes using Domain Value Objects (ShopperEstablishmentCode, ShopperSiteCode, ShopperServiceCode) and Eloquent Casts
- Migrate pagination from Domain to Shared\Pagination namespace across queries and inputs
- Remove legacy and dead CSV employee import/export code
- Restore Domain\Ports\Services\CsvGenerator interface for Regate order generation
- Add comprehensive Pest unit, integration, and feature test coverage
2026-10-27 09:58:44 +01:00

152 lines
4.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Events;
use Domain\Enums\Units\OrderUnit;
use Domain\Events\Dto\OrderPlacedLine;
use Domain\Events\Dto\OrderPlacedShop;
use Domain\Events\Dto\RegateOrderCsvGenerated;
use Domain\Events\Dto\SalariesHaveBeenSynced;
use Domain\Models\ValueObjects\IncoId;
use Domain\Models\ValueObjects\Matricule;
use Money\Currency;
use Money\Money;
describe('OrderPlacedLine', function () {
it('creates OrderPlacedLine correctly', function () {
// GIVEN
$productName = 'Product';
$incoId = new IncoId(1);
$unit = OrderUnit::PCE;
$price = new Money(2000, new Currency('EUR'));
// WHEN
$line = new OrderPlacedLine($productName, $incoId, false, null, $unit, 2, $price);
// THEN
expect($line->quantity)->toBe(2);
});
it('throws exception if quantity is zero or less for OrderPlacedLine', function () {
// GIVEN
$productName = 'Product';
$incoId = new IncoId(1);
$unit = OrderUnit::PCE;
$price = new Money(2000, new Currency('EUR'));
// WHEN
$action = fn () => new OrderPlacedLine($productName, $incoId, false, null, $unit, 0, $price);
// THEN
expect($action)->toThrow(\DomainException::class, 'Quantity must be greater than 0');
});
});
describe('OrderPlacedShop', function () {
it('creates OrderPlacedShop correctly', function () {
// GIVEN
$name = 'Name';
$address = 'Addr';
$zip = '12345';
$city = 'City';
// WHEN
$shop = new OrderPlacedShop($name, $address, $zip, $city);
// THEN
expect($shop->name)->toBe('Name');
});
it('throws exception if shop name is empty', function () {
// GIVEN
$name = ' ';
$address = 'Addr';
$zip = '12345';
$city = 'City';
// WHEN
$action = fn () => new OrderPlacedShop($name, $address, $zip, $city);
// THEN
expect($action)->toThrow(\DomainException::class, 'Shop name is required');
});
it('throws exception if shop address is empty', function () {
// GIVEN
$name = 'Name';
$address = '';
$zip = '12345';
$city = 'City';
// WHEN
$action = fn () => new OrderPlacedShop($name, $address, $zip, $city);
// THEN
expect($action)->toThrow(\DomainException::class, 'Shop address is required');
});
it('throws exception if shop postcode is empty', function () {
// GIVEN
$name = 'Name';
$address = 'Addr';
$zip = '';
$city = 'City';
// WHEN
$action = fn () => new OrderPlacedShop($name, $address, $zip, $city);
// THEN
expect($action)->toThrow(\DomainException::class, 'Shop postcode is required');
});
it('throws exception if shop city is empty', function () {
// GIVEN
$name = 'Name';
$address = 'Addr';
$zip = '12345';
$city = ' ';
// WHEN
$action = fn () => new OrderPlacedShop($name, $address, $zip, $city);
// THEN
expect($action)->toThrow(\DomainException::class, 'Shop city is required');
});
});
describe('RegateOrderCsvGenerated', function () {
it('creates RegateOrderCsvGenerated correctly', function () {
// GIVEN
$csvContent = 'csv';
$fileName = 'file.csv';
// WHEN
$dto = new RegateOrderCsvGenerated($csvContent, $fileName);
// THEN
expect($dto->csvContent)->toBe('csv')
->and($dto->fileName)->toBe('file.csv');
});
});
describe('SalariesHaveBeenSynced', function () {
it('creates SalariesHaveBeenSynced correctly', function () {
// GIVEN
$matricules = [new Matricule('1234567')];
// WHEN
$dto = new SalariesHaveBeenSynced($matricules);
// THEN
expect($dto->matricules)->toBe($matricules);
});
it('throws exception if SalariesHaveBeenSynced gets non-matricule', function () {
// GIVEN
/** @var array<Matricule> $matricules */
$matricules = ['1234567'];
// WHEN
$action = fn () => new SalariesHaveBeenSynced($matricules);
// THEN
expect($action)->toThrow(\UnexpectedValueException::class);
});
});