test(desfile): cover reservation cancellation
This commit is contained in:
@@ -82,6 +82,7 @@ class EntryReservationServiceTest extends TestCase
|
||||
Schema::create('attribute', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('codigo');
|
||||
$table->string('type')->default('string');
|
||||
});
|
||||
Schema::create('item_attributes', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
@@ -117,9 +118,24 @@ class EntryReservationServiceTest extends TestCase
|
||||
$table->unsignedBigInteger('source_purchase_item_id')->nullable();
|
||||
$table->unsignedBigInteger('event_id')->nullable();
|
||||
$table->timestamp('used_at')->nullable();
|
||||
$table->timestamp('disabled_at')->nullable();
|
||||
$table->timestamp('cancelled_at')->nullable();
|
||||
$table->timestamp('refunded_at')->nullable();
|
||||
});
|
||||
Schema::create('value_changes', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->morphs('trackable');
|
||||
$table->string('tenant_code');
|
||||
$table->string('attribute');
|
||||
$table->text('old_value')->nullable();
|
||||
$table->text('new_value')->nullable();
|
||||
$table->timestamp('changed_at');
|
||||
$table->string('actor_type');
|
||||
$table->foreignId('user_id')->nullable();
|
||||
});
|
||||
(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();
|
||||
DB::table('tenants')->insert(['codigo' => 'desfile_pura_tendencia']);
|
||||
DB::table('users')->insert(['id' => 1, 'tenant_codigo' => 'desfile_pura_tendencia']);
|
||||
DB::table('catalog_items')->insert([
|
||||
@@ -157,7 +173,11 @@ class EntryReservationServiceTest extends TestCase
|
||||
throw new \RuntimeException('Ticket generation failed');
|
||||
}
|
||||
$this->assertSame(1, $quantity);
|
||||
$id = DB::table('tickets')->insertGetId(['user_id' => $user->id, 'source_variant_id' => $variantId]);
|
||||
$id = DB::table('tickets')->insertGetId([
|
||||
'user_id' => $user->id,
|
||||
'source_variant_id' => $variantId,
|
||||
'tenant_code' => $user->tenant_codigo,
|
||||
]);
|
||||
|
||||
return collect([Ticket::query()->findOrFail($id)]);
|
||||
});
|
||||
@@ -230,6 +250,43 @@ class EntryReservationServiceTest extends TestCase
|
||||
$service->reserve($user, (string) Str::uuid(), $this->rows());
|
||||
}
|
||||
|
||||
public function test_it_cancels_the_ticket_releases_stock_and_soft_deletes_the_reservation(): void
|
||||
{
|
||||
$service = $this->service();
|
||||
$user = User::findOrFail(1);
|
||||
$reservation = $service->reserve($user, (string) Str::uuid(), [$this->rows()[0]])->sole();
|
||||
|
||||
$service->cancel($user, $reservation->id);
|
||||
|
||||
$this->assertSoftDeleted('desfile_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());
|
||||
$this->assertSame(0, $service->reservations($user)->total());
|
||||
$this->assertCount(0, $service->reservationsForExport($user));
|
||||
}
|
||||
|
||||
public function test_it_does_not_release_stock_when_the_ticket_is_not_active(): void
|
||||
{
|
||||
$service = $this->service();
|
||||
$user = User::findOrFail(1);
|
||||
$reservation = $service->reserve($user, (string) Str::uuid(), [$this->rows()[0]])->sole();
|
||||
Ticket::query()->whereKey($reservation->ticket_id)->update(['used_at' => now()]);
|
||||
|
||||
try {
|
||||
$service->cancel($user, $reservation->id);
|
||||
$this->fail('Expected cancellation validation error');
|
||||
} catch (ValidationException $error) {
|
||||
$this->assertArrayHasKey('status', $error->errors());
|
||||
}
|
||||
|
||||
$this->assertDatabaseHas('desfile_entry_reservations', [
|
||||
'id' => $reservation->id,
|
||||
'deleted_at' => null,
|
||||
]);
|
||||
$this->assertSame(1, Inventory::findOrFail(1)->entry_reserved_stock);
|
||||
}
|
||||
|
||||
public function test_a_reused_key_with_different_rows_is_rejected(): void
|
||||
{
|
||||
$service = $this->service();
|
||||
|
||||
@@ -22,6 +22,9 @@ class EntryReservationTest extends TestCase
|
||||
|
||||
$this->assertSame([
|
||||
'variant_id',
|
||||
'ticket_id',
|
||||
'inventory_id',
|
||||
'batch_id',
|
||||
'fecha_reserva',
|
||||
'importe',
|
||||
'tipo_pago',
|
||||
|
||||
Reference in New Issue
Block a user