Improve pagination support in API (#5073)

This commit is contained in:
Kevin Papst
2024-09-22 17:26:02 +02:00
committed by GitHub
parent 4076e1c3d3
commit 13649e146c
5 changed files with 70 additions and 23 deletions

View File

@@ -76,6 +76,25 @@ class InvoiceControllerTest extends APIControllerBaseTest
self::assertApiResponseTypeStructure('InvoiceCollection', $result[0]);
}
public function testGetCollectionWithPagination(): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$this->importInvoiceFixtures(20);
$query = ['page' => 2, 'size' => 4];
$this->assertAccessIsGranted($client, '/api/invoices', 'GET', $query);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertEquals(4, \count($result));
$this->assertPagination($client->getResponse(), 2, 4, 5, 20);
self::assertApiResponseTypeStructure('InvoiceCollection', $result[0]);
}
public function testGetEntityIsSecure(): void
{
$client = $this->getClientForAuthenticatedUser();

View File

@@ -57,11 +57,12 @@ class InvoiceFixtures implements TestFixture
$invoice->setTax($tax);
$invoice->setCustomer($customers[array_rand($customers)]);
$invoice->setInvoiceNumber($i . '_ ' . $faker->text(10));
$prefix = uniqid($i . '_') . '_';
$invoice->setInvoiceNumber($prefix . $faker->randomNumber(3));
$invoice->setFilename($prefix . $faker->randomNumber(3));
$invoice->setCreatedAt($faker->dateTimeBetween('-1 year', 'now'));
$invoice->setUser($users[array_rand($users)]);
$invoice->setDueDays($faker->randomNumber(2));
$invoice->setFilename($faker->text(30));
$invoice->setComment($faker->text(300));
$invoice->setCurrency($faker->currencyCode());