feat: implement tenant management system including CRUD operations and domain bootstrapping functionality

This commit is contained in:
2026-06-26 11:55:05 -03:00
parent 4c237fb729
commit 0dae985230
17 changed files with 9 additions and 567 deletions

View File

@@ -3,7 +3,6 @@
namespace Tests\Feature\Tenant;
use App\Domains\Tenant\Models\Tenant;
use App\Domains\Tenant\Models\TenantProp;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
@@ -11,7 +10,7 @@ class BootstrapTenantControllerTest extends TestCase
{
use RefreshDatabase;
public function test_it_bootstraps_a_tenant_by_domain_and_includes_props(): void
public function test_it_bootstraps_a_tenant_by_domain(): void
{
$tenant = Tenant::create([
'codigo' => 'acme',
@@ -19,23 +18,14 @@ class BootstrapTenantControllerTest extends TestCase
'dominio' => 'acme.com',
]);
TenantProp::create([
'codigo' => 'primary_color',
'nombre' => 'Primary Color',
'descripcion' => 'Brand color',
'is_required' => false,
'data_type' => 'string',
]);
$tenant->setPropValue('primary_color', 'blue');
$response = $this->getJson('/api/tenants/bootstrap/acme.com');
$response
->assertOk()
->assertJsonPath('data.codigo', 'acme')
->assertJsonPath('data.dominio', 'acme.com')
->assertJsonPath('data.props.primary_color', 'blue');
->assertJsonPath('data.dominio', 'acme.com');
$this->assertArrayNotHasKey('props', $response->json('data'));
}
public function test_it_bootstraps_a_tenant_from_a_full_url(): void
@@ -65,33 +55,15 @@ class BootstrapTenantControllerTest extends TestCase
public function test_it_rejects_duplicate_domains_after_normalization_when_storing(): void
{
TenantProp::create([
'codigo' => 'primary_color',
'nombre' => 'Primary Color',
'descripcion' => 'Brand color',
'is_required' => false,
'data_type' => 'string',
]);
$firstResponse = $this->postJson('/api/tenants', [
'codigo' => 'acme',
'nombre' => 'Acme',
'dominio' => 'https://ACME.com/path',
'props' => [
'primary_color' => 'blue',
],
]);
$firstResponse
->assertCreated()
->assertJsonPath('data.dominio', 'acme.com')
->assertJsonPath('data.props.primary_color', 'blue');
$this->assertDatabaseHas('tenant_prop_values', [
'tenant_codigo' => 'acme',
'tenant_prop_codigo' => 'primary_color',
'value' => 'blue',
]);
->assertJsonPath('data.dominio', 'acme.com');
$secondResponse = $this->postJson('/api/tenants', [
'codigo' => 'globex',
@@ -106,14 +78,6 @@ class BootstrapTenantControllerTest extends TestCase
public function test_it_allows_keeping_the_same_domain_on_update_but_rejects_collisions(): void
{
TenantProp::create([
'codigo' => 'primary_color',
'nombre' => 'Primary Color',
'descripcion' => 'Brand color',
'is_required' => false,
'data_type' => 'string',
]);
$tenant = Tenant::create([
'codigo' => 'acme',
'nombre' => 'Acme',
@@ -130,16 +94,12 @@ class BootstrapTenantControllerTest extends TestCase
'codigo' => 'acme',
'nombre' => 'Acme Updated',
'dominio' => 'https://ACME.com:443/admin',
'props' => [
'primary_color' => 'green',
],
]);
$successfulResponse
->assertOk()
->assertJsonPath('data.nombre', 'Acme Updated')
->assertJsonPath('data.dominio', 'acme.com')
->assertJsonPath('data.props.primary_color', 'green');
->assertJsonPath('data.dominio', 'acme.com');
$failingResponse = $this->putJson("/api/tenants/{$otherTenant->id}", [
'codigo' => 'globex',