feat(invitation): implement InvitationPurchaseProvisioner and related migration and seeder updates

This commit is contained in:
2026-08-19 14:33:08 -03:00
parent 16bc657a31
commit 2632a80722
4 changed files with 516 additions and 9 deletions

View File

@@ -216,12 +216,18 @@ class DesfilePuraTendenciaSeederTest extends TestCase
->whereIn('variant_id', (clone $variants)->pluck('id'))
->count());
$this->assertSame(330, (clone $variants)->whereNull('event_date_id')->count());
$this->assertSame(330, DB::table('inventories')
$this->assertSame(284, DB::table('inventories')
->whereIn('id', (clone $variants)->pluck('inventory_id'))
->where('real_stock', 1)
->where('reserved_stock', 0)
->where('sold_units', 0)
->count());
$this->assertSame(46, DB::table('inventories')
->whereIn('id', (clone $variants)->pluck('inventory_id'))
->where('real_stock', 0)
->where('reserved_stock', 0)
->where('sold_units', 1)
->count());
$this->assertDatabaseHas('variantes', [
'catalog_item_id' => $catalogItem->id,
'descripcion' => 'Sector A - Fila 1 - Asiento 17 - VIP + LUNCH',
@@ -247,7 +253,7 @@ class DesfilePuraTendenciaSeederTest extends TestCase
'sector' => ['B', 'D'],
'asiento' => ['17'],
]));
$this->assertSame(66, $this->variantCountForSelection($catalogItem->id, [
$this->assertSame(50, $this->variantCountForSelection($catalogItem->id, [
'tipo' => ['VIP + LUNCH'],
'fila' => ['1'],
]));
@@ -255,6 +261,71 @@ class DesfilePuraTendenciaSeederTest extends TestCase
'tipo' => ['NORMAL'],
'fila' => ['5'],
]));
$this->assertInvitationPurchase($catalogItem->id);
$this->seed(DesfilePuraTendenciaSeeder::class);
$this->assertInvitationPurchase($catalogItem->id);
}
private function assertInvitationPurchase(int $catalogItemId): void
{
$user = DB::table('users')->where('email', 'invitados@puratendencia.com')->sole();
$this->assertSame('user', $user->rol_codigo);
$this->assertSame('desfile_pura_tendencia', $user->tenant_codigo);
$purchase = DB::table('compras')
->where('tenant_codigo', 'desfile_pura_tendencia')
->where('user_id', $user->id)
->where('payment_method', 'invitation')
->sole();
$this->assertSame('paid', $purchase->status);
$this->assertEquals(0, $purchase->total);
$items = DB::table('compra_items')->where('compra_id', $purchase->id);
$this->assertSame(46, (clone $items)->count());
$this->assertSame(46, (clone $items)
->where('precio_unitario', 0)
->where('discount_total', 0)
->where('tax_total', 0)
->where('total', 0)
->count());
$this->assertSame(46, DB::table('tickets')
->where('source_purchase_id', $purchase->id)
->where('user_id', $user->id)
->where('source_catalog_item_id', $catalogItemId)
->count());
$this->assertSame(46, DB::table('stock_reservations')
->where('purchase_id', $purchase->id)
->where('status', 'committed')
->count());
foreach ([
['sector' => 'A', 'fila' => '1', 'tipo' => 'NORMAL', 'count' => 16],
['sector' => 'A', 'fila' => '3', 'tipo' => 'NORMAL', 'count' => 14],
['sector' => 'C', 'fila' => '1', 'tipo' => 'VIP + LUNCH', 'count' => 16],
] as $allocation) {
$allocatedVariants = DB::table('variantes')
->where('catalog_item_id', $catalogItemId)
->whereIn('id', (clone $items)->pluck('source_variant_id'));
foreach (['sector', 'fila', 'tipo'] as $code) {
$allocatedVariants->whereExists(fn ($query) => $query
->selectRaw('1')
->from('variant_values')
->join('item_attributes', 'item_attributes.id', '=', 'variant_values.item_attribute_id')
->join('attribute', 'attribute.id', '=', 'item_attributes.attribute_id')
->whereColumn('variant_values.variant_id', 'variantes.id')
->where('attribute.codigo', $code)
->where('variant_values.value', $allocation[$code]));
}
$this->assertSame($allocation['count'], $allocatedVariants->count());
}
}
/** @param array<string, list<string>> $selection */