52 lines
1.8 KiB
PHP
52 lines
1.8 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\Dto\PickupExceptionDto;
|
|
use App\Models\PickupException;
|
|
use App\Services\DataTableService;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
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;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
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)->toBeInstanceOf(LengthAwarePaginator::class)
|
|
->and($paginator->total())->toBe(3)
|
|
->and($paginator->items())->toHaveCount(3)
|
|
->and($paginator->items()[0])->toBeInstanceOf(PickupExceptionDto::class);
|
|
});
|
|
});
|