test(tenant): cover split website types and migration

This commit is contained in:
2026-09-17 14:25:54 -03:00
parent 6bc784519f
commit 486129a92f
36 changed files with 335 additions and 307 deletions

View File

@@ -15,29 +15,9 @@ class SetWebsiteTypeFaviconTest extends TestCase
{
Storage::fake('s3');
DB::table('website_type')->insert([
[
'codigo' => 'shopit',
'nombre' => 'ShopIt',
'created_at' => now(),
'updated_at' => now(),
],
[
'codigo' => 'onticket',
'nombre' => 'OnTicket',
'created_at' => now(),
'updated_at' => now(),
],
]);
$this->seed(\Database\Seeders\WebsiteTypeSeeder::class);
$migration = require database_path(
'migrations/2026_08_26_000000_set_website_type_favicon.php'
);
$migration->up();
$migration->up();
$faviconIds = DB::table('website_type')
$faviconIds = DB::table('admin_website_types')
->whereIn('codigo', ['shopit', 'onticket'])
->pluck('favicon_id');

View File

@@ -0,0 +1,94 @@
<?php
namespace Tests\Feature\Migrations;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Tests\TestCase;
class SplitWebsiteTypesMigrationTest extends TestCase
{
public function test_it_preserves_existing_associations_and_browser_branding(): void
{
Schema::create('website_type', function (Blueprint $table): void {
$table->id();
$table->string('codigo')->unique();
$table->string('nombre');
$table->string('site_title')->nullable();
$table->unsignedBigInteger('favicon_id')->nullable();
$table->timestamps();
});
Schema::create('tenants', function (Blueprint $table): void {
$table->id();
$table->string('website_type_code')->nullable();
$table->string('site_title')->nullable();
$table->unsignedBigInteger('favicon_id')->nullable();
$table->timestamps();
$table->foreign('website_type_code')->references('codigo')->on('website_type')->nullOnDelete();
});
Schema::create('website_type_extras', function (Blueprint $table): void {
$table->id();
$table->string('website_type_code');
$table->string('codigo')->nullable();
$table->string('nombre');
$table->text('descripcion');
$table->boolean('is_required')->default(false);
$table->json('config_schema');
$table->timestamps();
$table->foreign('website_type_code')->references('codigo')->on('website_type')->cascadeOnDelete();
});
Schema::create('websites_extras', function (Blueprint $table): void {
$table->id();
$table->string('website_code');
$table->foreignId('website_type_extra_id')->constrained('website_type_extras')->cascadeOnDelete();
$table->json('config');
$table->timestamps();
});
Schema::create('website_type_integrations', function (Blueprint $table): void {
$table->id();
$table->string('website_type_code');
$table->string('integration_code');
$table->unsignedBigInteger('integration_instance_id');
$table->timestamps();
$table->foreign('website_type_code')->references('codigo')->on('website_type')->cascadeOnDelete();
});
DB::table('website_type')->insert(['id' => 10, 'codigo' => 'onticket', 'nombre' => 'OnTicket', 'site_title' => 'Old title', 'favicon_id' => 42]);
DB::table('tenants')->insert([
['id' => 1, 'website_type_code' => 'onticket', 'site_title' => null, 'favicon_id' => null],
['id' => 2, 'website_type_code' => null, 'site_title' => null, 'favicon_id' => null],
['id' => 3, 'website_type_code' => 'onticket', 'site_title' => 'Custom title', 'favicon_id' => 99],
]);
DB::table('website_type_extras')->insert(['id' => 20, 'website_type_code' => 'onticket', 'codigo' => 'heroConfig', 'nombre' => 'Hero', 'descripcion' => 'Hero', 'config_schema' => '{}']);
DB::table('websites_extras')->insert(['id' => 30, 'website_code' => 'test', 'website_type_extra_id' => 20, 'config' => '{}']);
DB::table('website_type_integrations')->insert(['id' => 40, 'website_type_code' => 'onticket', 'integration_code' => 'email', 'integration_instance_id' => 50]);
$migration = require database_path('migrations/2026_09_17_000000_split_website_types.php');
$migration->up();
$this->assertDatabaseHas('tenants', ['id' => 1, 'admin_website_type_code' => 'onticket', 'storefront_website_type_code' => 'onticket', 'site_title' => 'Old title', 'favicon_id' => 42]);
$this->assertDatabaseHas('tenants', ['id' => 2, 'admin_website_type_code' => null, 'storefront_website_type_code' => null]);
$this->assertDatabaseHas('tenants', ['id' => 3, 'site_title' => 'Custom title', 'favicon_id' => 99]);
$this->assertDatabaseHas('storefront_website_type_extras', ['id' => 20, 'storefront_website_type_code' => 'onticket']);
$this->assertDatabaseHas('websites_extras', ['id' => 30, 'website_type_extra_id' => 20]);
$this->assertDatabaseHas('admin_website_type_integrations', ['id' => 40, 'admin_website_type_code' => 'onticket']);
DB::table('storefront_website_types')->insert(['codigo' => 'new-store', 'nombre' => 'New Store']);
DB::table('storefront_website_type_extras')->insert([
'storefront_website_type_code' => 'new-store',
'codigo' => 'banner',
'nombre' => 'Banner',
'descripcion' => 'Banner',
'config_schema' => '{}',
]);
$this->assertDatabaseHas('storefront_website_type_extras', ['storefront_website_type_code' => 'new-store', 'codigo' => 'banner']);
DB::table('storefront_website_types')->where('codigo', 'onticket')->delete();
$this->assertDatabaseMissing('storefront_website_type_extras', ['id' => 20]);
$this->assertDatabaseMissing('websites_extras', ['id' => 30]);
$this->assertDatabaseHas('tenants', ['id' => 1, 'admin_website_type_code' => 'onticket', 'storefront_website_type_code' => null]);
$this->assertDatabaseHas('admin_website_type_integrations', ['id' => 40, 'admin_website_type_code' => 'onticket']);
}
}