Fixed incorrect API listing total when offset set

Fixes #2043
This commit is contained in:
Dan Brown 2020-04-25 16:38:11 +01:00
parent 0883b0533b
commit 79a949836b
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9
2 changed files with 17 additions and 1 deletions

View file

@ -36,8 +36,8 @@ class ListingResponseBuilder
*/
public function toResponse()
{
$data = $this->fetchData();
$total = $this->query->count();
$data = $this->fetchData();
return response()->json([
'data' => $data,

View file

@ -81,4 +81,20 @@ class ApiListingTest extends TestCase
}
}
public function test_total_on_results_shows_correctly()
{
$this->actingAsApiEditor();
$bookCount = Book::query()->count();
$resp = $this->get($this->endpoint . '?count=1');
$resp->assertJson(['total' => $bookCount ]);
}
public function test_total_on_results_shows_correctly_when_offset_provided()
{
$this->actingAsApiEditor();
$bookCount = Book::query()->count();
$resp = $this->get($this->endpoint . '?count=1&offset=1');
$resp->assertJson(['total' => $bookCount ]);
}
}