feat(tickets): add tenant-aware server-side sorting

This commit is contained in:
2026-08-31 13:45:57 -03:00
parent 6a00d8d09c
commit fa1e11a69f
5 changed files with 251 additions and 22 deletions

View File

@@ -107,6 +107,7 @@ class AdminAppTicketFilterFormControllerTest extends TestCase
->assertJsonPath('data.fields.4.name', 'status')
->assertJsonPath('data.fields.4.query_param', 'status')
->assertJsonPath('data.columns.0.key', 'order_number')
->assertJsonPath('data.columns.0.sort_param', 'order_number')
->assertJsonPath('data.columns.1.key', 'category')
->assertJsonPath('data.columns.2.key', 'product')
->assertJsonPath('data.columns.3.key', 'type');
@@ -244,14 +245,14 @@ class AdminAppTicketFilterFormControllerTest extends TestCase
private function commonColumns(): array
{
return [
['key' => 'order_number', 'label' => 'N° de orden', 'type' => 'order_number', 'sortable' => true, 'width' => '11%'],
['key' => 'product', 'label' => 'Producto', 'type' => 'text', 'sortable' => true, 'width' => '15%'],
['key' => 'amount', 'label' => 'Importe', 'type' => 'currency', 'sortable' => true, 'width' => '10%'],
['key' => 'client', 'label' => 'Cliente', 'type' => 'text', 'sortable' => true, 'width' => '15%'],
['key' => 'ticket', 'label' => 'ID', 'type' => 'text', 'sortable' => true, 'width' => '19%'],
['key' => 'date', 'label' => 'Fecha', 'type' => 'date', 'sortable' => true, 'width' => '11%'],
['key' => 'status', 'label' => 'Estado', 'type' => 'status', 'sortable' => true, 'width' => '8%'],
['key' => 'scanned_by', 'label' => 'Escaneado por', 'type' => 'text', 'sortable' => true, 'width' => '11%'],
['key' => 'order_number', 'label' => 'N° de orden', 'type' => 'order_number', 'sortable' => true, 'sort_param' => 'order_number', 'width' => '11%'],
['key' => 'product', 'label' => 'Producto', 'type' => 'text', 'sortable' => true, 'sort_param' => 'product', 'width' => '15%'],
['key' => 'amount', 'label' => 'Importe', 'type' => 'currency', 'sortable' => true, 'sort_param' => 'amount', 'width' => '10%'],
['key' => 'client', 'label' => 'Cliente', 'type' => 'text', 'sortable' => true, 'sort_param' => 'client', 'width' => '15%'],
['key' => 'ticket', 'label' => 'ID', 'type' => 'text', 'sortable' => true, 'sort_param' => 'ticket', 'width' => '19%'],
['key' => 'date', 'label' => 'Fecha', 'type' => 'date', 'sortable' => true, 'sort_param' => 'date', 'width' => '11%'],
['key' => 'status', 'label' => 'Estado', 'type' => 'status', 'sortable' => true, 'sort_param' => 'status', 'width' => '8%'],
['key' => 'scanned_by', 'label' => 'Escaneado por', 'type' => 'text', 'sortable' => true, 'sort_param' => 'scanned_by', 'width' => '11%'],
];
}

View File

@@ -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');