Files
portal/app/tests/Unit/Services/PhonePrefixServiceTest.php
T
Дмитрий 5f08459615 feat(services): PhonePrefixService — phone → federal district bit (MVP)
Маппинг мобильных + 30+ ABC-кодов городов на 8 ФО RF (synchronized
с projects.region_mask битами). Мобильные → all-districts (255).
Полный Минсвязи справочник отложен на Plan 5+.

Spec: §6 step 2 routing geo-filter.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 18:36:43 +03:00

65 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Services\PhonePrefixService;
it('mobile prefix 9XX returns all-districts mask', function (): void {
$service = new PhonePrefixService;
expect($service->resolveDistrictBit('79991234567'))->toBe(0xFF);
});
it('Moscow code 495 returns Central district bit (1)', function (): void {
$service = new PhonePrefixService;
expect($service->resolveDistrictBit('74951234567'))->toBe(1);
});
it('Saint-Petersburg code 812 returns Northwest district bit (2)', function (): void {
$service = new PhonePrefixService;
expect($service->resolveDistrictBit('78121234567'))->toBe(2);
});
it('Yekaterinburg code 343 returns Ural district bit (32)', function (): void {
$service = new PhonePrefixService;
expect($service->resolveDistrictBit('73431234567'))->toBe(32);
});
it('unknown code returns all-districts mask (defensive default)', function (): void {
$service = new PhonePrefixService;
expect($service->resolveDistrictBit('70001234567'))->toBe(0xFF);
});
it('rejects invalid phone formats', function (): void {
$service = new PhonePrefixService;
expect(fn () => $service->resolveDistrictBit('123'))->toThrow(InvalidArgumentException::class);
expect(fn () => $service->resolveDistrictBit('+79991234567'))->toThrow(InvalidArgumentException::class);
expect(fn () => $service->resolveDistrictBit('89991234567'))->toThrow(InvalidArgumentException::class);
});
it('phoneMatchesRegions: include + matching bit', function (): void {
$service = new PhonePrefixService;
expect($service->phoneMatchesRegions('74951234567', regionMask: 1, regionMode: 'include'))->toBeTrue();
expect($service->phoneMatchesRegions('74951234567', regionMask: 2, regionMode: 'include'))->toBeFalse();
});
it('phoneMatchesRegions: exclude inverts logic', function (): void {
$service = new PhonePrefixService;
expect($service->phoneMatchesRegions('74951234567', regionMask: 1, regionMode: 'exclude'))->toBeFalse();
expect($service->phoneMatchesRegions('74951234567', regionMask: 2, regionMode: 'exclude'))->toBeTrue();
});
it('mobile (all-districts) always passes include any-bit', function (): void {
$service = new PhonePrefixService;
expect($service->phoneMatchesRegions('79991234567', regionMask: 1, regionMode: 'include'))->toBeTrue();
expect($service->phoneMatchesRegions('79991234567', regionMask: 255, regionMode: 'include'))->toBeTrue();
});