feat(tenant): provision Desfile Pura Tendencia and extend tenant customization
- Add Desfile Pura Tendencia tenant migration with catalog, variants, event, menus and assets - Support tenant header/footer background images - Add configurable cart visibility - Update tenant seeding and API resources - Add migration and bootstrap feature tests
This commit is contained in:
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Migrations;
|
||||
|
||||
use Database\Seeders\MenuSeeder;
|
||||
use Database\Seeders\SocialMediaSeeder;
|
||||
use Database\Seeders\TenantSeeder;
|
||||
use Database\Seeders\WebsiteTypeSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateDesfilePuraTendenciaTenantTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_it_provisions_the_desfile_tenant_configuration(): void
|
||||
{
|
||||
Storage::fake('s3');
|
||||
|
||||
$this->seed([
|
||||
WebsiteTypeSeeder::class,
|
||||
SocialMediaSeeder::class,
|
||||
TenantSeeder::class,
|
||||
MenuSeeder::class,
|
||||
]);
|
||||
|
||||
$migration = require database_path(
|
||||
'migrations/2026_08_12_020000_create_desfile_pura_tendencia_tenant.php'
|
||||
);
|
||||
$migration->up();
|
||||
|
||||
$this->assertDatabaseHas('tenants', [
|
||||
'codigo' => 'desfile_pura_tendencia',
|
||||
'nombre' => 'Desfile Pura Tendencia',
|
||||
'dominio' => 'desfile-pura-tendencia.localhost',
|
||||
'website_type_code' => 'onticket',
|
||||
'event_title' => 'Desfile Pura Tendencia',
|
||||
'event_location' => 'Salón Centro Recreativo Luz y Fuerza',
|
||||
'event_date_text' => '16 de Octubre 2026',
|
||||
'primary_color' => '#BA69A9',
|
||||
'secondary_color' => '#A0A0A0',
|
||||
'danger_color' => '#FF8888',
|
||||
'success_color' => '#198754',
|
||||
'header_bg_color' => '#ffffff',
|
||||
'footer_bg_color' => '#D4441C',
|
||||
'display_categories' => false,
|
||||
'display_seach_bar' => false,
|
||||
]);
|
||||
|
||||
$eventDate = DB::table('event_dates')
|
||||
->where('tenant_code', 'desfile_pura_tendencia')
|
||||
->sole();
|
||||
|
||||
$this->assertSame('2026-10-16', $eventDate->date);
|
||||
$this->assertSame('20:30:00', $eventDate->time_start);
|
||||
$this->assertSame('23:59:00', $eventDate->time_end);
|
||||
$this->assertDatabaseHas('validity_times', [
|
||||
'id' => $eventDate->validity_time_id,
|
||||
'type' => 'fixed_window',
|
||||
'fixed_starts_at' => '2026-10-16 20:30:00',
|
||||
'fixed_expires_at' => '2026-10-16 23:59:00',
|
||||
]);
|
||||
|
||||
$hero = DB::table('websites_extras')
|
||||
->join(
|
||||
'website_type_extras',
|
||||
'website_type_extras.id',
|
||||
'=',
|
||||
'websites_extras.website_type_extra_id',
|
||||
)
|
||||
->where('websites_extras.website_code', 'desfile_pura_tendencia')
|
||||
->where('website_type_extras.codigo', 'heroConfig')
|
||||
->value('websites_extras.config');
|
||||
$hero = json_decode($hero, true, flags: JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->assertSame('<h1>LA NOCHE DE LA MODA</h1>', $hero['title_html']);
|
||||
$this->assertSame(
|
||||
'Viví una experiencia de <b>Alta Costura con conducción exclusiva de Pampita</b> y las colecciones de Pucheta-Paz.',
|
||||
$hero['description_html'],
|
||||
);
|
||||
$this->assertDatabaseHas('attachments', [
|
||||
'id' => $hero['background_image_id'],
|
||||
'filename' => 'desfile_pura_tendencia_hero.png',
|
||||
'type' => 'image',
|
||||
]);
|
||||
|
||||
foreach ([
|
||||
'desfile_pura_tendencia_header.png',
|
||||
'desfile_pura_tendencia_footer.png',
|
||||
'desfile_pura_tendencia_hero.png',
|
||||
'entrada_pasarela.png',
|
||||
] as $filename) {
|
||||
$path = DB::table('attachments')->where('filename', $filename)->value('path');
|
||||
|
||||
$this->assertNotNull($path);
|
||||
Storage::disk('s3')->assertExists($path);
|
||||
}
|
||||
|
||||
$expectedMenus = DB::table('tenants_menues')
|
||||
->where('tenant_code', 'fiesta_futbol_infantil')
|
||||
->where('menu_code', 'not like', 'adminapp.fiesta-futbol-infantil.%')
|
||||
->orderBy('menu_code')
|
||||
->pluck('menu_code')
|
||||
->all();
|
||||
$actualMenus = DB::table('tenants_menues')
|
||||
->where('tenant_code', 'desfile_pura_tendencia')
|
||||
->orderBy('menu_code')
|
||||
->pluck('menu_code')
|
||||
->all();
|
||||
|
||||
$this->assertSame($expectedMenus, $actualMenus);
|
||||
$this->assertContains('main.adminapp', $actualMenus);
|
||||
$this->assertContains('adminapp.event', $actualMenus);
|
||||
$this->assertContains('scanner.scan', $actualMenus);
|
||||
$this->assertNotContains('adminapp.fiesta-futbol-infantil.entradas', $actualMenus);
|
||||
|
||||
$catalogItem = DB::table('catalog_items')
|
||||
->where('tenant_code', 'desfile_pura_tendencia')
|
||||
->where('slug', 'entrada')
|
||||
->sole();
|
||||
|
||||
$this->assertSame('Entrada', $catalogItem->nombre);
|
||||
$this->assertSame('tracked', $catalogItem->inventory_policy);
|
||||
$this->assertSame(1, $catalogItem->has_tickets);
|
||||
$this->assertSame('one_per_unit', $catalogItem->ticket_generation_policy);
|
||||
$this->assertSame($eventDate->validity_time_id, $catalogItem->validity_time_id);
|
||||
$this->assertDatabaseHas('catalog_items_attachments', [
|
||||
'catalog_item_id' => $catalogItem->id,
|
||||
'variant_id' => null,
|
||||
'orden' => 0,
|
||||
]);
|
||||
$this->assertDatabaseHas('featured_groups', [
|
||||
'tenant_code' => 'desfile_pura_tendencia',
|
||||
'source_type' => 'all',
|
||||
'product_layout' => 'ticket_selector',
|
||||
'group_layout' => 'single',
|
||||
]);
|
||||
|
||||
$attributes = DB::table('attribute')
|
||||
->where('tenant_codigo', 'desfile_pura_tendencia')
|
||||
->orderBy('id')
|
||||
->get()
|
||||
->keyBy('codigo');
|
||||
|
||||
$this->assertSame(['tipo', 'sector', 'fila', 'asiento'], $attributes->keys()->all());
|
||||
$this->assertSame([
|
||||
'tipo' => ['VIP + LUNCH', 'NORMAL'],
|
||||
'sector' => ['A', 'B', 'C', 'D'],
|
||||
'fila' => array_map('strval', range(1, 17)),
|
||||
'asiento' => array_map('strval', range(1, 5)),
|
||||
], $attributes->map(fn (object $attribute): array => DB::table('attribute_options')
|
||||
->where('attribute_id', $attribute->id)
|
||||
->orderBy('sort_order')
|
||||
->pluck('value')
|
||||
->all())->all());
|
||||
|
||||
$variants = DB::table('variantes')->where('catalog_item_id', $catalogItem->id);
|
||||
|
||||
$this->assertSame(330, (clone $variants)->count());
|
||||
$this->assertSame(1320, DB::table('variant_values')
|
||||
->whereIn('variant_id', (clone $variants)->pluck('id'))
|
||||
->count());
|
||||
$this->assertSame(0, DB::table('variant_event_dates')
|
||||
->whereIn('variant_id', (clone $variants)->pluck('id'))
|
||||
->count());
|
||||
$this->assertSame(330, (clone $variants)->whereNull('event_date_id')->count());
|
||||
$this->assertSame(330, DB::table('inventories')
|
||||
->whereIn('id', (clone $variants)->pluck('inventory_id'))
|
||||
->where('real_stock', 1)
|
||||
->where('reserved_stock', 0)
|
||||
->where('sold_units', 0)
|
||||
->count());
|
||||
|
||||
foreach ([
|
||||
250000 => 34,
|
||||
200000 => 34,
|
||||
100000 => 34,
|
||||
75000 => 34,
|
||||
50000 => 34,
|
||||
240000 => 32,
|
||||
190000 => 32,
|
||||
90000 => 32,
|
||||
65000 => 32,
|
||||
40000 => 32,
|
||||
] as $price => $expectedCount) {
|
||||
$this->assertSame($expectedCount, (clone $variants)->where('precio', $price)->count());
|
||||
}
|
||||
|
||||
$this->assertSame(0, $this->variantCountForSelection($catalogItem->id, [
|
||||
'sector' => ['B', 'D'],
|
||||
'fila' => ['17'],
|
||||
]));
|
||||
$this->assertSame(66, $this->variantCountForSelection($catalogItem->id, [
|
||||
'tipo' => ['VIP + LUNCH'],
|
||||
'asiento' => ['1'],
|
||||
]));
|
||||
$this->assertSame(66, $this->variantCountForSelection($catalogItem->id, [
|
||||
'tipo' => ['NORMAL'],
|
||||
'asiento' => ['5'],
|
||||
]));
|
||||
}
|
||||
|
||||
/** @param array<string, list<string>> $selection */
|
||||
private function variantCountForSelection(int $catalogItemId, array $selection): int
|
||||
{
|
||||
$query = DB::table('variantes')->where('catalog_item_id', $catalogItemId);
|
||||
|
||||
foreach ($selection as $attributeCode => $values) {
|
||||
$query->whereExists(fn ($subquery) => $subquery
|
||||
->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', $attributeCode)
|
||||
->whereIn('variant_values.value', $values));
|
||||
}
|
||||
|
||||
return $query->count();
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,20 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
'type' => AttachmentType::Image,
|
||||
'mime_type' => 'image/png',
|
||||
]);
|
||||
$headerBackgroundAttachment = Attachment::create([
|
||||
'key' => (string) Str::uuid(),
|
||||
'path' => 'tenants/header-background.png',
|
||||
'filename' => 'header-background.png',
|
||||
'type' => AttachmentType::Image,
|
||||
'mime_type' => 'image/png',
|
||||
]);
|
||||
$footerBackgroundAttachment = Attachment::create([
|
||||
'key' => (string) Str::uuid(),
|
||||
'path' => 'tenants/footer-background.png',
|
||||
'filename' => 'footer-background.png',
|
||||
'type' => AttachmentType::Image,
|
||||
'mime_type' => 'image/png',
|
||||
]);
|
||||
|
||||
$tenant = Tenant::create([
|
||||
'codigo' => 'acme',
|
||||
@@ -52,9 +66,12 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
'footer_bg_color' => '#ffffff',
|
||||
'header_logo_id' => $headerAttachment->id,
|
||||
'footer_logo_id' => $footerAttachment->id,
|
||||
'header_bg_image_id' => $headerBackgroundAttachment->id,
|
||||
'footer_bg_image_id' => $footerBackgroundAttachment->id,
|
||||
'event_date_text' => '9, 10, 11 y 12 de Octubre 2026',
|
||||
'display_categories' => false,
|
||||
'display_seach_bar' => false,
|
||||
'display_cart' => false,
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/tenants/bootstrap/acme.com');
|
||||
@@ -70,13 +87,18 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
->assertJsonPath('data.event_date_text', '9, 10, 11 y 12 de Octubre 2026')
|
||||
->assertJsonPath('data.display_categories', false)
|
||||
->assertJsonPath('data.display_seach_bar', false)
|
||||
->assertJsonPath('data.display_cart', false)
|
||||
->assertJsonPath('data.header_bg_color', '#ffffff')->assertJsonPath('data.footer_bg_color', '#ffffff');
|
||||
|
||||
$headerUrl = $response->json('data.header_logo');
|
||||
$footerUrl = $response->json('data.footer_logo');
|
||||
$headerBackgroundUrl = $response->json('data.header_bg_image');
|
||||
$footerBackgroundUrl = $response->json('data.footer_bg_image');
|
||||
|
||||
$this->assertStringContainsString($headerAttachment->key, $headerUrl);
|
||||
$this->assertStringContainsString($footerAttachment->key, $footerUrl);
|
||||
$this->assertStringContainsString($headerBackgroundAttachment->key, $headerBackgroundUrl);
|
||||
$this->assertStringContainsString($footerBackgroundAttachment->key, $footerBackgroundUrl);
|
||||
$this->assertTrue(
|
||||
str_contains($headerUrl, 'Expires=') || str_contains($headerUrl, 'expiration=') || str_contains($headerUrl, 'X-Amz-Expires=')
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user