From 1563a60ede15398bb2f6be9c5145c92512da2acd Mon Sep 17 00:00:00 2001 From: Saeed Ghasemi Date: Mon, 1 Jan 2024 13:52:32 +0330 Subject: [PATCH] Chore: add SamanTel phone number support (#42) * chore: add SamanTel phone number support * chore: add test for SamanTel phone number --- lib/src/constants/phone_number/constants.dart | 13 +++++++++++++ lib/src/core/phone_number/models.dart | 1 + test/test_phone_number.dart | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/lib/src/constants/phone_number/constants.dart b/lib/src/constants/phone_number/constants.dart index d978c25..1e38d67 100644 --- a/lib/src/constants/phone_number/constants.dart +++ b/lib/src/constants/phone_number/constants.dart @@ -189,12 +189,22 @@ const shatelMobile = { ), }; +const samanTel = { + '999': OperatorDetail( + provinces: [], + base: 'کشوری', + type: SimCardType.both, + operator: Operator.samanTel, + ), +}; + final List prefixes = [ ...MCI.keys, ...taliya.keys, ...rightTel.keys, ...irancell.keys, ...shatelMobile.keys, + ...samanTel.keys, ]; final operators = { @@ -203,6 +213,7 @@ final operators = { ...irancell, ...shatelMobile, ...rightTel, + ...samanTel, }; const shatelName = 'شاتل موبایل'; @@ -214,3 +225,5 @@ const irancellName = 'ایرانسل'; const taliaName = 'تالیا'; const rightTelName = 'رایتل'; + +const samanTelName = 'سامانتل'; diff --git a/lib/src/core/phone_number/models.dart b/lib/src/core/phone_number/models.dart index 8039b9d..49c0197 100644 --- a/lib/src/core/phone_number/models.dart +++ b/lib/src/core/phone_number/models.dart @@ -73,6 +73,7 @@ class Operator { static const irancell = Operator._(irancellName); static const taliya = Operator._(taliaName); static const rightTel = Operator._(rightTelName); + static const samanTel = Operator._(samanTelName); @override bool operator ==(Object other) => diff --git a/test/test_phone_number.dart b/test/test_phone_number.dart index d60f602..c28611d 100644 --- a/test/test_phone_number.dart +++ b/test/test_phone_number.dart @@ -35,6 +35,12 @@ void main() { expect(number5?.operator?.name, 'ایرانسل'); expect(number5?.type, SimCardType.both); + final number6 = getPhoneNumberDetail('09990880440'); + + expect(number6?.base, 'کشوری'); + expect(number6?.operator?.name, 'سامانتل'); + expect(number6?.type, SimCardType.both); + expect(getPhoneNumberDetail('09022002580')?.provinces?.length ?? 0, 0); /// Should return null, because it's not an iranian phone number @@ -52,6 +58,10 @@ void main() { expect(phoneNumberValidator('00989022002580'), true); expect(phoneNumberValidator('9022002580'), true); + expect(phoneNumberValidator('9992002580'), true); + expect(phoneNumberValidator('00989992002580'), true); + expect(phoneNumberValidator('+989992002580'), true); + expect(phoneNumberValidator('09802002580'), false); }); @@ -63,6 +73,8 @@ void main() { expect(getPhonePrefix('09123200007'), '912'); expect(getPhonePrefix('09300880440'), '930'); + expect(getPhonePrefix('09990880440'), '999'); + /// Should return the prefix with 98 or +98 expect(getPhonePrefix('+989022002580'), '902'); expect(getPhonePrefix('989122002580'), '912');