feat(website-extras): add 'is_enabled' column to websites_extras table and update model and tests

This commit is contained in:
2026-07-31 09:38:30 -03:00
parent cbb7b1c3a1
commit 45e56c43a6
5 changed files with 73 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
'website_code',
'website_type_extra_id',
'config',
'is_enabled',
])]
class WebsiteExtra extends Model
{
@@ -30,6 +31,7 @@ class WebsiteExtra extends Model
return [
'website_type_extra_id' => 'integer',
'config' => 'array',
'is_enabled' => 'boolean',
];
}

View File

@@ -41,11 +41,13 @@ class TenantResource extends JsonResource
),
'extras' => $this->whenLoaded(
'websiteExtras',
fn () => $this->websiteExtras->mapWithKeys(fn ($extra) => [
$extra->websiteTypeExtra->codigo => $this->formatExtraConfig(
$extra->resolvedConfig()
),
])
fn () => $this->websiteExtras
->filter(fn ($extra) => $extra->is_enabled)
->mapWithKeys(fn ($extra) => [
$extra->websiteTypeExtra->codigo => $this->formatExtraConfig(
$extra->resolvedConfig()
),
])
),
// 1 day
'header_logo' => $this->headerLogo?->getTemporaryUrl(1440),

View File

@@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('websites_extras', function (Blueprint $table): void {
$table->boolean('is_enabled')->nullable()->after('config');
});
}
public function down(): void
{
Schema::table('websites_extras', function (Blueprint $table): void {
$table->dropColumn('is_enabled');
});
}
};

View File

@@ -9,6 +9,7 @@ use App\Domains\Authorization\Models\Role;
use App\Domains\Catalog\Models\Category;
use App\Domains\Menu\Models\Menu;
use App\Domains\Tenant\Models\Tenant;
use App\Domains\Tenant\Models\WebsiteType;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
@@ -137,6 +138,44 @@ class BootstrapTenantControllerTest extends TestCase
->assertJsonMissing(['nombre' => 'Global']);
}
public function test_it_returns_only_enabled_website_extras_in_the_bootstrap(): void
{
$tenant = $this->createTenant();
$websiteType = WebsiteType::query()->create([
'codigo' => 'store',
'nombre' => 'Tienda',
]);
$tenant->update(['website_type_code' => $websiteType->codigo]);
$enabledExtra = $websiteType->extras()->create([
'codigo' => 'contact',
'nombre' => 'Contacto',
'descripcion' => 'Datos de contacto.',
'config_schema' => [],
]);
$disabledExtra = $websiteType->extras()->create([
'codigo' => 'banner',
'nombre' => 'Banner',
'descripcion' => 'Banner promocional.',
'config_schema' => [],
]);
$tenant->websiteExtras()->create([
'website_type_extra_id' => $enabledExtra->id,
'config' => ['phone' => '+54 341 555 0101'],
'is_enabled' => true,
]);
$tenant->websiteExtras()->create([
'website_type_extra_id' => $disabledExtra->id,
'config' => ['title' => 'No mostrar'],
'is_enabled' => false,
]);
$this->getJson('/api/tenants/bootstrap/acme.com')
->assertOk()
->assertJsonPath('data.extras.contact.phone', '+54 341 555 0101')
->assertJsonMissingPath('data.extras.banner');
}
public function test_it_returns_not_found_when_the_domain_does_not_exist(): void
{
$response = $this->getJson('/api/tenants/bootstrap/missing.example');

View File

@@ -41,6 +41,7 @@ class WebsiteExtrasTest extends TestCase
'website_code',
'website_type_extra_id',
'config',
'is_enabled',
'created_at',
'updated_at',
], Schema::getColumnListing('websites_extras'));
@@ -67,6 +68,7 @@ class WebsiteExtrasTest extends TestCase
$websiteExtra = $tenant->websiteExtras()->create([
'website_type_extra_id' => $typeExtra->id,
'config' => ['phone' => '+5491112345678'],
'is_enabled' => true,
]);
$this->assertTrue($type->extras()->firstOrFail()->is($typeExtra));
@@ -85,6 +87,7 @@ class WebsiteExtrasTest extends TestCase
'required' => ['phone'],
], $typeExtra->config_schema);
$this->assertSame(['phone' => '+5491112345678'], $websiteExtra->config);
$this->assertTrue($websiteExtra->is_enabled);
}
public function test_deleting_a_type_cascades_its_definitions_and_website_values(): void