PhoneNumber.test.js.map 9.6 KB

1
  1. {"version":3,"file":"PhoneNumber.test.js","names":["metadata","type","PhoneNumber","describe","it","expect","to","phoneNumber","countryCallingCode","should","equal","country","number","ext","format","formatExtension","extension","isEqual","isNonGeographic","setExt","formatNational","be","undefined","getPossibleCountries","deep","indexOf","length"],"sources":["../source/PhoneNumber.test.js"],"sourcesContent":["import metadata from '../metadata.min.json' assert { type: 'json' }\r\nimport PhoneNumber from './PhoneNumber.js'\r\n\r\ndescribe('PhoneNumber', () => {\r\n\tit('should validate constructor arguments', () => {\r\n\t\texpect(() => new PhoneNumber()).to.throw('`countryCallingCode` not passed')\r\n\t\texpect(() => new PhoneNumber('7')).to.throw('`nationalNumber` not passed')\r\n\t\texpect(() => new PhoneNumber('7', '8005553535')).to.throw('`metadata` not passed')\r\n\t})\r\n\r\n\tit('should accept country code argument', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('RU', '8005553535', metadata)\r\n\t\tphoneNumber.countryCallingCode.should.equal('7')\r\n\t\tphoneNumber.country.should.equal('RU')\r\n\t\tphoneNumber.number.should.equal('+78005553535')\r\n\t})\r\n\r\n\tit('should format number with options', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('7', '8005553535', metadata)\r\n\t\tphoneNumber.ext = '123'\r\n\t\tphoneNumber.format('NATIONAL', {\r\n\t\t\tformatExtension: (number, extension) => `${number} доб. ${extension}`\r\n\t\t})\r\n\t\t.should.equal('8 (800) 555-35-35 доб. 123')\r\n\t})\r\n\r\n\tit('should compare phone numbers', () => {\r\n\t\tnew PhoneNumber('RU', '8005553535', metadata).isEqual(new PhoneNumber('RU', '8005553535', metadata)).should.equal(true)\r\n\t\tnew PhoneNumber('RU', '8005553535', metadata).isEqual(new PhoneNumber('7', '8005553535', metadata)).should.equal(true)\r\n\t\tnew PhoneNumber('RU', '8005553535', metadata).isEqual(new PhoneNumber('RU', '8005553536', metadata)).should.equal(false)\r\n\t})\r\n\r\n\tit('should tell if a number is non-geographic', () => {\r\n\t\tnew PhoneNumber('7', '8005553535', metadata).isNonGeographic().should.equal(false)\r\n\t\tnew PhoneNumber('870', '773111632', metadata).isNonGeographic().should.equal(true)\r\n\t})\r\n\r\n\tit('should allow setting extension', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('1', '2133734253', metadata)\r\n\t\tphoneNumber.setExt('1234')\r\n\t\tphoneNumber.ext.should.equal('1234')\r\n\t\tphoneNumber.formatNational().should.equal('(213) 373-4253 ext. 1234')\r\n\t})\r\n\r\n\tit('should return possible countries', () => {\r\n // \"599\": [\r\n // \"CW\", // \"possible_lengths\": [7, 8]\r\n // \"BQ\" // \"possible_lengths\": [7]\r\n // ]\r\n\r\n\t\tlet phoneNumber = new PhoneNumber('599', '123456', metadata)\r\n\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\tphoneNumber.getPossibleCountries().should.deep.equal([])\r\n\r\n\t\tphoneNumber = new PhoneNumber('599', '1234567', metadata)\r\n\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\tphoneNumber.getPossibleCountries().should.deep.equal(['CW', 'BQ'])\r\n\r\n\t\tphoneNumber = new PhoneNumber('599', '12345678', metadata)\r\n\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\tphoneNumber.getPossibleCountries().should.deep.equal(['CW'])\r\n\r\n\t\tphoneNumber = new PhoneNumber('599', '123456789', metadata)\r\n\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\tphoneNumber.getPossibleCountries().should.deep.equal([])\r\n\t})\r\n\r\n\tit('should return possible countries in case of ambiguity', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('1', '2223334444', metadata)\r\n\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\tphoneNumber.getPossibleCountries().indexOf('US').should.equal(0)\r\n\t\tphoneNumber.getPossibleCountries().length.should.equal(25)\r\n\t})\r\n\r\n\t// it('should return empty possible countries when no national number has been input', () => {\r\n\t// \tconst phoneNumber = new PhoneNumber('1', '', metadata)\r\n\t// \texpect(phoneNumber.country).to.be.undefined\r\n\t// \tphoneNumber.getPossibleCountries().should.deep.equal([])\r\n\t// })\r\n\r\n\tit('should return empty possible countries when not enough national number digits have been input', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('1', '222', metadata)\r\n\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\tphoneNumber.getPossibleCountries().should.deep.equal([])\r\n\t})\r\n\r\n\tit('should return possible countries in case of no ambiguity', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('US', '2133734253', metadata)\r\n\t\tphoneNumber.country.should.equal('US')\r\n\t\tphoneNumber.getPossibleCountries().should.deep.equal(['US'])\r\n\t})\r\n\r\n\tit('should return empty possible countries in case of an unknown calling code', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('777', '123', metadata)\r\n\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\tphoneNumber.getPossibleCountries().should.deep.equal([])\r\n\t})\r\n\r\n\t// it('should validate phone number length', () => {\r\n\t// \tconst phoneNumber = new PhoneNumber('RU', '800', metadata)\r\n\t// \texpect(phoneNumber.validateLength()).to.equal('TOO_SHORT')\r\n\t//\r\n\t// \tconst phoneNumberValid = new PhoneNumber('RU', '8005553535', metadata)\r\n\t// \texpect(phoneNumberValid.validateLength()).to.be.undefined\r\n\t// })\r\n})"],"mappings":"AAAA,OAAOA,QAAP,MAAqB,sBAArB,UAAqDC,IAAI,EAAE,MAA3D;AACA,OAAOC,WAAP,MAAwB,kBAAxB;AAEAC,QAAQ,CAAC,aAAD,EAAgB,YAAM;EAC7BC,EAAE,CAAC,uCAAD,EAA0C,YAAM;IACjDC,MAAM,CAAC;MAAA,OAAM,IAAIH,WAAJ,EAAN;IAAA,CAAD,CAAN,CAAgCI,EAAhC,UAAyC,iCAAzC;IACAD,MAAM,CAAC;MAAA,OAAM,IAAIH,WAAJ,CAAgB,GAAhB,CAAN;IAAA,CAAD,CAAN,CAAmCI,EAAnC,UAA4C,6BAA5C;IACAD,MAAM,CAAC;MAAA,OAAM,IAAIH,WAAJ,CAAg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