test(api) : add comprehensive API test suite (161 tests)
- Add AbstractApiTestCase with auth helpers and entity factories - Add tests for all entities: Machine, Piece, Composant, Product, Site, ModelType, Constructeur, CustomField, CustomFieldValue, Document, MachineComponentLink, MachinePieceLink, MachineProductLink, Profile - Add controller tests: CommentController, EntityHistory - Add HealthCheck, Filter, Pagination, Validation, Session tests - Test auth (401), authorization (403), CRUD, and edge cases Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
71
tests/Api/PaginationTest.php
Normal file
71
tests/Api/PaginationTest.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Api;
|
||||
|
||||
use App\Tests\AbstractApiTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class PaginationTest extends AbstractApiTestCase
|
||||
{
|
||||
public function testDefaultPagination(): void
|
||||
{
|
||||
for ($i = 1; $i <= 35; ++$i) {
|
||||
$this->createConstructeur("Constructeur {$i}");
|
||||
}
|
||||
|
||||
$client = $this->createViewerClient();
|
||||
$client->request('GET', '/api/constructeurs');
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$data = $client->getResponse()->toArray();
|
||||
$this->assertSame(35, $data['totalItems']);
|
||||
$this->assertCount(30, $data['member']);
|
||||
}
|
||||
|
||||
public function testCustomItemsPerPage(): void
|
||||
{
|
||||
for ($i = 1; $i <= 15; ++$i) {
|
||||
$this->createConstructeur("Constructeur {$i}");
|
||||
}
|
||||
|
||||
$client = $this->createViewerClient();
|
||||
$client->request('GET', '/api/constructeurs?itemsPerPage=5');
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$data = $client->getResponse()->toArray();
|
||||
$this->assertCount(5, $data['member']);
|
||||
$this->assertSame(15, $data['totalItems']);
|
||||
}
|
||||
|
||||
public function testPageNavigation(): void
|
||||
{
|
||||
for ($i = 1; $i <= 15; ++$i) {
|
||||
$this->createConstructeur("Constructeur {$i}");
|
||||
}
|
||||
|
||||
$client = $this->createViewerClient();
|
||||
$client->request('GET', '/api/constructeurs?itemsPerPage=5&page=2');
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$data = $client->getResponse()->toArray();
|
||||
$this->assertCount(5, $data['member']);
|
||||
}
|
||||
|
||||
public function testMaxItemsPerPageIsCapped(): void
|
||||
{
|
||||
for ($i = 1; $i <= 5; ++$i) {
|
||||
$this->createConstructeur("Constructeur {$i}");
|
||||
}
|
||||
|
||||
$client = $this->createViewerClient();
|
||||
$client->request('GET', '/api/constructeurs?itemsPerPage=999');
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$data = $client->getResponse()->toArray();
|
||||
$this->assertCount(5, $data['member']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user