From d430fa01d264363c0a606d4174bd2f209fe53dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Sun, 15 Nov 2026 19:43:45 +0100 Subject: [PATCH] fix(product): adjust orderable end condition to include equality Updated the condition for orderable end to include equality, ensuring products are excluded correctly when the current date matches the orderable end date. --- domain/Models/Entities/Product.php | 2 +- .../WithApp/App/Models/ProductTest.php | 81 +++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 tests/Integration/WithApp/App/Models/ProductTest.php diff --git a/domain/Models/Entities/Product.php b/domain/Models/Entities/Product.php index 827907e0..5e876902 100644 --- a/domain/Models/Entities/Product.php +++ b/domain/Models/Entities/Product.php @@ -52,7 +52,7 @@ final class Product implements Entity if ($this->orderable_start && $target < $this->orderable_start) { return false; } - if ($this->orderable_end && $target > $this->orderable_end) { + if ($this->orderable_end && $target >= $this->orderable_end) { return false; } diff --git a/tests/Integration/WithApp/App/Models/ProductTest.php b/tests/Integration/WithApp/App/Models/ProductTest.php new file mode 100644 index 00000000..0ac00de8 --- /dev/null +++ b/tests/Integration/WithApp/App/Models/ProductTest.php @@ -0,0 +1,81 @@ + $range->id, + 'name' => 'Produit ' . uniqid(), + 'brand' => ProductBrand::loue, + 'invoicing_unit' => InvoicingUnit::PCE, + 'sell_unit' => SellUnit::PCE, + 'order_unit' => OrderUnit::PCE, + 'tax_rate' => TaxRate::TVA_20, + 'description' => 'Description test', + 'status' => true, + 'orderable_start' => $orderableStart, + 'orderable_end' => $orderableEnd, + ]); + $product->id = Uuid::uuid7()->toString(); + $product->order = random_int(1, 999999); + $product->price = Money::EUR(1000); + $product->short_description = 'Description courte'; + $product->picture_alt = 'alt'; + $product->picture_title = 'title'; + $product->picture_large_alt = 'alt'; + $product->picture_large_title = 'title'; + $product->saveOrFail(); + + $inco = new ProductInco(); + $inco->no_art = random_int(10000, 99999); + $inco->product()->associate($product); + $inco->saveOrFail(); + + return $product; +} + +describe('Product::scopeOrderable', function (): void { + it('includes product when current date equals orderable_start and excludes when current date equals orderable_end', function (): void { + // GIVEN + $now = Date::parse('2026-11-15 12:00:00'); + Date::setTestNow($now); + + $range = new Range(); + $range->name = 'Gamme ' . uniqid(); + $range->status = true; + $range->order = 1; + $range->picture_alt = 'alt'; + $range->picture_title = 'title'; + $range->saveOrFail(); + + $startsNow = createOrderableTestProduct($range, orderableStart: $now, orderableEnd: $now->copy()->addHour()); + $endsNow = createOrderableTestProduct($range, orderableStart: $now->copy()->subHour(), orderableEnd: $now); + $inRange = createOrderableTestProduct($range, orderableStart: $now->copy()->subHour(), orderableEnd: $now->copy()->addHour()); + $future = createOrderableTestProduct($range, orderableStart: $now->copy()->addSecond(), orderableEnd: $now->copy()->addHour()); + + // WHEN + $orderableIds = Product::query()->orderable()->pluck('id')->all(); + + // THEN + expect($orderableIds)->toContain($startsNow->id, $inRange->id) + ->and($orderableIds)->not->toContain($endsNow->id, $future->id); + + Date::setTestNow(); + }); +});