feat(desfile): list paginated entry reservations

This commit is contained in:
2026-09-24 10:02:26 -03:00
parent 5bb61fc74c
commit d8d8354070
6 changed files with 157 additions and 1 deletions

View File

@@ -4,13 +4,16 @@ namespace Tests\Feature\Desfile;
use App\Domains\Commerce\Catalog\Models\Inventory;
use App\Domains\Core\Auth\Models\User;
use App\Domains\Ticketing\Desfile\Requests\IndexEntryReservationsRequest;
use App\Domains\Ticketing\Desfile\Requests\StoreEntryReservationsRequest;
use App\Domains\Ticketing\Desfile\Resources\EntryReservationResource;
use App\Domains\Ticketing\Desfile\Services\EntryReservationService;
use App\Domains\Ticketing\Ticket\Models\Ticket;
use App\Domains\Ticketing\Ticket\Services\ResolvedTicketValidity;
use App\Domains\Ticketing\Ticket\Services\TicketGeneratorService;
use App\Domains\Ticketing\Ticket\Services\TicketValidityResolver;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Validator;
@@ -75,8 +78,17 @@ class EntryReservationServiceTest extends TestCase
});
Schema::create('item_attributes', function (Blueprint $table): void {
$table->id();
$table->foreignId('catalog_item_id');
$table->foreignId('attribute_id');
$table->boolean('allow_multi_select')->default(false);
$table->integer('sort_order')->default(0);
});
Schema::create('attribute_options', function (Blueprint $table): void {
$table->id();
$table->foreignId('attribute_id');
$table->string('value');
$table->string('label');
$table->integer('sort_order')->default(0);
});
Schema::create('variant_values', function (Blueprint $table): void {
$table->id();
@@ -113,7 +125,15 @@ class EntryReservationServiceTest extends TestCase
}
foreach (['tipo' => 'NORMAL', 'sector' => 'A', 'fila' => '3', 'asiento' => '17'] as $code => $value) {
$attributeId = DB::table('attribute')->insertGetId(['codigo' => $code]);
$itemAttributeId = DB::table('item_attributes')->insertGetId(['attribute_id' => $attributeId]);
$itemAttributeId = DB::table('item_attributes')->insertGetId([
'catalog_item_id' => 1,
'attribute_id' => $attributeId,
]);
DB::table('attribute_options')->insert([
'attribute_id' => $attributeId,
'value' => $value,
'label' => $value,
]);
foreach ([1, 2] as $variantId) {
DB::table('variant_values')->insert([
'variant_id' => $variantId, 'item_attribute_id' => $itemAttributeId, 'value' => $value,
@@ -247,6 +267,32 @@ class EntryReservationServiceTest extends TestCase
Inventory::findOrFail(1)->reserve(1, true);
}
public function test_lists_paginated_reservations_filtered_by_payment_type(): void
{
$service = $this->service();
$user = User::findOrFail(1);
$service->reserve($user, (string) Str::uuid(), $this->rows());
$reservations = $service->reservations($user, [
'tipo_pago' => 'otro_metodo',
'page' => 1,
'per_page' => 1,
]);
$this->assertSame(1, $reservations->total());
$this->assertSame(1, $reservations->perPage());
$reservation = $reservations->sole();
$this->assertSame('otro_metodo', $reservation->tipo_pago->value);
$this->assertNotNull($reservation->ticket_id);
$this->assertSame('NORMAL', $reservation->variant->selectionValues()->get('tipo'));
$payload = (new EntryReservationResource($reservation))->toArray(Request::create('/'));
$this->assertSame($reservation->id, $payload['id']);
$this->assertSame($reservation->ticket_id, $payload['ticket_id']);
$this->assertSame('NORMAL', $payload['entrada']['tipo']);
$this->assertSame('Otro método', $payload['tipo_pago_label']);
}
public function test_request_rejects_duplicate_variants_and_client_amounts(): void
{
$rules = (new StoreEntryReservationsRequest)->rules();
@@ -263,6 +309,21 @@ class EntryReservationServiceTest extends TestCase
$this->assertArrayHasKey('rows.1.tipo_pago', $validator->errors()->toArray());
}
public function test_index_request_validates_payment_type_and_pagination(): void
{
$validator = Validator::make([
'tipo_pago' => 'invalid',
'page' => 0,
'per_page' => 101,
], (new IndexEntryReservationsRequest)->rules());
$this->assertTrue($validator->fails());
$this->assertSame(
['tipo_pago', 'page', 'per_page'],
array_keys($validator->errors()->toArray()),
);
}
public function test_real_ticket_generator_links_admin_variant_and_reservation(): void
{
$validity = Mockery::mock(TicketValidityResolver::class);