feat(desfile): enhance entry reservation form and service with tenant-specific data

This commit is contained in:
2026-09-23 16:55:35 -03:00
parent 5e78f2bb1e
commit 3671b95a83
6 changed files with 170 additions and 6 deletions

View File

@@ -2,10 +2,14 @@
namespace Tests\Feature\Forms;
use App\Domains\Commerce\Catalog\Models\Attribute;
use App\Domains\Commerce\Catalog\Models\CatalogItem;
use App\Domains\Commerce\Catalog\Models\Inventory;
use App\Domains\Core\Auth\Models\User;
use App\Domains\Core\Authorization\Enums\RoleCode;
use App\Domains\Core\Menu\Models\Menu;
use App\Domains\Core\Tenant\Models\Tenant;
use App\Shared\Enums\FieldType;
use Database\Seeders\AuthorizationSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Sanctum\Sanctum;
@@ -37,7 +41,7 @@ class AdminAppDesfileEntryReservationFormControllerTest extends TestCase
->assertNotFound();
}
public function test_it_only_returns_the_available_payment_types(): void
public function test_it_returns_payment_types_and_empty_variant_options_without_a_catalog(): void
{
$tenant = $this->createTenant('desfile_pura_tendencia');
$this->grantReservationsMenu($tenant);
@@ -51,10 +55,66 @@ class AdminAppDesfileEntryReservationFormControllerTest extends TestCase
['value' => 'sin_cargo', 'label' => 'Sin cargo'],
['value' => 'otro_metodo', 'label' => 'Otro método'],
],
'fields' => [
['key' => 'tipo', 'label' => 'Tipo', 'options' => []],
['key' => 'sector', 'label' => 'Sector', 'options' => []],
['key' => 'fila', 'label' => 'Fila', 'options' => []],
['key' => 'asiento', 'label' => 'Asiento', 'options' => []],
],
'variants' => [],
],
]);
}
public function test_it_returns_only_available_combinations_without_reserving_stock(): void
{
$tenant = $this->createTenant('desfile_pura_tendencia');
$this->grantReservationsMenu($tenant);
Sanctum::actingAs($this->createAdminAppUser($tenant));
$entry = CatalogItem::query()->create([
'tenant_code' => $tenant->codigo, 'slug' => 'entrada', 'nombre' => 'Entrada', 'precio' => 100,
]);
$attributes = [];
foreach (['tipo', 'sector', 'fila', 'asiento'] as $code) {
$attribute = Attribute::query()->create([
'tenant_codigo' => $tenant->codigo, 'codigo' => $code,
'nombre' => $code, 'type' => FieldType::Select,
]);
$attributes[$code] = $entry->itemAttributes()->create(['attribute_id' => $attribute->id]);
}
$availableId = null;
foreach (['available', 'reserved', 'sold', 'disabled', 'administrative'] as $index => $state) {
$inventory = Inventory::query()->create([
'real_stock' => $state === 'sold' ? 0 : 1,
'reserved_stock' => $state === 'reserved' ? 1 : 0,
]);
$variant = $entry->variants()->create([
'inventory_id' => $inventory->id, 'precio' => 100,
'sales_disabled_at' => $state === 'disabled' ? now() : null,
]);
foreach ($attributes as $code => $attribute) {
$variant->definitions()->create([
'item_attribute_id' => $attribute->id,
'value' => $code === 'asiento' ? (string) ($index + 1) : '1',
]);
}
if ($state === 'administrative') {
$variant->desfileEntryReservations()->create([
'fecha_reserva' => now(), 'importe' => 0, 'tipo_pago' => 'sin_cargo',
]);
}
if ($state === 'available') {
$availableId = $variant->id;
}
}
$this->getJson('/api/v1/adminapp/forms/desfile/entry-reservation')
->assertOk()->assertJsonCount(1, 'data.variants')
->assertJsonPath('data.variants.0.id', $availableId)
->assertJsonPath('data.fields.3.options', [['value' => '1', 'label' => '1']]);
$this->assertDatabaseCount('desfile_entry_reservations', 1);
$this->assertSame(1, (int) Inventory::query()->sum('reserved_stock'));
}
private function createTenant(string $code): Tenant
{
return Tenant::query()->create([