feat: implement tenant update request validation and add feature tests for domain bootstrapping
This commit is contained in:
@@ -27,6 +27,11 @@ class Tenant extends Model
|
|||||||
use HasAttachments;
|
use HasAttachments;
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
|
public function getRouteKeyName(): string
|
||||||
|
{
|
||||||
|
return 'codigo';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return BelongsTo<Attachment, $this>
|
* @return BelongsTo<Attachment, $this>
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -88,12 +88,12 @@ class UpdateTenantRequest extends FormRequest
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'codigo' => [
|
'codigo' => [
|
||||||
'required',
|
'sometimes',
|
||||||
'string',
|
'string',
|
||||||
'max:255',
|
'max:255',
|
||||||
Rule::unique('tenants', 'codigo')->ignore($tenant?->id),
|
Rule::unique('tenants', 'codigo')->ignore($tenant?->id),
|
||||||
],
|
],
|
||||||
'nombre' => ['required', 'string', 'max:255'],
|
'nombre' => ['sometimes', 'string', 'max:255'],
|
||||||
'dominio' => [
|
'dominio' => [
|
||||||
'bail',
|
'bail',
|
||||||
function (string $attribute, mixed $value, Closure $fail): void {
|
function (string $attribute, mixed $value, Closure $fail): void {
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ class BootstrapTenantControllerTest extends TestCase
|
|||||||
'mime_type' => 'image/png',
|
'mime_type' => 'image/png',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$successfulResponse = $this->putJson("/api/tenants/{$tenant->id}", [
|
$successfulResponse = $this->putJson("/api/tenants/{$tenant->codigo}", [
|
||||||
'codigo' => 'acme',
|
'codigo' => 'acme',
|
||||||
'nombre' => 'Acme Updated',
|
'nombre' => 'Acme Updated',
|
||||||
'dominio' => 'https://ACME.com:443/admin',
|
'dominio' => 'https://ACME.com:443/admin',
|
||||||
@@ -233,7 +233,7 @@ class BootstrapTenantControllerTest extends TestCase
|
|||||||
'footer_logo_id' => $ftrAttachment->id,
|
'footer_logo_id' => $ftrAttachment->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$failingResponse = $this->putJson("/api/tenants/{$otherTenant->id}", [
|
$failingResponse = $this->putJson("/api/tenants/{$otherTenant->codigo}", [
|
||||||
'codigo' => 'globex',
|
'codigo' => 'globex',
|
||||||
'nombre' => 'Globex',
|
'nombre' => 'Globex',
|
||||||
'dominio' => 'https://ACME.com/storefront',
|
'dominio' => 'https://ACME.com/storefront',
|
||||||
@@ -244,6 +244,33 @@ class BootstrapTenantControllerTest extends TestCase
|
|||||||
->assertJsonValidationErrors(['dominio']);
|
->assertJsonValidationErrors(['dominio']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_it_allows_partial_update_without_required_fields(): void
|
||||||
|
{
|
||||||
|
$tenant = Tenant::create([
|
||||||
|
'codigo' => 'acme',
|
||||||
|
'nombre' => 'Acme',
|
||||||
|
'dominio' => 'acme.com',
|
||||||
|
'primary_color' => '#ffffff',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->putJson("/api/tenants/{$tenant->codigo}", [
|
||||||
|
'primary_color' => '#000000',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('data.codigo', 'acme')
|
||||||
|
->assertJsonPath('data.nombre', 'Acme')
|
||||||
|
->assertJsonPath('data.primary_color', '#000000');
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('tenants', [
|
||||||
|
'id' => $tenant->id,
|
||||||
|
'codigo' => 'acme',
|
||||||
|
'nombre' => 'Acme',
|
||||||
|
'primary_color' => '#000000',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_it_validates_aesthetic_colors(): void
|
public function test_it_validates_aesthetic_colors(): void
|
||||||
{
|
{
|
||||||
$response = $this->postJson('/api/tenants', [
|
$response = $this->postJson('/api/tenants', [
|
||||||
|
|||||||
Reference in New Issue
Block a user