53 lines
1.7 KiB
PHP
53 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Presentation\Api\V1\Dto;
|
|
|
|
use Presentation\Api\V1\Dto\PaginationDto;
|
|
use Uri\Rfc3986\Uri;
|
|
|
|
covers(PaginationDto::class);
|
|
|
|
describe('PaginationDto Unit Tests', function (): void {
|
|
it('creates pagination metadata and links correctly', function (): void {
|
|
// GIVEN
|
|
$baseUri = new Uri('http://localhost/api/v1/employees');
|
|
|
|
// WHEN
|
|
$dto = PaginationDto::create(
|
|
page: 2,
|
|
pageSize: 10,
|
|
totalItems: 35,
|
|
baseUri: $baseUri,
|
|
);
|
|
|
|
// THEN
|
|
expect($dto->page)->toBe(2)
|
|
->and($dto->pageSize)->toBe(10)
|
|
->and($dto->totalItems)->toBe(35)
|
|
->and($dto->totalPages)->toBe(4)
|
|
->and($dto->links['self'])->toBe('http://localhost/api/v1/employees?page=2&pageSize=10')
|
|
->and($dto->links['first'])->toBe('http://localhost/api/v1/employees?page=1&pageSize=10')
|
|
->and($dto->links['prev'])->toBe('http://localhost/api/v1/employees?page=1&pageSize=10')
|
|
->and($dto->links['next'])->toBe('http://localhost/api/v1/employees?page=3&pageSize=10')
|
|
->and($dto->links['last'])->toBe('http://localhost/api/v1/employees?page=4&pageSize=10');
|
|
});
|
|
|
|
it('handles first page correctly with null prev link', function (): void {
|
|
// GIVEN
|
|
$baseUri = new Uri('http://localhost/api/v1/employees');
|
|
|
|
// WHEN
|
|
$dto = PaginationDto::create(
|
|
page: 1,
|
|
pageSize: 10,
|
|
totalItems: 15,
|
|
baseUri: $baseUri,
|
|
);
|
|
|
|
// THEN
|
|
expect($dto->links['prev'])->toBeNull()
|
|
->and($dto->links['next'])->toBe('http://localhost/api/v1/employees?page=2&pageSize=10');
|
|
});
|
|
});
|