feat(phone): split phone number components into separate fields and update related models and resources
This commit is contained in:
@@ -2,10 +2,13 @@
|
||||
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use App\Domains\Core\Address\Models\Address;
|
||||
use App\Domains\Core\Auth\Models\User;
|
||||
use App\Domains\Core\Authorization\Enums\RoleCode;
|
||||
use App\Domains\Core\Authorization\Models\Role;
|
||||
use App\Domains\Core\Menu\Models\Menu;
|
||||
use App\Domains\Core\PhoneNumber\Models\PhoneNumber;
|
||||
use App\Domains\Core\Tenant\Models\SocialMedia;
|
||||
use App\Domains\Core\Tenant\Models\Tenant;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
@@ -46,6 +49,21 @@ class AdminAppMeControllerTest extends TestCase
|
||||
$tenant->menues()->sync([$catalog->code, $staff->code, $storefront->code]);
|
||||
$otherTenant->menues()->sync([$staff->code]);
|
||||
|
||||
$instagram = SocialMedia::query()->create([
|
||||
'code' => 'instagram', 'name' => 'Instagram', 'icon' => 'fa-brands fa-instagram',
|
||||
]);
|
||||
$tenant->socialMedia()->attach($instagram->code, ['url' => 'https://instagram.com/acme', 'orden' => 0]);
|
||||
$address = Address::query()->create(['label' => 'Principal', 'address_text' => 'San Martín 123']);
|
||||
$tenant->addresses()->attach($address->id, ['is_main' => true]);
|
||||
$phone = PhoneNumber::query()->create([
|
||||
'label' => 'Principal',
|
||||
'country_code' => '+54',
|
||||
'mobile_prefix' => '9',
|
||||
'area_code' => '0341',
|
||||
'local_number' => '6658247',
|
||||
]);
|
||||
$tenant->phoneNumbers()->attach($phone->id, ['is_main' => true]);
|
||||
|
||||
$user = User::factory()->create([
|
||||
'nombre_apellido' => 'Admin Acme',
|
||||
'email' => 'admin@acme.test',
|
||||
@@ -59,6 +77,11 @@ class AdminAppMeControllerTest extends TestCase
|
||||
->assertJsonPath('data.user.id', $user->id)
|
||||
->assertJsonPath('data.user.email', 'admin@acme.test')
|
||||
->assertJsonPath('data.tenant.codigo', 'acme')
|
||||
->assertJsonPath('data.tenant.social_media.0.url', 'https://instagram.com/acme')
|
||||
->assertJsonPath('data.tenant.addresses.0.address_text', 'San Martín 123')
|
||||
->assertJsonPath('data.tenant.phone_numbers.0.number', '+54 9 (0341) 6658247')
|
||||
->assertJsonPath('data.tenant.phone_numbers.0.area_code', '0341')
|
||||
->assertJsonPath('data.tenant.phone_numbers.0.local_number', '6658247')
|
||||
->assertJsonCount(1, 'data.tenant.menues')
|
||||
->assertJsonPath('data.tenant.menues.0.code', 'admin.catalog')
|
||||
->assertJsonPath('data.tenant.menues.0.label', 'Catálogo')
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Feature\Migrations;
|
||||
|
||||
use App\Domains\Core\PhoneNumber\Models\PhoneNumber;
|
||||
use App\Domains\Core\PhoneNumber\Resources\PhoneNumberResource;
|
||||
use App\Domains\Core\Tenant\Models\Tenant;
|
||||
use Illuminate\Database\QueryException;
|
||||
@@ -96,6 +97,49 @@ class ContactPhoneNumbersTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_it_splits_mobile_and_landline_numbers_and_builds_dialable_urls(): void
|
||||
{
|
||||
DB::table('phone_numbers')->insert([
|
||||
['label' => 'Móvil', 'number' => '+54 9 (0341) 6658247'],
|
||||
['label' => 'Fijo', 'number' => '+54 341 111-1111'],
|
||||
['label' => 'Local', 'number' => '0341 1234567'],
|
||||
['label' => 'Móvil sin signo', 'number' => '54 9 (0341) 6658247'],
|
||||
]);
|
||||
|
||||
$migration = require database_path('migrations/2026_09_30_000700_split_phone_number_components.php');
|
||||
$migration->up();
|
||||
|
||||
[$mobile, $landline, $local, $mobileWithoutPlus] = PhoneNumber::query()->orderBy('id')->get()->all();
|
||||
$this->assertSame('+54', $mobile->country_code);
|
||||
$this->assertSame('9', $mobile->mobile_prefix);
|
||||
$this->assertSame('0341', $mobile->area_code);
|
||||
$this->assertSame('6658247', $mobile->local_number);
|
||||
$this->assertSame('+54 9 (0341) 6658247', $mobile->number);
|
||||
$this->assertSame('tel:+5493416658247', $mobile->telUrl());
|
||||
$this->assertSame('+54 341 1111111', $landline->number);
|
||||
$this->assertSame('tel:+543411111111', $landline->telUrl());
|
||||
$this->assertSame('0341 1234567', $local->number);
|
||||
$this->assertSame('tel:03411234567', $local->telUrl());
|
||||
$this->assertSame('+54 9 (0341) 6658247', $mobileWithoutPlus->number);
|
||||
$resource = PhoneNumberResource::make($mobile)->resolve();
|
||||
$this->assertSame('9', $resource['mobile_prefix']);
|
||||
$this->assertSame('0341', $resource['area_code']);
|
||||
$this->assertSame('tel:+5493416658247', $resource['tel_url']);
|
||||
|
||||
$created = PhoneNumber::query()->create([
|
||||
'label' => 'Nuevo',
|
||||
'area_code' => '0341',
|
||||
'local_number' => '7777777',
|
||||
]);
|
||||
$this->assertSame('+54', $created->fresh()->country_code);
|
||||
$this->assertSame('9', $created->fresh()->mobile_prefix);
|
||||
$this->assertSame('+54 9 (0341) 7777777', $created->number);
|
||||
$this->assertSame('tel:+5493417777777', $created->telUrl());
|
||||
|
||||
$migration->down();
|
||||
$this->assertDatabaseHas('phone_numbers', ['id' => $mobile->id, 'number' => '+54 9 0341 6658247']);
|
||||
}
|
||||
|
||||
private function contact(string $tenant, mixed $phone): void
|
||||
{
|
||||
DB::table('tenants_menues')->insert([
|
||||
|
||||
Reference in New Issue
Block a user