isPossiblePhoneNumber.test.js 1.3 KB

123456789101112131415161718192021222324252627
  1. import _isPossiblePhoneNumber from './isPossiblePhoneNumber.js'
  2. import metadata from '../metadata.min.json' assert { type: 'json' }
  3. import oldMetadata from '../test/metadata/1.0.0/metadata.min.json' assert { type: 'json' }
  4. function isPossiblePhoneNumber(...parameters) {
  5. parameters.push(metadata)
  6. return _isPossiblePhoneNumber.apply(this, parameters)
  7. }
  8. describe('isPossiblePhoneNumber', () => {
  9. it('should detect whether a phone number is possible', () => {
  10. isPossiblePhoneNumber('8 (800) 555 35 35', 'RU').should.equal(true)
  11. isPossiblePhoneNumber('8 (800) 555 35 35 0', 'RU').should.equal(false)
  12. isPossiblePhoneNumber('Call: 8 (800) 555 35 35', 'RU').should.equal(false)
  13. isPossiblePhoneNumber('8 (800) 555 35 35', { defaultCountry: 'RU' }).should.equal(true)
  14. isPossiblePhoneNumber('+7 (800) 555 35 35').should.equal(true)
  15. isPossiblePhoneNumber('+7 1 (800) 555 35 35').should.equal(false)
  16. isPossiblePhoneNumber(' +7 (800) 555 35 35').should.equal(false)
  17. isPossiblePhoneNumber(' ').should.equal(false)
  18. })
  19. it('should detect whether a phone number is possible when using old metadata', () => {
  20. expect(() => _isPossiblePhoneNumber('8 (800) 555 35 35', 'RU', oldMetadata))
  21. .to.throw('Missing "possibleLengths" in metadata.')
  22. _isPossiblePhoneNumber('+888 123 456 78901', oldMetadata).should.equal(true)
  23. })
  24. })