validatePhoneNumberLength.test.js 1.3 KB

123456789101112131415161718192021222324252627282930
  1. import _validatePhoneNumberLength from './validatePhoneNumberLength.js'
  2. import metadata from '../metadata.min.json' assert { type: 'json' }
  3. function validatePhoneNumberLength(...parameters) {
  4. parameters.push(metadata)
  5. return _validatePhoneNumberLength.apply(this, parameters)
  6. }
  7. describe('validatePhoneNumberLength', () => {
  8. it('should detect whether a phone number length is valid', () => {
  9. // Not a phone number.
  10. validatePhoneNumberLength('+').should.equal('NOT_A_NUMBER')
  11. validatePhoneNumberLength('abcde').should.equal('NOT_A_NUMBER')
  12. // No country supplied for a national number.
  13. validatePhoneNumberLength('123').should.equal('INVALID_COUNTRY')
  14. // Too short while the number is not considered "viable"
  15. // by Google's `libphonenumber`.
  16. validatePhoneNumberLength('2', 'US').should.equal('TOO_SHORT')
  17. validatePhoneNumberLength('+1', 'US').should.equal('TOO_SHORT')
  18. validatePhoneNumberLength('+12', 'US').should.equal('TOO_SHORT')
  19. // Test national (significant) number length.
  20. validatePhoneNumberLength('444 1 44', 'TR').should.equal('TOO_SHORT')
  21. expect(validatePhoneNumberLength('444 1 444', 'TR')).to.be.undefined
  22. validatePhoneNumberLength('444 1 4444', 'TR').should.equal('INVALID_LENGTH')
  23. validatePhoneNumberLength('444 1 4444444444', 'TR').should.equal('TOO_LONG')
  24. })
  25. })