Refactor entry reservation handling by generalizing ticket reservations
- Renamed `desfile_entry_reservations` to `entry_reservations` and `desfile_reservation_batches` to `reservation_batches`. - Updated models, services, and requests to use the new `EntryReservation` model from the `Ticket` domain instead of the deleted `Desfile` model. - Introduced a new `EntryReservationPaymentType` enum to manage payment types. - Modified database migrations to ensure data integrity during the transition. - Updated tests to reflect changes in the database schema and model relationships. - Ensured that existing functionality remains intact while improving code organization and clarity.
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Desfile;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EntryReservationSchemaTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_the_entry_reservations_table_has_the_requested_columns(): void
|
||||
{
|
||||
$this->assertTrue(Schema::hasColumns('desfile_entry_reservations', [
|
||||
'id',
|
||||
'variant_id',
|
||||
'fecha_reserva',
|
||||
'importe',
|
||||
'tipo_pago',
|
||||
]));
|
||||
}
|
||||
}
|
||||
@@ -136,6 +136,7 @@ class EntryReservationServiceTest extends TestCase
|
||||
(require database_path('migrations/2026_09_23_010000_create_desfile_entry_reservations_table.php'))->up();
|
||||
(require database_path('migrations/2026_09_24_000000_add_administrative_entry_reservation_stock.php'))->up();
|
||||
(require database_path('migrations/2026_09_24_010000_add_soft_deletes_to_desfile_entry_reservations_table.php'))->up();
|
||||
(require database_path('migrations/2026_10_02_000000_generalize_ticket_reservations.php'))->up();
|
||||
DB::table('tenants')->insert(['codigo' => 'desfile_pura_tendencia']);
|
||||
DB::table('users')->insert(['id' => 1, 'tenant_codigo' => 'desfile_pura_tendencia']);
|
||||
DB::table('catalog_items')->insert([
|
||||
@@ -200,8 +201,8 @@ class EntryReservationServiceTest extends TestCase
|
||||
$replayed = $service->reserve($user, $key, $this->rows());
|
||||
$this->assertSame($result->pluck('id')->all(), $replayed->pluck('id')->all());
|
||||
$this->assertDatabaseCount('tickets', 2);
|
||||
$this->assertDatabaseCount('desfile_entry_reservations', 2);
|
||||
$this->assertDatabaseCount('desfile_reservation_batches', 1);
|
||||
$this->assertDatabaseCount('entry_reservations', 2);
|
||||
$this->assertDatabaseCount('reservation_batches', 1);
|
||||
foreach (Inventory::all() as $inventory) {
|
||||
$this->assertSame(1, $inventory->entry_reserved_stock);
|
||||
$this->assertSame(1, $inventory->real_stock);
|
||||
@@ -223,7 +224,7 @@ class EntryReservationServiceTest extends TestCase
|
||||
$this->assertStringContainsString('Tipo: NORMAL, Sector: A, Fila: 3, Asiento: 17', $error->errors()['rows.1.variant_id'][0]);
|
||||
}
|
||||
$this->assertDatabaseCount('tickets', 0);
|
||||
$this->assertDatabaseCount('desfile_entry_reservations', 0);
|
||||
$this->assertDatabaseCount('entry_reservations', 0);
|
||||
$this->assertSame(0, (int) Inventory::sum('entry_reserved_stock'));
|
||||
}
|
||||
|
||||
@@ -236,8 +237,8 @@ class EntryReservationServiceTest extends TestCase
|
||||
$this->assertSame('Ticket generation failed', $error->getMessage());
|
||||
}
|
||||
$this->assertDatabaseCount('tickets', 0);
|
||||
$this->assertDatabaseCount('desfile_entry_reservations', 0);
|
||||
$this->assertDatabaseCount('desfile_reservation_batches', 0);
|
||||
$this->assertDatabaseCount('entry_reservations', 0);
|
||||
$this->assertDatabaseCount('reservation_batches', 0);
|
||||
$this->assertSame(0, (int) Inventory::sum('entry_reserved_stock'));
|
||||
}
|
||||
|
||||
@@ -258,7 +259,7 @@ class EntryReservationServiceTest extends TestCase
|
||||
|
||||
$service->cancel($user, $reservation->id);
|
||||
|
||||
$this->assertSoftDeleted('desfile_entry_reservations', ['id' => $reservation->id]);
|
||||
$this->assertSoftDeleted('entry_reservations', ['id' => $reservation->id]);
|
||||
$this->assertNotNull(Ticket::findOrFail($reservation->ticket_id)->cancelled_at);
|
||||
$this->assertSame(0, Inventory::findOrFail(1)->entry_reserved_stock);
|
||||
$this->assertSame(1, Inventory::findOrFail(1)->availableStock());
|
||||
@@ -280,7 +281,7 @@ class EntryReservationServiceTest extends TestCase
|
||||
$this->assertArrayHasKey('status', $error->errors());
|
||||
}
|
||||
|
||||
$this->assertDatabaseHas('desfile_entry_reservations', [
|
||||
$this->assertDatabaseHas('entry_reservations', [
|
||||
'id' => $reservation->id,
|
||||
'deleted_at' => null,
|
||||
]);
|
||||
@@ -443,6 +444,7 @@ class EntryReservationServiceTest extends TestCase
|
||||
$service = new EntryReservationService(new TicketGeneratorService($validity));
|
||||
$result = $service->reserve(User::findOrFail(1), (string) Str::uuid(), $this->rows());
|
||||
foreach ($result as $reservation) {
|
||||
$this->assertSame(1, $reservation->catalog_item_id);
|
||||
$this->assertDatabaseHas('tickets', [
|
||||
'id' => $reservation->ticket_id, 'user_id' => 1,
|
||||
'source_variant_id' => $reservation->variant_id,
|
||||
|
||||
Reference in New Issue
Block a user