feat(phone): split phone number components into separate fields and update related models and resources
This commit is contained in:
@@ -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