Skip to content

Commit

Permalink
(#9531) Update google-libphonenumber and types
Browse files Browse the repository at this point in the history
### Description

Updates [google-libphonenumber](https://www.npmjs.com/package/google-libphonenumber) and [@types/google-libphonenumber](https://www.npmjs.com/package/@types/google-libphonenumber) to their latest versions.

### Other changes

N/A 

### Tested

`phoneNumbers.test.ts` updated for new metadata included in the updated dependencies. 

### Backwards compatibility

Yes

### Documentation

N/A
  • Loading branch information
MuckT authored Apr 30, 2022
1 parent 2453434 commit 6ea82bf
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/sdk/phone-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
"@celo/utils": "2.0.1-dev",
"@types/country-data": "^0.0.0",
"@types/ethereumjs-util": "^5.2.0",
"@types/google-libphonenumber": "^7.4.17",
"@types/google-libphonenumber": "^7.4.23",
"@types/node": "^10.12.18",
"country-data": "^0.0.31",
"fp-ts": "2.1.1",
"io-ts": "2.0.1",
"google-libphonenumber": "^3.2.15"
"google-libphonenumber": "^3.2.27"
},
"devDependencies": {
"@celo/flake-tracker": "0.0.1-dev",
Expand Down
31 changes: 31 additions & 0 deletions packages/sdk/phone-utils/src/phoneNumbers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const COUNTRY_CODES = {
AR: '+54',
MX: '+52',
LR: '+231',
CI: '+225',
}

const TEST_PHONE_NUMBERS = {
Expand All @@ -36,12 +37,15 @@ const TEST_PHONE_NUMBERS = {
VALID_MX_2: '1 33 1234-5678',
VALID_MX_3: '+52 1 33 1234-5678',
VALID_LR: '881551952',
VALID_CI: '+225 2122003801',
FORMATTED_AR: '+5491126431111',
FORMATTED_MX: '+523312345678',
FORMATTED_LR: '+231881551952',
FORMATTED_CI: '+2252122003801',
DISPLAY_AR: '9 11 2643-1111',
DISPLAY_MX: '33 1234 5678',
DISPLAY_LR: '88 155 1952',
DISPLAY_CI: '21 22 0 03801',
INVALID_EMPTY: '',
TOO_SHORT: '123',
VALID_E164: '+141555544444',
Expand Down Expand Up @@ -134,6 +138,12 @@ describe('Phone number formatting and utilities', () => {
TEST_PHONE_NUMBERS.FORMATTED_LR
)
})

it('Format CI phone with country code', () => {
expect(getE164Number(TEST_PHONE_NUMBERS.VALID_CI, COUNTRY_CODES.CI)).toBe(
TEST_PHONE_NUMBERS.FORMATTED_CI
)
})
})

describe('Display formatting', () => {
Expand Down Expand Up @@ -212,6 +222,12 @@ describe('Phone number formatting and utilities', () => {
TEST_PHONE_NUMBERS.DISPLAY_LR
)
})

it('Format CI phone with no country code', () => {
expect(getDisplayPhoneNumber(TEST_PHONE_NUMBERS.VALID_CI, COUNTRY_CODES.CI)).toBe(
TEST_PHONE_NUMBERS.DISPLAY_CI
)
})
})

describe('Number Parsing', () => {
Expand Down Expand Up @@ -254,25 +270,37 @@ describe('Phone number formatting and utilities', () => {
regionCode: 'MX',
})
})

it('Format CI phone #', () => {
expect(parsePhoneNumber(TEST_PHONE_NUMBERS.VALID_CI, COUNTRY_CODES.CI)).toMatchObject({
e164Number: TEST_PHONE_NUMBERS.FORMATTED_CI,
displayNumber: TEST_PHONE_NUMBERS.DISPLAY_CI,
countryCode: 225,
regionCode: 'CI',
})
})
})

