Skip to content

Commit

Permalink
Chore: add SamanTel phone number support (#42)
Browse files Browse the repository at this point in the history
* chore: add SamanTel phone number support

* chore: add test for SamanTel phone number
  • Loading branch information
sgsm74 committed Jan 1, 2024
1 parent d558906 commit 1563a60
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/src/constants/phone_number/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,22 @@ const shatelMobile = {
),
};

const samanTel = {
'999': OperatorDetail(
provinces: [],
base: 'کشوری',
type: SimCardType.both,
operator: Operator.samanTel,
),
};

final List<String> prefixes = [
...MCI.keys,
...taliya.keys,
...rightTel.keys,
...irancell.keys,
...shatelMobile.keys,
...samanTel.keys,
];

final operators = {
Expand All @@ -203,6 +213,7 @@ final operators = {
...irancell,
...shatelMobile,
...rightTel,
...samanTel,
};

const shatelName = 'شاتل موبایل';
Expand All @@ -214,3 +225,5 @@ const irancellName = 'ایرانسل';
const taliaName = 'تالیا';

const rightTelName = 'رایتل';

const samanTelName = 'سامانتل';
1 change: 1 addition & 0 deletions lib/src/core/phone_number/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
12 changes: 12 additions & 0 deletions test/test_phone_number.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
});

Expand All @@ -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');
Expand Down

0 comments on commit 1563a60

Please sign in to comment.