feat(tenant): reintroduce tenant-specific props and instance values
Restore props support only for the Tenant domain using a tenant-scoped model instead of the removed generic Prop/Propable implementation. Add tenant prop definitions and instance values: - add TenantProp and TenantPropValue models - add tenant-only data type enum and prop validation rules - add migrations for tenant_props and tenant_prop_values tables - persist prop values by tenant_codigo + tenant_prop_codigo Expose tenant prop management through the Tenant domain: - add TenantPropController with CRUD endpoints - add Store/Update request classes for tenant prop definitions - register tenant-props routes Re-enable tenant prop syncing and serialization: - restore createWithProps/updateWithProps flows in Tenant - validate props on tenant create/update requests - include collapsed props in TenantResource - keep the implementation scoped to Tenant without reintroducing polymorphic props Add coverage for the new tenant prop behavior: - update bootstrap tenant feature test to assert prop values - add feature tests for tenant prop creation and validation
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Tests\Feature\Tenant;
|
||||
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Tenant\Models\TenantProp;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -10,7 +11,7 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_it_bootstraps_a_tenant_by_domain(): void
|
||||
public function test_it_bootstraps_a_tenant_by_domain_and_includes_props(): void
|
||||
{
|
||||
$tenant = Tenant::create([
|
||||
'codigo' => 'acme',
|
||||
@@ -18,12 +19,23 @@ 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('codigo', 'acme')
|
||||
->assertJsonPath('dominio', 'acme.com');
|
||||
->assertJsonPath('dominio', 'acme.com')
|
||||
->assertJsonPath('props.primary_color', 'blue');
|
||||
}
|
||||
|
||||
public function test_it_bootstraps_a_tenant_from_a_full_url(): void
|
||||
@@ -53,15 +65,33 @@ 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('dominio', 'acme.com');
|
||||
->assertJsonPath('dominio', 'acme.com')
|
||||
->assertJsonPath('props.primary_color', 'blue');
|
||||
|
||||
$this->assertDatabaseHas('tenant_prop_values', [
|
||||
'tenant_codigo' => 'acme',
|
||||
'tenant_prop_codigo' => 'primary_color',
|
||||
'value' => 'blue',
|
||||
]);
|
||||
|
||||
$secondResponse = $this->postJson('/api/tenants', [
|
||||
'codigo' => 'globex',
|
||||
@@ -76,6 +106,14 @@ 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',
|
||||
@@ -92,12 +130,16 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
'codigo' => 'acme',
|
||||
'nombre' => 'Acme Updated',
|
||||
'dominio' => 'https://ACME.com:443/admin',
|
||||
'props' => [
|
||||
'primary_color' => 'green',
|
||||
],
|
||||
]);
|
||||
|
||||
$successfulResponse
|
||||
->assertOk()
|
||||
->assertJsonPath('nombre', 'Acme Updated')
|
||||
->assertJsonPath('dominio', 'acme.com');
|
||||
->assertJsonPath('dominio', 'acme.com')
|
||||
->assertJsonPath('props.primary_color', 'green');
|
||||
|
||||
$failingResponse = $this->putJson("/api/tenants/{$otherTenant->id}", [
|
||||
'codigo' => 'globex',
|
||||
|
||||
45
tests/Feature/Tenant/TenantPropControllerTest.php
Normal file
45
tests/Feature/Tenant/TenantPropControllerTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Tenant;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TenantPropControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_it_creates_a_tenant_prop(): void
|
||||
{
|
||||
$response = $this->postJson('/api/tenant-props', [
|
||||
'codigo' => 'primary_color',
|
||||
'nombre' => 'Primary Color',
|
||||
'descripcion' => 'Brand color',
|
||||
'is_required' => false,
|
||||
'data_type' => 'string',
|
||||
]);
|
||||
|
||||
$response
|
||||
->assertCreated()
|
||||
->assertJsonPath('codigo', 'primary_color')
|
||||
->assertJsonPath('data_type', 'string');
|
||||
|
||||
$this->assertDatabaseHas('tenant_props', [
|
||||
'codigo' => 'primary_color',
|
||||
'data_type' => 'string',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_it_rejects_unknown_data_type(): void
|
||||
{
|
||||
$response = $this->postJson('/api/tenant-props', [
|
||||
'codigo' => 'primary_color',
|
||||
'nombre' => 'Primary Color',
|
||||
'data_type' => 'unsupported',
|
||||
]);
|
||||
|
||||
$response
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['data_type']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user