Skip to content

Commit

Permalink
Merge pull request #25 from OLIOEX/develop
Browse files Browse the repository at this point in the history
Fix getNumType method and add tests
  • Loading branch information
rililive authored Nov 4, 2021
2 parents 4a0553d + 043a8db commit 946c7c4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/PhoneInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from 'react-native';
import Country from './country';
import Flags from './resources/flags';
import PhoneNumber from './phoneNumber';
import PhoneNumber from './PhoneNumber';
import styles from './styles';
import CountryPicker from './CountryPicker';
import { ReactNativePhoneInputProps } from './typings';
Expand Down
4 changes: 2 additions & 2 deletions src/phoneNumber.tsx → src/PhoneNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ class PhoneNumber {

getNumberType(number, iso2) {
const phoneInfo = this.parse(number, iso2);
const type = phoneInfo ? phoneUtil.getNumberType(phoneInfo) : -1;
return _.findKey((numType, noType) => noType === type);
const typeIndex = phoneInfo ? phoneUtil.getNumberType(phoneInfo) : -1;
return _.findKey(numberType, (noType) => noType === typeIndex);
}

// eslint-disable-next-line class-methods-use-this
Expand Down
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import PhoneInput from './PhoneInput';

export { default as CountryPicker } from './CountryPicker';
export { default as CountryList } from './resources/countries.json';
export { default as PhoneNumber } from './PhoneNumber';
export default PhoneInput;
25 changes: 25 additions & 0 deletions tests/PhoneNumber.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect } from 'chai';
import PhoneNumber from '../src/PhoneNumber';

describe('getNumberType', () => {
it('returns UNKNOWN type', () => {
const number = '+44000';
const iso2 = 'gb';
const numberType = PhoneNumber.getNumberType(number, iso2);
expect(numberType).to.equal('UNKNOWN');
});

it('returns MOBILE type', () => {
const number = '+447900000001';
const iso2 = 'gb';
const numberType = PhoneNumber.getNumberType(number, iso2);
expect(numberType).to.equal('MOBILE');
});

it('returns FIXED_LINE type', () => {
const number = '+442072212217';
const iso2 = 'gb';
const numberType = PhoneNumber.getNumberType(number, iso2);
expect(numberType).to.equal('FIXED_LINE');
});
});
7 changes: 0 additions & 7 deletions tests/index.test.ts

This file was deleted.

0 comments on commit 946c7c4

Please sign in to comment.