feat(tickets): add tenant-aware server-side sorting
This commit is contained in:
@@ -96,6 +96,47 @@ class AdminAppTicketControllerTest extends TestCase
|
||||
->assertJsonPath('data.0.ticket', $matching->ticket);
|
||||
}
|
||||
|
||||
public function test_it_sorts_the_complete_filtered_result_before_paginating(): void
|
||||
{
|
||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||
$admin = $this->createAdminAppUser($tenant);
|
||||
$this->grantTicketsMenu($tenant);
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
foreach (['ticket-c', 'ticket-a', 'ticket-d', 'ticket-b'] as $value) {
|
||||
$this->createTicket($tenant, $admin)->update(['ticket' => $value]);
|
||||
}
|
||||
|
||||
$query = http_build_query([
|
||||
'sort_by' => 'ticket',
|
||||
'sort_direction' => 'asc',
|
||||
'per_page' => 2,
|
||||
]);
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/tickets?'.$query)
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.values.ticket', 'ticket-a')
|
||||
->assertJsonPath('data.1.values.ticket', 'ticket-b')
|
||||
->assertJsonPath('meta.total', 4)
|
||||
->assertJsonPath('meta.last_page', 2);
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/tickets?'.$query.'&page=2')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.values.ticket', 'ticket-c')
|
||||
->assertJsonPath('data.1.values.ticket', 'ticket-d');
|
||||
}
|
||||
|
||||
public function test_it_rejects_sort_columns_not_enabled_for_the_tenant(): void
|
||||
{
|
||||
$tenant = $this->createTenant('other');
|
||||
$this->grantTicketsMenu($tenant);
|
||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/tickets?sort_by=category&sort_direction=sideways')
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['sort_by', 'sort_direction']);
|
||||
}
|
||||
|
||||
public function test_it_includes_tenant_scanned_and_total_ticket_counts(): void
|
||||
{
|
||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||
|
||||
Reference in New Issue
Block a user