Skip to content

Commit

Permalink
Fix: unable to submit requests that use null as pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
jordyvanderhaegen committed Apr 10, 2024
1 parent 6f2a3ec commit bb0ac02
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Pagination/PagedPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class PagedPaginator extends BasePagedPaginator
{
protected ?int $perPageLimit = 25;
protected ?string $paginationOrder = null;
protected string $paginationOrder = '';

protected function isLastPage(Response $response): bool
{
Expand Down Expand Up @@ -48,7 +48,7 @@ protected function applyPagination(Request $request): Request
return $request;
}

public function setPaginationOrder(?string $order): static
public function setPaginationOrder(string $order): static
{
$this->paginationOrder = $order;

Expand Down
23 changes: 23 additions & 0 deletions tests/Feature/Pagination/PagedPaginationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,27 @@ public function it_can_set_the_pagination_order()
}
});
}

/** @test */
public function it_can_use_an_empty_string_as_pagination_order_default()
{
$plytix = new Plytix();
$mockClient = MockClient::global([
MockResponseFixture::make(fixtureName: 'token.json', status: 200),
MockResponseFixture::make(fixtureName: 'product-categories-search-page-1.json', status: 200),
MockResponseFixture::make(fixtureName: 'product-categories-search-page-2.json', status: 200),
]);

$paginator = $plytix->paginate(new ProductCategoriesSearchRequest());

foreach ($paginator as $response) {
// Let's loop so the paginator fetches all pages
}

$mockClient->assertSent(function (Request $request, Response $response) {
if ($request instanceof ProductCategoriesSearchRequest) {
return Arr::get($request->body()->all(), 'pagination.order') === '';
}
});
}
}

0 comments on commit bb0ac02

Please sign in to comment.