test(tenant): cover split website types and migration
This commit is contained in:
@@ -5,7 +5,8 @@ namespace Tests\Feature\Tenant;
|
||||
use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Tenant\Models\WebsiteType;
|
||||
use App\Domains\Tenant\Models\AdminWebsiteType;
|
||||
use App\Domains\Tenant\Models\StorefrontWebsiteType;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Tests\TestCase;
|
||||
@@ -16,32 +17,15 @@ class WebsiteExtrasTest extends TestCase
|
||||
|
||||
public function test_website_extra_tables_have_the_expected_columns(): void
|
||||
{
|
||||
$this->assertTrue(Schema::hasColumn('tenants', 'website_type_code'));
|
||||
$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',
|
||||
'codigo',
|
||||
'nombre',
|
||||
'dominio',
|
||||
'primary_color',
|
||||
'secondary_color',
|
||||
'danger_color',
|
||||
'success_color',
|
||||
'warning_color',
|
||||
'body_color',
|
||||
'darker_body_color',
|
||||
'surface_color',
|
||||
'background_color',
|
||||
'border_color',
|
||||
'login_header_footer_color',
|
||||
'site_logo',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
], Schema::getColumnListing('website_type'));
|
||||
|
||||
$this->assertEqualsCanonicalizing([
|
||||
'id',
|
||||
'website_type_code',
|
||||
'storefront_website_type_code',
|
||||
'codigo',
|
||||
'nombre',
|
||||
'descripcion',
|
||||
@@ -49,7 +33,7 @@ class WebsiteExtrasTest extends TestCase
|
||||
'config_schema',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
], Schema::getColumnListing('website_type_extras'));
|
||||
], Schema::getColumnListing('storefront_website_type_extras'));
|
||||
|
||||
$this->assertEqualsCanonicalizing([
|
||||
'id',
|
||||
@@ -62,85 +46,45 @@ class WebsiteExtrasTest extends TestCase
|
||||
], Schema::getColumnListing('websites_extras'));
|
||||
}
|
||||
|
||||
public function test_models_map_the_diagram_relations_and_casts(): void
|
||||
public function test_models_keep_admin_branding_and_storefront_extras_independent(): void
|
||||
{
|
||||
$siteLogo = Attachment::query()->create([
|
||||
'key' => '92bb3986-fb22-4871-b98c-fc5663d78aa6',
|
||||
'path' => 'website-types/site-logo.png',
|
||||
'filename' => 'site-logo.png',
|
||||
'type' => AttachmentType::Image,
|
||||
'mime_type' => 'image/png',
|
||||
$admin = AdminWebsiteType::query()->create([
|
||||
'codigo' => 'admin-brand',
|
||||
'nombre' => 'Admin Brand',
|
||||
'dominio' => 'admin.test',
|
||||
]);
|
||||
$type = WebsiteType::query()->create([
|
||||
$storefront = StorefrontWebsiteType::query()->create([
|
||||
'codigo' => 'store',
|
||||
'nombre' => 'Tienda',
|
||||
'dominio' => 'store.test',
|
||||
'primary_color' => '#111111',
|
||||
'secondary_color' => '#222222',
|
||||
'danger_color' => '#ff0000',
|
||||
'success_color' => '#00aa55',
|
||||
'warning_color' => '#ffaa00',
|
||||
'body_color' => '#666666',
|
||||
'darker_body_color' => '#333333',
|
||||
'surface_color' => '#ffffff',
|
||||
'background_color' => '#f8f8f8',
|
||||
'border_color' => '#dddddd',
|
||||
'login_header_footer_color' => '#333333',
|
||||
'site_logo' => $siteLogo->id,
|
||||
]);
|
||||
$typeExtra = $type->extras()->create([
|
||||
$definition = $storefront->extras()->create([
|
||||
'codigo' => 'whatsapp',
|
||||
'nombre' => 'WhatsApp',
|
||||
'descripcion' => 'Configuracion del canal de WhatsApp',
|
||||
'descripcion' => 'Canal de WhatsApp',
|
||||
'is_required' => true,
|
||||
'config_schema' => [
|
||||
'type' => 'object',
|
||||
'required' => ['phone'],
|
||||
],
|
||||
'config_schema' => ['type' => 'object'],
|
||||
]);
|
||||
$tenant = $this->createTenant();
|
||||
$tenant->websiteType()->associate($type)->save();
|
||||
$websiteExtra = $tenant->websiteExtras()->create([
|
||||
'website_type_extra_id' => $typeExtra->id,
|
||||
$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($type->extras()->firstOrFail()->is($typeExtra));
|
||||
$this->assertSame('store.test', $type->dominio);
|
||||
$this->assertSame('#111111', $type->primary_color);
|
||||
$this->assertSame('#222222', $type->secondary_color);
|
||||
$this->assertSame('#ff0000', $type->danger_color);
|
||||
$this->assertSame('#00aa55', $type->success_color);
|
||||
$this->assertSame('#ffaa00', $type->warning_color);
|
||||
$this->assertSame('#666666', $type->body_color);
|
||||
$this->assertSame('#333333', $type->darker_body_color);
|
||||
$this->assertSame('#ffffff', $type->surface_color);
|
||||
$this->assertSame('#f8f8f8', $type->background_color);
|
||||
$this->assertSame('#dddddd', $type->border_color);
|
||||
$this->assertSame('#333333', $type->login_header_footer_color);
|
||||
$this->assertTrue($type->siteLogo()->firstOrFail()->is($siteLogo));
|
||||
$this->assertSame($type->codigo, $typeExtra->website_type_code);
|
||||
$this->assertSame('whatsapp', $typeExtra->codigo);
|
||||
$this->assertTrue($type->tenants()->firstOrFail()->is($tenant));
|
||||
$this->assertTrue($tenant->websiteType()->firstOrFail()->is($type));
|
||||
$this->assertSame($type->codigo, $tenant->website_type_code);
|
||||
$this->assertTrue($typeExtra->websiteType()->firstOrFail()->is($type));
|
||||
$this->assertTrue($typeExtra->websiteExtras()->firstOrFail()->is($websiteExtra));
|
||||
$this->assertTrue($websiteExtra->website()->firstOrFail()->is($tenant));
|
||||
$this->assertTrue($websiteExtra->websiteTypeExtra()->firstOrFail()->is($typeExtra));
|
||||
$this->assertTrue($typeExtra->is_required);
|
||||
$this->assertSame([
|
||||
'type' => 'object',
|
||||
'required' => ['phone'],
|
||||
], $typeExtra->config_schema);
|
||||
$this->assertSame(['phone' => '+5491112345678'], $websiteExtra->config);
|
||||
$this->assertTrue($websiteExtra->is_enabled);
|
||||
$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 = WebsiteType::query()->create([
|
||||
$type = StorefrontWebsiteType::query()->create([
|
||||
'codigo' => 'store',
|
||||
'nombre' => 'Tienda',
|
||||
]);
|
||||
@@ -157,7 +101,7 @@ class WebsiteExtrasTest extends TestCase
|
||||
|
||||
$type->delete();
|
||||
|
||||
$this->assertDatabaseMissing('website_type_extras', ['id' => $typeExtra->id]);
|
||||
$this->assertDatabaseMissing('storefront_website_type_extras', ['id' => $typeExtra->id]);
|
||||
$this->assertDatabaseMissing('websites_extras', ['id' => $websiteExtra->id]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user