describe('Other phone helper methods', () => {
it('gets country code', () => {
expect(getCountryCode(TEST_PHONE_NUMBERS.VALID_US_3)).toBe(1)
expect(getCountryCode(TEST_PHONE_NUMBERS.VALID_DE_3)).toBe(49)
expect(getCountryCode(TEST_PHONE_NUMBERS.VALID_AR_3)).toBe(54)
expect(getCountryCode(TEST_PHONE_NUMBERS.VALID_CI)).toBe(225)
})

it('gets region code', () => {
expect(getRegionCode(TEST_PHONE_NUMBERS.VALID_US_3)).toBe('US')
expect(getRegionCode(TEST_PHONE_NUMBERS.VALID_DE_3)).toBe('DE')
expect(getRegionCode(TEST_PHONE_NUMBERS.VALID_AR_3)).toBe('AR')
expect(getRegionCode(TEST_PHONE_NUMBERS.VALID_CI)).toBe('CI')
})

it('gets region code from country code', () => {
expect(getRegionCodeFromCountryCode(COUNTRY_CODES.US)).toBe('US')
expect(getRegionCodeFromCountryCode(COUNTRY_CODES.DE)).toBe('DE')
expect(getRegionCodeFromCountryCode(COUNTRY_CODES.AR)).toBe('AR')
expect(getRegionCodeFromCountryCode(COUNTRY_CODES.CI)).toBe('CI')
})

it('checks if number is e164', () => {
Expand All @@ -291,18 +319,21 @@ describe('Phone number formatting and utilities', () => {
expect(getExampleNumber(COUNTRY_CODES.AR)).toBe('000 0000-0000')
expect(getExampleNumber(COUNTRY_CODES.DE)).toBe('000 000000')
expect(getExampleNumber(COUNTRY_CODES.US)).toBe('(000) 000-0000')
expect(getExampleNumber(COUNTRY_CODES.CI)).toBe('00 00 0 00000')
})

it('gets example by country', () => {
expect(getExampleNumber(COUNTRY_CODES.AR, false)).toBe('011 2345-6789')
expect(getExampleNumber(COUNTRY_CODES.DE, false)).toBe('030 123456')
expect(getExampleNumber(COUNTRY_CODES.US, false)).toBe('(201) 555-0123')
expect(getExampleNumber(COUNTRY_CODES.CI, false)).toBe('21 23 4 56789')
})

it('gets example by country showing zeros in international way', () => {
expect(getExampleNumber(COUNTRY_CODES.AR, true, true)).toBe('+54 00 0000-0000')
expect(getExampleNumber(COUNTRY_CODES.DE, true, true)).toBe('+49 00 000000')
expect(getExampleNumber(COUNTRY_CODES.US, true, true)).toBe('+1 000-000-0000')
expect(getExampleNumber(COUNTRY_CODES.CI, true, true)).toBe('+225 00 00 0 00000')
})
})
})
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4881,6 +4881,11 @@
resolved "https://registry.yarnpkg.com/@types/google-libphonenumber/-/google-libphonenumber-7.4.17.tgz#26974213353cb459e403a5740812115a596cf170"
integrity sha512-NdqFHXBGxwiGjJn7dTAjcCckgxE+LbE3jik6/SNiC9ZfG4BxHJM1X6m8w+/ZpSGRN5s0+4dIL+MaD/KSXywp1g==

"@types/google-libphonenumber@^7.4.23":
version "7.4.23"
resolved "https://registry.yarnpkg.com/@types/google-libphonenumber/-/google-libphonenumber-7.4.23.tgz#c44c9125d45f042943694d605fd8d8d796cafc3b"
integrity sha512-C3ydakLTQa8HxtYf9ge4q6uT9krDX8smSIxmmW3oACFi5g5vv6T068PRExF7UyWbWpuYiDG8Nm24q2X5XhcZWw==

"@types/graceful-fs@^4.1.2":
version "4.1.3"
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.3.tgz#039af35fe26bec35003e8d86d2ee9c586354348f"
Expand Down Expand Up @@ -13754,6 +13759,11 @@ google-libphonenumber@^3.2.15:
resolved "https://registry.yarnpkg.com/google-libphonenumber/-/google-libphonenumber-3.2.15.tgz#3a01dc554dbf83c754f249c16df3605e5d154bb9"
integrity sha512-tbCIuzMoH34RdrbFRw5kijAZn/p6JMQvsgtr1glg2ugbwqrMPlOL8pHNK8cyGo9B6SXpcMm4hdyDqwomR+HPRg==

google-libphonenumber@^3.2.27:
version "3.2.27"
resolved "https://registry.yarnpkg.com/google-libphonenumber/-/google-libphonenumber-3.2.27.tgz#06a0c1d42be712a6fd4189e2e3b07fc36cacee01"
integrity sha512-et3QlrfWemNPhyUfXZmJG8TfzitfAN71ygNI15+B35zNge/7vyZxkpDsc13oninkf8RAtN2kNEzvMr4L1n3vfQ==

google-p12-pem@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/google-p12-pem/-/google-p12-pem-1.0.2.tgz#c8a3843504012283a0dbffc7430b7c753ecd4b07"
Expand Down

0 comments on commit 6ea82bf

Please sign in to comment.