feat(tickets): enhance AdminAppTicketIndexRequest and AdminAppTicketService with additional filters and update tests for ticket filtering functionality
This commit is contained in:
@@ -181,7 +181,7 @@ class AdminAppTicketFilterFormControllerTest extends TestCase
|
||||
});
|
||||
$this->assertNotNull($historicalVariant);
|
||||
|
||||
Ticket::query()->create([
|
||||
$ticket = Ticket::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'ticket' => (string) Str::uuid(),
|
||||
'user_id' => $admin->id,
|
||||
@@ -206,6 +206,15 @@ class AdminAppTicketFilterFormControllerTest extends TestCase
|
||||
['Cena'],
|
||||
collect($products->first()['children']['options'])->pluck('label')->all(),
|
||||
);
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/tickets?'.http_build_query([
|
||||
'category' => 'comidas',
|
||||
'product' => $products->first()['value'],
|
||||
'type' => 'Cena',
|
||||
]))
|
||||
->assertOk()
|
||||
->assertJsonCount(1, 'data')
|
||||
->assertJsonPath('data.0.id', $ticket->id);
|
||||
}
|
||||
|
||||
private function createFiestaFutbolInfantilTenant(): Tenant
|
||||
|
||||
@@ -17,7 +17,9 @@ use App\Domains\Shared\Enums\FieldType;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Tenant\Models\WebsiteType;
|
||||
use App\Domains\Ticket\Models\Ticket;
|
||||
use Database\Seeders\AttributeSeeder;
|
||||
use Database\Seeders\AuthorizationSeeder;
|
||||
use Database\Seeders\FiestaFutbolInfantilProductSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
@@ -188,6 +190,100 @@ class AdminAppTicketControllerTest extends TestCase
|
||||
->assertJsonPath('data.0.variant_properties.0.values.0.label', 'XL');
|
||||
}
|
||||
|
||||
public function test_it_applies_the_ticket_filter_form_values(): void
|
||||
{
|
||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||
$admin = $this->createAdminAppUser($tenant);
|
||||
$this->grantTicketsMenu($tenant);
|
||||
$this->seed([AttributeSeeder::class, FiestaFutbolInfantilProductSeeder::class]);
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$date = $tenant->eventDates()->orderByDesc('date')->firstOrFail();
|
||||
$food = CatalogItem::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('slug', 'comida')
|
||||
->with([
|
||||
'variants.definitions.itemAttribute.attribute.options',
|
||||
'variants.eventDates',
|
||||
'variants.eventDate',
|
||||
])
|
||||
->firstOrFail();
|
||||
$dinner = $food->variants->first(fn (Variant $variant): bool => $variant
|
||||
->selectedEventDates()->contains('id', $date->id)
|
||||
&& $variant->selectionValues()->get('horario') === 'Cena');
|
||||
$lunch = $food->variants->first(fn (Variant $variant): bool => $variant
|
||||
->selectedEventDates()->contains('id', $date->id)
|
||||
&& $variant->selectionValues()->get('horario') === 'Almuerzo');
|
||||
$this->assertNotNull($dinner);
|
||||
$this->assertNotNull($lunch);
|
||||
|
||||
$matchingPurchase = $this->createPurchase($tenant, $admin, '2026-08-20 10:00:00');
|
||||
$otherPurchase = $this->createPurchase($tenant, $admin, '2026-08-21 10:00:00');
|
||||
$matching = $this->createTicket($tenant, $admin, [
|
||||
'source_purchase_id' => $matchingPurchase->id,
|
||||
'source_catalog_item_id' => $food->id,
|
||||
'source_variant_id' => $dinner->id,
|
||||
'used_at' => now(),
|
||||
]);
|
||||
$this->createTicket($tenant, $admin, [
|
||||
'source_purchase_id' => $matchingPurchase->id,
|
||||
'source_catalog_item_id' => $food->id,
|
||||
'source_variant_id' => $lunch->id,
|
||||
'used_at' => now(),
|
||||
]);
|
||||
$this->createTicket($tenant, $admin, [
|
||||
'source_purchase_id' => $otherPurchase->id,
|
||||
'source_catalog_item_id' => $food->id,
|
||||
'source_variant_id' => $dinner->id,
|
||||
'used_at' => now(),
|
||||
]);
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/tickets?'.http_build_query([
|
||||
'category' => 'comidas',
|
||||
'product' => (string) $date->id,
|
||||
'type' => 'Cena',
|
||||
'date' => '2026-08-20',
|
||||
'status' => Ticket::STATUS_USED,
|
||||
]))
|
||||
->assertOk()
|
||||
->assertJsonCount(1, 'data')
|
||||
->assertJsonPath('data.0.id', $matching->id)
|
||||
->assertJsonPath('scanned_tickets', 1)
|
||||
->assertJsonPath('total_tickets', 1);
|
||||
}
|
||||
|
||||
public function test_it_filters_computed_active_and_expired_statuses(): void
|
||||
{
|
||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||
$admin = $this->createAdminAppUser($tenant);
|
||||
$this->grantTicketsMenu($tenant);
|
||||
$this->seed([AttributeSeeder::class, FiestaFutbolInfantilProductSeeder::class]);
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$food = CatalogItem::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('slug', 'comida')
|
||||
->with('variants')
|
||||
->firstOrFail();
|
||||
$expired = $this->createTicket($tenant, $admin, [
|
||||
'source_catalog_item_id' => $food->id,
|
||||
'source_variant_id' => $food->variants->firstOrFail()->id,
|
||||
]);
|
||||
$active = $this->createTicket($tenant, $admin);
|
||||
|
||||
$this->travelTo('2026-10-20 12:00:00');
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/tickets?status=expired')
|
||||
->assertOk()
|
||||
->assertJsonCount(1, 'data')
|
||||
->assertJsonPath('data.0.id', $expired->id);
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/tickets?status=active')
|
||||
->assertOk()
|
||||
->assertJsonCount(1, 'data')
|
||||
->assertJsonPath('data.0.id', $active->id);
|
||||
}
|
||||
|
||||
private function createTenant(string $code): Tenant
|
||||
{
|
||||
$headerLogo = $this->createAttachment("{$code}-header.png");
|
||||
@@ -227,6 +323,20 @@ class AdminAppTicketControllerTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
private function createPurchase(Tenant $tenant, User $user, string $createdAt): Purchase
|
||||
{
|
||||
$purchase = Purchase::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'user_id' => $user->id,
|
||||
'status' => Purchase::STATUS_PAID,
|
||||
'nombre_apellido' => $user->nombre_apellido,
|
||||
'total' => '0.00',
|
||||
]);
|
||||
$purchase->forceFill(['created_at' => $createdAt, 'updated_at' => $createdAt])->saveQuietly();
|
||||
|
||||
return $purchase;
|
||||
}
|
||||
|
||||
private function grantTicketsMenu(Tenant $tenant): void
|
||||
{
|
||||
$menu = Menu::query()->create([
|
||||
|
||||
Reference in New Issue
Block a user