ldc-cocotte/tests/Integration/WithApp/App/Cqs/Queries/PickupExceptions/GetPaginatedPickupExceptionsQueryTest.php

45 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Integration\WithApp\App\Cqs\Queries\PickupExceptions;
use App\Cqs\Queries\PickupExceptions\GetPaginatedPickupExceptionsQuery;
use App\Cqs\Queries\PickupExceptions\GetPaginatedPickupExceptionsQueryInput;
use App\Models\PickupException;
use App\Services\DataTableService;
use Illuminate\Http\Request;
use Illuminate\Session\NullSessionHandler;
use Illuminate\Session\Store;
use Illuminate\Support\Facades\Schema;
use Shared\Pagination\PageNumber;
use Shared\Pagination\PageSize;
use Shared\Pagination\Pagination;
afterEach(function (): void {
DataTableService::clearColumnsCache();
});
describe('GetPaginatedPickupExceptionsQuery', function () {
test('it executes and returns paginated pickup exception DTOs', function () {
// GIVEN
PickupException::factory()->count(3)->create();
$dataTableService = new DataTableService(
Request::create('/'),
new Store('test', new NullSessionHandler()),
static fn (string $table): array => Schema::getColumnListing($table),
);
$query = new GetPaginatedPickupExceptionsQuery($dataTableService);
$input = new GetPaginatedPickupExceptionsQueryInput(
pagination: Pagination::ofPage(new PageNumber(1), new PageSize(10)),
);
// WHEN
$paginator = $query($input);
// THEN
expect($paginator->total())->toBe(3)
->and($paginator->items())->toHaveCount(3);
});
});