checkNumberLength.test.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import Metadata from '../metadata.js'
  2. import metadata from '../../metadata.max.json' assert { type: 'json' }
  3. import oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' assert { type: 'json' }
  4. import { checkNumberLengthForType } from './checkNumberLength.js'
  5. describe('checkNumberLength', () => {
  6. it('should check phone number length', () => {
  7. // Too short.
  8. checkNumberLength('800555353', 'FIXED_LINE', 'RU').should.equal('TOO_SHORT')
  9. // Normal.
  10. checkNumberLength('8005553535', 'FIXED_LINE', 'RU').should.equal('IS_POSSIBLE')
  11. // Too long.
  12. checkNumberLength('80055535355', 'FIXED_LINE', 'RU').should.equal('TOO_LONG')
  13. // No such type.
  14. checkNumberLength('169454850', 'VOIP', 'AC').should.equal('INVALID_LENGTH')
  15. // No such possible length.
  16. checkNumberLength('1694548', undefined, 'AD').should.equal('INVALID_LENGTH')
  17. // FIXED_LINE_OR_MOBILE
  18. checkNumberLength('1694548', 'FIXED_LINE_OR_MOBILE', 'AD').should.equal('INVALID_LENGTH')
  19. // No mobile phones.
  20. checkNumberLength('8123', 'FIXED_LINE_OR_MOBILE', 'TA').should.equal('IS_POSSIBLE')
  21. // No "possible lengths" for "mobile".
  22. checkNumberLength('81234567', 'FIXED_LINE_OR_MOBILE', 'SZ').should.equal('IS_POSSIBLE')
  23. })
  24. it('should work for old metadata', function() {
  25. const _oldMetadata = new Metadata(oldMetadata)
  26. _oldMetadata.country('RU')
  27. checkNumberLengthForType('8005553535', 'FIXED_LINE', _oldMetadata).should.equal('IS_POSSIBLE')
  28. })
  29. })
  30. function checkNumberLength(number, type, country) {
  31. const _metadata = new Metadata(metadata)
  32. _metadata.country(country)
  33. return checkNumberLengthForType(number, type, _metadata)
  34. }