feat(desfile): associate tickets menu with desfile tenant and add migration test
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Migrations;
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AssociateAdminAppTicketsMenuWithDesfileTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Schema::create('menues', function (Blueprint $table): void {
|
||||
$table->string('code')->primary();
|
||||
});
|
||||
Schema::create('tenants', function (Blueprint $table): void {
|
||||
$table->string('codigo')->primary();
|
||||
});
|
||||
Schema::create('tenants_menues', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('tenant_code');
|
||||
$table->string('menu_code');
|
||||
$table->json('static_content')->nullable();
|
||||
$table->timestamps();
|
||||
$table->unique(['tenant_code', 'menu_code']);
|
||||
});
|
||||
|
||||
DB::table('menues')->insert(['code' => 'adminapp.tickets']);
|
||||
DB::table('tenants')->insert([
|
||||
['codigo' => 'desfile_pura_tendencia'],
|
||||
['codigo' => 'fiesta_futbol_infantil'],
|
||||
]);
|
||||
DB::table('tenants_menues')->insert([
|
||||
'tenant_code' => 'fiesta_futbol_infantil',
|
||||
'menu_code' => 'adminapp.tickets',
|
||||
]);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Schema::dropIfExists('tenants_menues');
|
||||
Schema::dropIfExists('tenants');
|
||||
Schema::dropIfExists('menues');
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_it_associates_the_tickets_menu_only_with_desfile_and_rolls_back_that_association(): void
|
||||
{
|
||||
$migration = require database_path(
|
||||
'migrations/2026_09_25_000000_associate_adminapp_tickets_menu_with_desfile.php'
|
||||
);
|
||||
|
||||
$migration->down();
|
||||
$migration->up();
|
||||
$migration->up();
|
||||
|
||||
$this->assertSame(1, DB::table('tenants_menues')
|
||||
->where('tenant_code', 'desfile_pura_tendencia')
|
||||
->where('menu_code', 'adminapp.tickets')
|
||||
->count());
|
||||
$this->assertDatabaseHas('tenants_menues', [
|
||||
'tenant_code' => 'fiesta_futbol_infantil',
|
||||
'menu_code' => 'adminapp.tickets',
|
||||
]);
|
||||
|
||||
$migration->down();
|
||||
|
||||
$this->assertDatabaseMissing('tenants_menues', [
|
||||
'tenant_code' => 'desfile_pura_tendencia',
|
||||
'menu_code' => 'adminapp.tickets',
|
||||
]);
|
||||
$this->assertDatabaseHas('tenants_menues', [
|
||||
'tenant_code' => 'fiesta_futbol_infantil',
|
||||
'menu_code' => 'adminapp.tickets',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
namespace Tests\Feature\Ticket;
|
||||
|
||||
use App\Shared\Attachable\Enums\AttachmentType;
|
||||
use App\Shared\Attachable\Models\Attachment;
|
||||
use App\Domains\Core\Auth\Models\User;
|
||||
use App\Domains\Core\Authorization\Enums\RoleCode;
|
||||
use App\Domains\Commerce\Catalog\Models\Attribute;
|
||||
use App\Domains\Commerce\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Commerce\Catalog\Models\Inventory;
|
||||
use App\Domains\Commerce\Catalog\Models\Variant;
|
||||
use App\Domains\Core\Menu\Models\Menu;
|
||||
use App\Domains\Commerce\Purchase\Models\Purchase;
|
||||
use App\Domains\Commerce\Purchase\Models\PurchaseItem;
|
||||
use App\Shared\Enums\FieldType;
|
||||
use App\Domains\Core\Tenant\Models\Tenant;
|
||||
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\AdminWebsiteType;
|
||||
use App\Domains\Core\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticketing\Ticket\Models\Ticket;
|
||||
use App\Domains\Ticketing\Ticket\Models\TicketRefund;
|
||||
use App\Shared\Attachable\Enums\AttachmentType;
|
||||
use App\Shared\Attachable\Models\Attachment;
|
||||
use App\Shared\Enums\FieldType;
|
||||
use Barryvdh\DomPDF\ServiceProvider as DomPdfServiceProvider;
|
||||
use Database\Seeders\AttributeSeeder;
|
||||
use Database\Seeders\AuthorizationSeeder;
|
||||
@@ -840,6 +840,103 @@ class AdminAppTicketControllerTest extends TestCase
|
||||
->assertJsonPath('data.0.variant_properties.0.values.0.label', 'XL');
|
||||
}
|
||||
|
||||
public function test_desfile_exposes_and_applies_filters_and_columns_from_ticket_product_attributes(): void
|
||||
{
|
||||
$tenant = $this->createTenant('desfile_pura_tendencia');
|
||||
$admin = $this->createAdminAppUser($tenant);
|
||||
$this->grantTicketsMenu($tenant);
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$item = CatalogItem::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'slug' => 'entrada',
|
||||
'nombre' => 'Entrada',
|
||||
'precio' => '1000.00',
|
||||
'has_tickets' => true,
|
||||
]);
|
||||
$type = Attribute::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'codigo' => 'tipo',
|
||||
'nombre' => 'Tipo',
|
||||
'type' => FieldType::Select,
|
||||
]);
|
||||
$type->options()->create(['value' => 'vip', 'label' => 'VIP']);
|
||||
$sector = Attribute::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'codigo' => 'sector',
|
||||
'nombre' => 'Sector',
|
||||
'type' => FieldType::Select,
|
||||
]);
|
||||
$sector->options()->createMany([
|
||||
['value' => 'a', 'label' => 'A'],
|
||||
['value' => 'b', 'label' => 'B'],
|
||||
]);
|
||||
$typeItemAttribute = $item->itemAttributes()->create([
|
||||
'attribute_id' => $type->id,
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
$sectorItemAttribute = $item->itemAttributes()->create([
|
||||
'attribute_id' => $sector->id,
|
||||
'sort_order' => 2,
|
||||
'ticket_label' => 'Lado',
|
||||
]);
|
||||
|
||||
$variants = collect(['a', 'b'])->map(function (string $sectorValue) use (
|
||||
$item,
|
||||
$typeItemAttribute,
|
||||
$sectorItemAttribute,
|
||||
): Variant {
|
||||
$variant = Variant::query()->create([
|
||||
'catalog_item_id' => $item->id,
|
||||
'inventory_id' => Inventory::query()->create()->id,
|
||||
]);
|
||||
$variant->definitions()->createMany([
|
||||
['item_attribute_id' => $typeItemAttribute->id, 'value' => 'vip'],
|
||||
['item_attribute_id' => $sectorItemAttribute->id, 'value' => $sectorValue],
|
||||
]);
|
||||
|
||||
return $variant;
|
||||
});
|
||||
|
||||
$purchase = $this->createPurchase($tenant, $admin, '2026-09-25 10:00:00');
|
||||
$matchingItem = $this->createPurchaseItem($purchase, $item, $variants[0]);
|
||||
$otherItem = $this->createPurchaseItem($purchase, $item, $variants[1]);
|
||||
$matching = $this->createTicket($tenant, $admin, [
|
||||
'source_purchase_item_id' => $matchingItem->id,
|
||||
'source_catalog_item_id' => $item->id,
|
||||
'source_variant_id' => $variants[0]->id,
|
||||
]);
|
||||
$this->createTicket($tenant, $admin, [
|
||||
'source_purchase_item_id' => $otherItem->id,
|
||||
'source_catalog_item_id' => $item->id,
|
||||
'source_variant_id' => $variants[1]->id,
|
||||
]);
|
||||
|
||||
$this->getJson('/api/v1/adminapp/forms/tickets-filter')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.fields.0.name', 'tipo')
|
||||
->assertJsonPath('data.fields.0.label', 'Tipo')
|
||||
->assertJsonPath('data.fields.0.options.0', ['value' => 'vip', 'label' => 'VIP'])
|
||||
->assertJsonPath('data.fields.1.name', 'sector')
|
||||
->assertJsonPath('data.fields.1.label', 'Lado')
|
||||
->assertJsonPath('data.columns.1.key', 'product')
|
||||
->assertJsonPath('data.columns.2.key', 'tipo')
|
||||
->assertJsonPath('data.columns.2.sortable', false)
|
||||
->assertJsonPath('data.columns.3.key', 'sector')
|
||||
->assertJsonPath('data.columns.3.label', 'Lado');
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/tickets?tipo=vip§or=a')
|
||||
->assertOk()
|
||||
->assertJsonCount(1, 'data')
|
||||
->assertJsonPath('data.0.id', $matching->id)
|
||||
->assertJsonPath('data.0.values.tipo', 'VIP')
|
||||
->assertJsonPath('data.0.values.sector', 'A');
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/tickets?sector=invalid')
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors('sector');
|
||||
}
|
||||
|
||||
public function test_it_applies_the_ticket_filter_form_values(): void
|
||||
{
|
||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||
|
||||
Reference in New Issue
Block a user