97 lines
4.6 KiB
PHP
97 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Migrations;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Tests\TestCase;
|
|
|
|
class AddOnticketImmersiveHeroConfigurationTest extends TestCase
|
|
{
|
|
public function test_it_preserves_existing_tenants_and_extra_content(): void
|
|
{
|
|
Schema::create('storefront_website_types', function (Blueprint $table): void {
|
|
$table->id();
|
|
$table->string('codigo')->unique();
|
|
$table->string('nombre');
|
|
$table->string('header_type');
|
|
$table->timestamps();
|
|
});
|
|
Schema::create('storefront_website_type_extras', function (Blueprint $table): void {
|
|
$table->id();
|
|
$table->string('storefront_website_type_code');
|
|
$table->string('codigo');
|
|
$table->string('nombre');
|
|
$table->text('descripcion');
|
|
$table->boolean('is_required');
|
|
$table->json('config_schema');
|
|
$table->timestamps();
|
|
$table->unique(['storefront_website_type_code', 'codigo']);
|
|
});
|
|
Schema::create('tenants', function (Blueprint $table): void {
|
|
$table->id();
|
|
$table->string('codigo')->unique();
|
|
$table->string('storefront_website_type_code');
|
|
$table->boolean('display_seach_bar');
|
|
$table->timestamps();
|
|
});
|
|
Schema::create('websites_extras', function (Blueprint $table): void {
|
|
$table->id();
|
|
$table->string('website_code');
|
|
$table->foreignId('website_type_extra_id');
|
|
$table->json('config');
|
|
$table->boolean('is_enabled');
|
|
$table->timestamps();
|
|
$table->unique(['website_code', 'website_type_extra_id']);
|
|
});
|
|
|
|
DB::table('storefront_website_types')->insert([
|
|
'codigo' => 'onticket_multi_event', 'nombre' => 'OnTicket', 'header_type' => 'immersive',
|
|
]);
|
|
DB::table('tenants')->insert([
|
|
['id' => 10, 'codigo' => 'onticket', 'storefront_website_type_code' => 'onticket', 'display_seach_bar' => false],
|
|
['id' => 20, 'codigo' => 'sonder', 'storefront_website_type_code' => 'shopit', 'display_seach_bar' => false],
|
|
]);
|
|
DB::table('storefront_website_type_extras')->insert([
|
|
'id' => 30, 'storefront_website_type_code' => 'onticket_multi_event', 'codigo' => 'heroCarousel',
|
|
'nombre' => 'Carrusel', 'descripcion' => 'Existente', 'is_required' => false, 'config_schema' => '{}',
|
|
]);
|
|
DB::table('websites_extras')->insert([
|
|
'id' => 40, 'website_code' => 'onticket', 'website_type_extra_id' => 30,
|
|
'config' => '[1,2]', 'is_enabled' => true,
|
|
]);
|
|
|
|
$migration = require database_path('migrations/2026_09_18_000000_add_onticket_immersive_hero_configuration.php');
|
|
$migration->up();
|
|
|
|
$this->assertSame(10, DB::table('tenants')->where('codigo', 'onticket')->value('id'));
|
|
$this->assertSame(20, DB::table('tenants')->where('codigo', 'sonder')->value('id'));
|
|
$this->assertSame(0, DB::table('tenants')->where('codigo', 'sonder')->value('display_seach_bar'));
|
|
$this->assertSame(1, DB::table('tenants')->where('codigo', 'onticket')->value('display_seach_bar'));
|
|
$this->assertSame('onticket_multi_event', DB::table('tenants')->where('codigo', 'onticket')->value('storefront_website_type_code'));
|
|
$this->assertSame('[1,2]', DB::table('websites_extras')->where('id', 40)->value('config'));
|
|
|
|
$extraId = DB::table('storefront_website_type_extras')
|
|
->where('storefront_website_type_code', 'onticket_multi_event')
|
|
->where('codigo', 'immersiveHero')->value('id');
|
|
$this->assertNotNull($extraId);
|
|
$websiteExtra = DB::table('websites_extras')
|
|
->where('website_code', 'onticket')->where('website_type_extra_id', $extraId)->sole();
|
|
$this->assertSame([
|
|
'eyebrow' => 'Encendé tu', 'title' => 'experiencia',
|
|
'description' => 'Reservá tu entrada y formá parte',
|
|
], json_decode($websiteExtra->config, true));
|
|
|
|
DB::table('websites_extras')->where('id', $websiteExtra->id)->update([
|
|
'config' => '{"eyebrow":"Personalizado"}',
|
|
]);
|
|
$migration->up();
|
|
|
|
$this->assertSame('{"eyebrow":"Personalizado"}', DB::table('websites_extras')
|
|
->where('id', $websiteExtra->id)->value('config'));
|
|
$this->assertSame(1, DB::table('websites_extras')
|
|
->where('website_code', 'onticket')->where('website_type_extra_id', $extraId)->count());
|
|
}
|
|
}
|