From f84a1a7b8cdeba17ed1809334c2b2a2c19ef2e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Fri, 2 Oct 2026 14:53:21 +0200 Subject: [PATCH] fix(orders): preserve pagination and query parameters in IndexOrdersRequest --- .../Requests/Bo/Orders/IndexOrdersRequest.php | 10 +++---- .../Controllers/Bo/OrdersControllerTest.php | 28 +++++++++++++++++++ .../Bo/Orders/IndexOrdersRequestTest.php | 7 ++++- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/app/Http/Requests/Bo/Orders/IndexOrdersRequest.php b/app/Http/Requests/Bo/Orders/IndexOrdersRequest.php index 658333f..0c71bd4 100644 --- a/app/Http/Requests/Bo/Orders/IndexOrdersRequest.php +++ b/app/Http/Requests/Bo/Orders/IndexOrdersRequest.php @@ -57,8 +57,7 @@ class IndexOrdersRequest extends FormRequest #[\Override] protected function prepareForValidation(): void { - // * Keep only non null values. - $inputs = []; + // * Remove empty filter values to prevent date and enum validation failures on empty strings. foreach ( [ 'order_date_start', @@ -68,12 +67,11 @@ class IndexOrdersRequest extends FormRequest 'status', ] as $inputName ) { - if (! empty($this->input($inputName))) { - $inputs[$inputName] = $this->input($inputName); + if ($this->has($inputName) && empty($this->input($inputName))) { + $this->request->remove($inputName); + $this->query->remove($inputName); } } - - $this->replace($inputs); } public function getStatus(): ?OrderStatus diff --git a/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php b/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php index 84668c1..24d3dcd 100644 --- a/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php @@ -62,6 +62,34 @@ describe('Bo\OrdersController', function (): void { $response->assertViewHas('orderStatusList'); }); + it('can paginate orders across pages', function (): void { + /** @var \Tests\TestCase $this */ + // GIVEN + $shop = Shop::factory()->create(['name' => 'Boutique Pagination']); + for ($i = 0; $i < 30; $i++) { + Order::forceCreate([ + 'id' => Uuid::uuid7()->toString(), + 'shop_id' => $shop->id, + 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'status' => OrderStatus::VALIDATED->value, + 'total' => new Money(2500, new Currency('EUR')), + 'employee' => new OrderEmployee(new Matricule((string) (1000100 + $i)), 'Alice', 'Smith', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), + 'pickup_day' => Date::now()->toDateString(), + ]); + } + + // WHEN + $response = $this->get('/bo/orders?page=2'); + + // THEN + expect($response->status())->toBe(200); + $response->assertViewHas('orders', function ($orders): bool { + return $orders instanceof LengthAwarePaginator + && $orders->currentPage() === 2; + }); + }); + it('can filter index by search term', function (): void { /** @var \Tests\TestCase $this */ // GIVEN diff --git a/tests/Feature/App/Http/Requests/Bo/Orders/IndexOrdersRequestTest.php b/tests/Feature/App/Http/Requests/Bo/Orders/IndexOrdersRequestTest.php index 8d9f5be..6e8254c 100644 --- a/tests/Feature/App/Http/Requests/Bo/Orders/IndexOrdersRequestTest.php +++ b/tests/Feature/App/Http/Requests/Bo/Orders/IndexOrdersRequestTest.php @@ -24,7 +24,7 @@ describe('IndexOrdersRequest', function () { expect($request->authorize())->toBeTrue(); }); - it('prepares for validation by keeping only non-null values', function () { + it('prepares for validation by removing empty filter values while preserving other parameters', function () { // GIVEN $authService = mock(AppAdminAuthService::class); $request = new IndexOrdersRequest($authService); @@ -36,6 +36,7 @@ describe('IndexOrdersRequest', function () { 'order_date_end' => '', 'order_pickup_start' => null, 'status' => 'pending', + 'page' => '3', 'other_field' => 'value', ]); @@ -48,6 +49,8 @@ describe('IndexOrdersRequest', function () { expect($request->all())->toBe([ 'order_date_start' => '2023-01-01', 'status' => 'pending', + 'page' => '3', + 'other_field' => 'value', ]); }); @@ -163,6 +166,7 @@ describe('IndexOrdersRequest', function () { $authService = mock(AppAdminAuthService::class); $request = new IndexOrdersRequest($authService); $request->initialize(query: [ + 'page' => 3, 'search' => 'TEST-REF', 'status' => (string) OrderStatus::VALIDATED->value, ]); @@ -172,6 +176,7 @@ describe('IndexOrdersRequest', function () { // THEN expect($input)->toBeInstanceOf(GetBoPaginatedOrdersQueryInput::class) + ->and($input->pagination->pageNumber()->value())->toBe(3) ->and($input->search)->toBe('TEST-REF') ->and($input->status)->toBe(OrderStatus::VALIDATED); });