feat: implement full CRUD support and database schema for multi-tenant architecture

This commit is contained in:
2026-06-26 16:57:59 -03:00
parent 8708cea122
commit 31b65eb676
10 changed files with 562 additions and 58 deletions

View File

@@ -17,11 +17,7 @@ class CartControllerTest extends TestCase
public function test_it_returns_an_empty_guest_cart_when_cart_does_not_exist(): void
{
Tenant::create([
'codigo' => 'acme',
'nombre' => 'Acme',
'dominio' => 'acme.com',
]);
$this->createTenant('acme', 'Acme', 'acme.com');
$this->getJson('/api/tenants/acme/cart')
->assertOk()
@@ -272,10 +268,10 @@ class CartControllerTest extends TestCase
string $price,
string $slugPrefix = 'shirt',
): ProductVariant {
Tenant::query()->firstOrCreate(
['codigo' => $tenantCode],
['nombre' => ucfirst($tenantCode), 'dominio' => "{$tenantCode}.com"],
);
$tenant = Tenant::query()->where('codigo', $tenantCode)->first();
if (! $tenant) {
$this->createTenant($tenantCode, ucfirst($tenantCode), "{$tenantCode}.com");
}
$category = \App\Domains\Catalog\Models\Category::query()->create([
'tenant_code' => $tenantCode,
@@ -300,4 +296,37 @@ class CartControllerTest extends TestCase
'precio' => $price,
])->load('product');
}
protected function createTenant(string $codigo, string $nombre, string $dominio): Tenant
{
$hdrKey = (string) \Illuminate\Support\Str::uuid();
$ftrKey = (string) \Illuminate\Support\Str::uuid();
$headerAttachment = \App\Domains\Attachable\Models\Attachment::create([
'key' => $hdrKey,
'path' => 'tenants/' . $hdrKey . '.png',
'filename' => 'logo_header.png',
'type' => \App\Domains\Attachable\Enums\AttachmentType::Image,
'mime_type' => 'image/png',
]);
$footerAttachment = \App\Domains\Attachable\Models\Attachment::create([
'key' => $ftrKey,
'path' => 'tenants/' . $ftrKey . '.png',
'filename' => 'logo_footer.png',
'type' => \App\Domains\Attachable\Enums\AttachmentType::Image,
'mime_type' => 'image/png',
]);
return Tenant::create([
'codigo' => $codigo,
'nombre' => $nombre,
'dominio' => $dominio,
'primary_color' => '#111111',
'secondary_color' => '#222222',
'danger_color' => '#333333',
'header_footer_bg_color' => '#444444',
'header_logo_id' => $headerAttachment->id,
'footer_logo_id' => $footerAttachment->id,
]);
}
}