125 lines
4.5 KiB
PHP
125 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Tenant;
|
|
|
|
use App\Shared\Attachable\Enums\AttachmentType;
|
|
use App\Shared\Attachable\Models\Attachment;
|
|
use App\Domains\Core\Tenant\Models\Tenant;
|
|
use App\Domains\Core\Tenant\Models\AdminWebsiteType;
|
|
use App\Domains\Core\Tenant\Models\StorefrontWebsiteType;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Tests\TestCase;
|
|
|
|
class WebsiteExtrasTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_website_extra_tables_have_the_expected_columns(): void
|
|
{
|
|
$this->assertTrue(Schema::hasColumn('tenants', 'storefront_website_type_code'));
|
|
|
|
$this->assertTrue(Schema::hasColumn('tenants', 'admin_website_type_code'));
|
|
$this->assertEqualsCanonicalizing(['id', 'codigo', 'nombre', 'created_at', 'updated_at'], Schema::getColumnListing('storefront_website_types'));
|
|
$this->assertTrue(Schema::hasColumn('admin_website_types', 'dominio'));
|
|
|
|
$this->assertEqualsCanonicalizing([
|
|
'id',
|
|
'storefront_website_type_code',
|
|
'codigo',
|
|
'nombre',
|
|
'descripcion',
|
|
'is_required',
|
|
'config_schema',
|
|
'created_at',
|
|
'updated_at',
|
|
], Schema::getColumnListing('storefront_website_type_extras'));
|
|
|
|
$this->assertEqualsCanonicalizing([
|
|
'id',
|
|
'website_code',
|
|
'website_type_extra_id',
|
|
'config',
|
|
'is_enabled',
|
|
'created_at',
|
|
'updated_at',
|
|
], Schema::getColumnListing('websites_extras'));
|
|
}
|
|
|
|
public function test_models_keep_admin_branding_and_storefront_extras_independent(): void
|
|
{
|
|
$admin = AdminWebsiteType::query()->create([
|
|
'codigo' => 'admin-brand',
|
|
'nombre' => 'Admin Brand',
|
|
'dominio' => 'admin.test',
|
|
]);
|
|
$storefront = StorefrontWebsiteType::query()->create([
|
|
'codigo' => 'store',
|
|
'nombre' => 'Tienda',
|
|
]);
|
|
$definition = $storefront->extras()->create([
|
|
'codigo' => 'whatsapp',
|
|
'nombre' => 'WhatsApp',
|
|
'descripcion' => 'Canal de WhatsApp',
|
|
'is_required' => true,
|
|
'config_schema' => ['type' => 'object'],
|
|
]);
|
|
$tenant = $this->createTenant();
|
|
$tenant->adminWebsiteType()->associate($admin);
|
|
$tenant->storefrontWebsiteType()->associate($storefront);
|
|
$tenant->save();
|
|
$value = $tenant->websiteExtras()->create([
|
|
'website_type_extra_id' => $definition->id,
|
|
'config' => ['phone' => '+5491112345678'],
|
|
'is_enabled' => true,
|
|
]);
|
|
|
|
$this->assertTrue($tenant->adminWebsiteType->is($admin));
|
|
$this->assertTrue($tenant->storefrontWebsiteType->is($storefront));
|
|
$this->assertTrue($definition->storefrontWebsiteType->is($storefront));
|
|
$this->assertTrue($definition->websiteExtras()->firstOrFail()->is($value));
|
|
$this->assertSame('store', $tenant->storefront_website_type_code);
|
|
$this->assertSame('admin-brand', $tenant->admin_website_type_code);
|
|
}
|
|
|
|
public function test_deleting_a_type_cascades_its_definitions_and_website_values(): void
|
|
{
|
|
$type = StorefrontWebsiteType::query()->create([
|
|
'codigo' => 'store',
|
|
'nombre' => 'Tienda',
|
|
]);
|
|
$typeExtra = $type->extras()->create([
|
|
'codigo' => 'whatsapp',
|
|
'nombre' => 'WhatsApp',
|
|
'descripcion' => 'Configuracion del canal de WhatsApp',
|
|
'config_schema' => ['type' => 'object'],
|
|
]);
|
|
$websiteExtra = $this->createTenant()->websiteExtras()->create([
|
|
'website_type_extra_id' => $typeExtra->id,
|
|
'config' => ['phone' => '+5491112345678'],
|
|
]);
|
|
|
|
$type->delete();
|
|
|
|
$this->assertDatabaseMissing('storefront_website_type_extras', ['id' => $typeExtra->id]);
|
|
$this->assertDatabaseMissing('websites_extras', ['id' => $websiteExtra->id]);
|
|
}
|
|
|
|
private function createTenant(): Tenant
|
|
{
|
|
return Tenant::query()->create([
|
|
'codigo' => 'acme',
|
|
'nombre' => 'Acme',
|
|
'dominio' => 'acme.com',
|
|
'primary_color' => '#111111',
|
|
'secondary_color' => '#222222',
|
|
'danger_color' => '#333333',
|
|
'success_color' => '#444444',
|
|
'header_bg_color' => '#ffffff',
|
|
'footer_bg_color' => '#ffffff',
|
|
'header_logo_id' => 1,
|
|
'footer_logo_id' => 2,
|
|
]);
|
|
}
|
|
}
|