feat(menu): update validation rules and structure for contact content in MenuSeeder and related tests

This commit is contained in:
2026-07-24 09:41:13 -03:00
parent 460eec3c78
commit f6ce85cbde
3 changed files with 75 additions and 17 deletions

View File

@@ -48,10 +48,13 @@ class MenuSeeder extends Seeder
'locations' => 'required|array|min:1', 'locations' => 'required|array|min:1',
'locations.*.label' => 'required|string', 'locations.*.label' => 'required|string',
'locations.*.addresses' => 'required|array|min:1', 'locations.*.addresses' => 'required|array|min:1',
'locations.*.addresses.*' => 'required|string', 'locations.*.addresses.*' => 'required|array:label,address,coordinates',
'map_locations' => 'required|array', 'locations.*.addresses.*.label' => 'required|string',
'map_locations.*' => 'required|array|size:2', 'locations.*.addresses.*.address' => 'required|string',
'map_locations.*.*' => 'required|numeric', 'locations.*.addresses.*.coordinates' => 'required|array|size:2',
'locations.*.addresses.*.coordinates.0' => 'required|numeric|between:-90,90',
'locations.*.addresses.*.coordinates.1' => 'required|numeric|between:-180,180',
'map_locations' => 'prohibited',
], ],
'route' => '/ayuda/contacto', 'route' => '/ayuda/contacto',
], ],
@@ -127,15 +130,19 @@ class MenuSeeder extends Seeder
'rosario' => [ 'rosario' => [
'label' => 'Rosario', 'label' => 'Rosario',
'addresses' => [ 'addresses' => [
'Av. San Lorenzo 1542', [
'label' => 'Gigante de Arroyito',
'address' => 'Av. Génova 640, Rosario',
'coordinates' => [-32.913997, -60.674567],
],
[
'label' => 'Telepagos',
'address' => 'Rioja 1150, piso 12, dpto. 3, Rosario',
'coordinates' => [-32.946820, -60.639320],
],
], ],
], ],
], ],
'map_locations' => [
'gigante_de_arroyito' => [-32.913997, -60.674567],
'punto_centro' => [-32.946820, -60.639320],
'punto_sur' => [-32.971510, -60.650640],
],
]; ];
foreach ($tenants as $tenant) { foreach ($tenants as $tenant) {

View File

@@ -6,6 +6,7 @@ use App\Domains\Attachable\Enums\AttachmentType;
use App\Domains\Attachable\Models\Attachment; use App\Domains\Attachable\Models\Attachment;
use App\Domains\Menu\Models\Menu; use App\Domains\Menu\Models\Menu;
use App\Domains\Tenant\Models\Tenant; use App\Domains\Tenant\Models\Tenant;
use Database\Seeders\MenuSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase; use Tests\TestCase;
@@ -98,6 +99,43 @@ class TenantMenuControllerTest extends TestCase
]); ]);
} }
public function test_contact_content_requires_coordinates_inside_each_address(): void
{
$tenant = $this->createTenant();
$this->seed(MenuSeeder::class);
$this->postJson("/api/{$tenant->codigo}/menues/help.contact", [
'static_content' => [
'whatsapp' => [
'whatsapp_url' => 'https://wa.me/543412602222',
'whatsapp_label' => 'Chatea con nosotros',
],
'phone' => '+54 9 (0341) 6658247',
'locations' => [
'rosario' => [
'label' => 'Rosario',
'addresses' => [
[
'label' => 'Av. San Lorenzo 1542',
'address' => 'Av. San Lorenzo 1542, Rosario',
'coordinates' => [-91, -181],
],
],
],
],
'map_locations' => [
'legacy_point' => [-32.946820, -60.639320],
],
],
])
->assertUnprocessable()
->assertJsonValidationErrors([
'static_content.locations.rosario.addresses.0.coordinates.0',
'static_content.locations.rosario.addresses.0.coordinates.1',
'static_content.map_locations',
]);
}
private function createTenant(): Tenant private function createTenant(): Tenant
{ {
$headerLogo = $this->createAttachment('header.png'); $headerLogo = $this->createAttachment('header.png');

View File

@@ -50,8 +50,17 @@ class MenuSeederTest extends TestCase
); );
$this->assertSame( $this->assertSame(
'required|array|size:2', 'required|array|size:2',
$contact->static_content_schema['map_locations.*'] $contact->static_content_schema['locations.*.addresses.*.coordinates']
); );
$this->assertSame(
'required|string',
$contact->static_content_schema['locations.*.addresses.*.address']
);
$this->assertSame(
'required|numeric|between:-90,90',
$contact->static_content_schema['locations.*.addresses.*.coordinates.0']
);
$this->assertSame('prohibited', $contact->static_content_schema['map_locations']);
} }
public function test_it_assigns_help_to_the_supported_tenants_with_faq_content(): void public function test_it_assigns_help_to_the_supported_tenants_with_faq_content(): void
@@ -89,15 +98,19 @@ class MenuSeederTest extends TestCase
'rosario' => [ 'rosario' => [
'label' => 'Rosario', 'label' => 'Rosario',
'addresses' => [ 'addresses' => [
'Av. San Lorenzo 1542', [
'label' => 'Gigante de Arroyito',
'address' => 'Av. Génova 640, Rosario',
'coordinates' => [-32.913997, -60.674567],
],
[
'label' => 'Telepagos',
'address' => 'Rioja 1150, piso 12, dpto. 3, Rosario',
'coordinates' => [-32.946820, -60.639320],
],
], ],
], ],
], ],
'map_locations' => [
'gigante_de_arroyito' => [-32.913997, -60.674567],
'punto_centro' => [-32.946820, -60.639320],
'punto_sur' => [-32.971510, -60.650640],
],
]; ];
foreach ([$sonder, $fiesta] as $tenant) { foreach ([$sonder, $fiesta] as $tenant) {