2026-11-02 14:53:06 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-16 14:21:17 +01:00
|
|
|
namespace Tests\Integration\WithApp\App\Dto;
|
|
|
|
|
|
2026-11-02 14:53:06 +01:00
|
|
|
use App\Dto\OrderLineDto;
|
|
|
|
|
use App\Models\Order;
|
|
|
|
|
use App\Models\OrderLine;
|
|
|
|
|
use App\Models\Shop;
|
2026-11-16 15:49:48 +01:00
|
|
|
use Carbon\Carbon;
|
|
|
|
|
use Carbon\CarbonImmutable;
|
2026-11-02 14:53:06 +01:00
|
|
|
use Domain\Enums\OrderStatus;
|
|
|
|
|
use Domain\Enums\ProductBrand;
|
|
|
|
|
use Domain\Enums\TaxRate;
|
|
|
|
|
use Domain\Enums\Units\OrderUnit;
|
|
|
|
|
use Domain\Models\ValueObjects\DeliveryAddress;
|
|
|
|
|
use Domain\Models\ValueObjects\Entities\ProductId;
|
|
|
|
|
use Domain\Models\ValueObjects\IncoId;
|
|
|
|
|
use Domain\Models\ValueObjects\Matricule;
|
|
|
|
|
use Domain\Models\ValueObjects\OrderEmployee;
|
|
|
|
|
use Domain\Models\ValueObjects\OrderLineProduct;
|
|
|
|
|
use Domain\Models\ValueObjects\OrderReference;
|
|
|
|
|
use Domain\Models\ValueObjects\ProductWeight;
|
|
|
|
|
use Domain\Models\ValueObjects\ShopperEstablishmentCode;
|
|
|
|
|
use Domain\Models\ValueObjects\ShopperServiceCode;
|
|
|
|
|
use Domain\Models\ValueObjects\ShopperSiteCode;
|
|
|
|
|
use Illuminate\Support\Facades\Date;
|
|
|
|
|
use Money\Money;
|
2026-11-17 12:15:39 +01:00
|
|
|
use Shared\Helpers\UuidHelper;
|
2026-11-02 14:53:06 +01:00
|
|
|
|
2026-11-16 15:49:48 +01:00
|
|
|
beforeEach(function (): void {
|
|
|
|
|
$now = CarbonImmutable::parse('2026-06-15 10:00:00', 'Europe/Paris');
|
|
|
|
|
Date::setTestNow($now);
|
|
|
|
|
CarbonImmutable::setTestNow($now);
|
|
|
|
|
Carbon::setTestNow($now);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(function (): void {
|
|
|
|
|
Date::setTestNow();
|
|
|
|
|
CarbonImmutable::setTestNow();
|
|
|
|
|
Carbon::setTestNow();
|
|
|
|
|
});
|
|
|
|
|
|
2026-11-02 14:53:06 +01:00
|
|
|
describe('OrderLineDto Integration', function (): void {
|
|
|
|
|
test('it maps from OrderLine Eloquent model with correct unit price TTC and flattened product properties', function (): void {
|
|
|
|
|
// GIVEN
|
2026-11-02 15:21:39 +01:00
|
|
|
$shop = Shop::factory()->create();
|
2026-11-16 15:54:41 +01:00
|
|
|
$order = Order::query()->forceCreate([
|
2026-11-17 12:15:39 +01:00
|
|
|
'id' => UuidHelper::v7()->toString(),
|
2026-11-02 14:53:06 +01:00
|
|
|
'shop_id' => $shop->id,
|
2026-11-17 12:15:39 +01:00
|
|
|
'reference' => new OrderReference(UuidHelper::v7()),
|
2026-11-02 14:53:06 +01:00
|
|
|
'status' => OrderStatus::VALIDATED->value,
|
|
|
|
|
'total' => Money::EUR(4154),
|
2026-11-16 16:29:17 +01:00
|
|
|
'employee' => new OrderEmployee(
|
|
|
|
|
new Matricule('8888001'),
|
|
|
|
|
'Jean',
|
|
|
|
|
'Dupont',
|
|
|
|
|
new ShopperEstablishmentCode('FAC01'),
|
|
|
|
|
new ShopperSiteCode('SITE'),
|
|
|
|
|
new ShopperServiceCode('101'),
|
|
|
|
|
),
|
2026-11-02 14:53:06 +01:00
|
|
|
'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'),
|
|
|
|
|
'pickup_day' => Date::now()->toDateString(),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$orderLineProduct = new OrderLineProduct(
|
|
|
|
|
incoId: new IncoId(999),
|
2026-11-17 12:15:39 +01:00
|
|
|
originalId: new ProductId(UuidHelper::v7()),
|
2026-11-02 14:53:06 +01:00
|
|
|
name: 'Terrine de Foie Gras de Canard mi-cuit 500g',
|
|
|
|
|
weight: new ProductWeight(500, false),
|
|
|
|
|
brand: ProductBrand::loue,
|
|
|
|
|
orderUnit: OrderUnit::PCE,
|
|
|
|
|
price: Money::EUR(1969),
|
|
|
|
|
discountedPrice: Money::EUR(1969),
|
|
|
|
|
priceKgTtc: Money::EUR(3938),
|
|
|
|
|
taxRate: TaxRate::TVA_5_5,
|
|
|
|
|
picture: null,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$line = new OrderLine();
|
|
|
|
|
$line->order()->associate($order);
|
|
|
|
|
$line->product = $orderLineProduct;
|
|
|
|
|
$line->quantity = 2;
|
|
|
|
|
$line->unit_price = Money::EUR(1969);
|
|
|
|
|
$line->unit_tax = Money::EUR(108);
|
|
|
|
|
$line->unit_discount = Money::EUR(0);
|
|
|
|
|
$line->tax_rate = TaxRate::TVA_5_5;
|
|
|
|
|
$line->total_ttc = Money::EUR(4154);
|
|
|
|
|
$line->total_ht = Money::EUR(3938);
|
|
|
|
|
$line->total_tax = Money::EUR(216);
|
|
|
|
|
$line->total_discount = Money::EUR(0);
|
|
|
|
|
$line->save();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$dto = OrderLineDto::fromModel($line);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($line->unitPriceTtc)->toEqual(Money::EUR(2077))
|
|
|
|
|
->and($dto->id)->toBe((int) $line->id)
|
|
|
|
|
->and($dto->order_id)->toBe((string) $line->order_id)
|
|
|
|
|
->and($dto->product_name)->toBe('Terrine de Foie Gras de Canard mi-cuit 500g')
|
|
|
|
|
->and($dto->product_inco_id)->toBe('999')
|
|
|
|
|
->and($dto->product_brand_label)->toBe(ProductBrand::loue->label())
|
|
|
|
|
->and($dto->is_variable_weight)->toBeFalse()
|
|
|
|
|
->and($dto->price_kg_ttc)->toEqual(Money::EUR(3938))
|
|
|
|
|
->and($dto->quantity)->toBe(2)
|
|
|
|
|
->and($dto->unit_price)->toEqual(Money::EUR(1969))
|
|
|
|
|
->and($dto->unit_tax)->toEqual(Money::EUR(108))
|
|
|
|
|
->and($dto->unit_discount)->toEqual(Money::EUR(0))
|
|
|
|
|
->and($dto->tax_rate)->toBe(TaxRate::TVA_5_5)
|
|
|
|
|
->and($dto->unit_price_ttc)->toEqual(Money::EUR(2077))
|
|
|
|
|
->and($dto->unitPriceTtc)->toEqual(Money::EUR(2077))
|
|
|
|
|
->and($dto->total_ht)->toEqual(Money::EUR(3938))
|
|
|
|
|
->and($dto->total_tax)->toEqual(Money::EUR(216))
|
2026-11-16 12:50:19 +01:00
|
|
|
->and($dto->total_ttc)->toEqual(Money::EUR(4154))
|
|
|
|
|
->and($dto->toArray())->toBe([
|
|
|
|
|
'id' => (int) $line->id,
|
|
|
|
|
'order_id' => (string) $line->order_id,
|
|
|
|
|
'product_name' => 'Terrine de Foie Gras de Canard mi-cuit 500g',
|
|
|
|
|
'product_inco_id' => '999',
|
|
|
|
|
'product_brand_label' => ProductBrand::loue->label(),
|
|
|
|
|
'is_variable_weight' => false,
|
|
|
|
|
'price_kg_ttc' => '3938',
|
|
|
|
|
'quantity' => 2,
|
|
|
|
|
'unit_price' => '1969',
|
|
|
|
|
'unit_tax' => '108',
|
|
|
|
|
'unit_discount' => '0',
|
|
|
|
|
'tax_rate' => TaxRate::TVA_5_5->value,
|
|
|
|
|
'unit_price_ttc' => '2077',
|
|
|
|
|
'unit_price_discounted_ht' => '1969',
|
|
|
|
|
'total_ttc' => '4154',
|
|
|
|
|
'total_ht' => '3938',
|
|
|
|
|
'total_tax' => '216',
|
|
|
|
|
'total_discount' => '0',
|
|
|
|
|
'total_gross_ht' => '3938',
|
|
|
|
|
]);
|
2026-11-02 14:53:06 +01:00
|
|
|
});
|
|
|
|
|
});
|