feat(menu): update contact menu to dynamic content type and preserve legacy data for rollback

This commit is contained in:
2026-09-30 13:29:41 -03:00
parent 917f2dff09
commit 77dd0e2715
7 changed files with 149 additions and 116 deletions

View File

@@ -0,0 +1,48 @@
<?php
namespace Tests\Feature\Migrations;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Tests\TestCase;
class DynamicContactMenuTest extends TestCase
{
public function test_it_converts_only_contact_and_preserves_legacy_data_for_rollback(): void
{
Schema::create('menues', function (Blueprint $table): void {
$table->string('code')->primary();
$table->string('content_type');
$table->json('static_content_schema')->nullable();
});
Schema::create('tenants_menues', function (Blueprint $table): void {
$table->string('tenant_code');
$table->string('menu_code');
$table->json('static_content')->nullable();
});
DB::table('menues')->insert([
['code' => 'help.contact', 'content_type' => 'static', 'static_content_schema' => '{}'],
['code' => 'help.faq', 'content_type' => 'static', 'static_content_schema' => '{}'],
]);
$legacy = json_encode(['whatsapp' => ['whatsapp_url' => 'https://wa.me/123']], JSON_THROW_ON_ERROR);
DB::table('tenants_menues')->insert([
'tenant_code' => 'test', 'menu_code' => 'help.contact', 'static_content' => $legacy,
]);
$migration = require database_path('migrations/2026_09_30_000600_make_contact_menu_dynamic.php');
$migration->up();
$migration->up();
$this->assertDatabaseHas('menues', [
'code' => 'help.contact', 'content_type' => 'dynamic', 'static_content_schema' => null,
]);
$this->assertDatabaseHas('menues', ['code' => 'help.faq', 'content_type' => 'static', 'static_content_schema' => '{}']);
$this->assertDatabaseHas('tenants_menues', ['menu_code' => 'help.contact', 'static_content' => $legacy]);
$migration->down();
$this->assertDatabaseHas('menues', ['code' => 'help.contact', 'content_type' => 'static']);
$schema = json_decode(DB::table('menues')->where('code', 'help.contact')->value('static_content_schema'), true, flags: JSON_THROW_ON_ERROR);
$this->assertSame('required|url', $schema['whatsapp.whatsapp_url']);
$this->assertDatabaseHas('tenants_menues', ['menu_code' => 'help.contact', 'static_content' => $legacy]);
}
}

View File

@@ -338,26 +338,8 @@ class MenuSeederTest extends TestCase
], $faq->static_content_schema);
$contact = Menu::query()->where('code', 'help.contact')->firstOrFail();
$this->assertSame(Menu::CONTENT_TYPE_STATIC, $contact->content_type);
$this->assertSame('required|url', $contact->static_content_schema['whatsapp.whatsapp_url']);
$this->assertSame('required|string', $contact->static_content_schema['phone']);
$this->assertSame(
'required|array|min:1',
$contact->static_content_schema['locations.*.addresses']
);
$this->assertSame(
'required|array|size:2',
$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']);
$this->assertSame(Menu::CONTENT_TYPE_DYNAMIC, $contact->content_type);
$this->assertNull($contact->static_content_schema);
}
public function test_it_assigns_help_to_the_supported_tenants_with_faq_content(): void
@@ -385,30 +367,6 @@ class MenuSeederTest extends TestCase
'is_active' => false,
],
];
$expectedContact = [
'whatsapp' => [
'whatsapp_url' => 'https://wa.me/543412602222',
'whatsapp_label' => 'Chatea con nosotros',
],
'phone' => '+54 9 (0341) 6658247',
'locations' => [
'rosario' => [
'label' => 'Rosario',
'addresses' => [
[
'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],
],
],
],
],
];
foreach ([$sonder, $fiesta] as $tenant) {
$helpMenus = $tenant->menues()
@@ -422,10 +380,7 @@ class MenuSeederTest extends TestCase
$expectedQuestions,
$helpMenus->firstWhere('code', 'help.faq')->pivot->static_content
);
$this->assertEquals(
$expectedContact,
$helpMenus->firstWhere('code', 'help.contact')->pivot->static_content
);
$this->assertNull($helpMenus->firstWhere('code', 'help.contact')->pivot->static_content);
}
$this->assertFalse(

View File

@@ -510,7 +510,7 @@ class BootstrapTenantControllerTest extends TestCase
$tenant->menues()->sync([
$parent->code,
$staticChild->code => ['static_content' => $staticContent],
$dynamicChild->code,
$dynamicChild->code => ['static_content' => ['legacy' => 'must not be returned']],
]);
$userRole->menus()->sync([
$parent->code,