Step 03 — ACL (LegacyFulfillment)
- LegacyShipmentAcl : mapping explicite sales.v1.OrderConfirmed → LegacyCreateShipmentCommand - LegacyCreateShipmentCommand : modèle legacy (champs abrégés, codification date/status) - WhenOrderConfirmed (LegacyFulfillment) : consumer Messenger via ACL - Tests unitaires mapping ACL + test d'intégration
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Tests\Unit\LegacyFulfillment\Infrastructure\AntiCorruption;
|
||||
|
||||
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed;
|
||||
use MiniShop\LegacyFulfillment\Infrastructure\AntiCorruption\LegacyShipmentAcl;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests du mapping ACL : sales.v1.OrderConfirmed → LegacyCreateShipmentCommand.
|
||||
*/
|
||||
final class LegacyShipmentAclTest extends TestCase
|
||||
{
|
||||
private LegacyShipmentAcl $acl;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->acl = new LegacyShipmentAcl();
|
||||
}
|
||||
|
||||
public function test_maps_order_ref_with_legacy_prefix(): void
|
||||
{
|
||||
$command = $this->acl->fromSalesOrderConfirmed($this->createMessage());
|
||||
|
||||
self::assertStringStartsWith('LEG-', $command->ord_ref);
|
||||
self::assertSame('LEG-order-acl-001', $command->ord_ref);
|
||||
}
|
||||
|
||||
public function test_truncates_recipient_name(): void
|
||||
{
|
||||
$message = new OrderConfirmed(
|
||||
orderId: 'order-001',
|
||||
customerId: 'very-long-customer-id-that-exceeds-thirty-five-characters-limit',
|
||||
totalInCents: 1000,
|
||||
currency: 'EUR',
|
||||
lines: [['productName' => 'X', 'quantity' => 1, 'unitPriceInCents' => 1000, 'currency' => 'EUR']],
|
||||
);
|
||||
|
||||
$command = $this->acl->fromSalesOrderConfirmed($message);
|
||||
|
||||
self::assertLessThanOrEqual(35, mb_strlen($command->rcpt_nm));
|
||||
}
|
||||
|
||||
public function test_calculates_weight_from_line_count(): void
|
||||
{
|
||||
$command = $this->acl->fromSalesOrderConfirmed($this->createMessage(lineCount: 3));
|
||||
|
||||
self::assertSame(1500, $command->wgt_g); // 3 * 500g
|
||||
}
|
||||
|
||||
public function test_minimum_weight_is_100g(): void
|
||||
{
|
||||
$command = $this->acl->fromSalesOrderConfirmed($this->createMessage(lineCount: 0));
|
||||
|
||||
self::assertGreaterThanOrEqual(100, $command->wgt_g);
|
||||
}
|
||||
|
||||
public function test_status_is_new(): void
|
||||
{
|
||||
$command = $this->acl->fromSalesOrderConfirmed($this->createMessage());
|
||||
|
||||
self::assertSame('NEW', $command->sts);
|
||||
}
|
||||
|
||||
public function test_date_format_is_legacy_yyyymmdd(): void
|
||||
{
|
||||
$command = $this->acl->fromSalesOrderConfirmed($this->createMessage());
|
||||
|
||||
self::assertMatchesRegularExpression('/^\d{8}$/', $command->req_dt);
|
||||
}
|
||||
|
||||
public function test_description_contains_order_ref_and_article_count(): void
|
||||
{
|
||||
$command = $this->acl->fromSalesOrderConfirmed($this->createMessage(lineCount: 2));
|
||||
|
||||
self::assertStringContainsString('CMD-', $command->desc);
|
||||
self::assertStringContainsString('2 articles', $command->desc);
|
||||
}
|
||||
|
||||
private function createMessage(int $lineCount = 1): OrderConfirmed
|
||||
{
|
||||
$lines = array_fill(0, $lineCount, [
|
||||
'productName' => 'Widget',
|
||||
'quantity' => 1,
|
||||
'unitPriceInCents' => 1000,
|
||||
'currency' => 'EUR',
|
||||
]);
|
||||
|
||||
return new OrderConfirmed(
|
||||
orderId: 'order-acl-001',
|
||||
customerId: 'cust-001',
|
||||
totalInCents: $lineCount * 1000,
|
||||
currency: 'EUR',
|
||||
lines: $lines,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user