checkNumberLength.test.js 1.7 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', function () {
  6. it('should check phone number length', function () {
  7. // Too short.
  8. checkNumberLength('800555353', 'FIXED_LINE', 'RU').should.equal('TOO_SHORT'); // Normal.
  9. checkNumberLength('8005553535', 'FIXED_LINE', 'RU').should.equal('IS_POSSIBLE'); // Too long.
  10. checkNumberLength('80055535355', 'FIXED_LINE', 'RU').should.equal('TOO_LONG'); // No such type.
  11. checkNumberLength('169454850', 'VOIP', 'AC').should.equal('INVALID_LENGTH'); // No such possible length.
  12. checkNumberLength('1694548', undefined, 'AD').should.equal('INVALID_LENGTH'); // FIXED_LINE_OR_MOBILE
  13. checkNumberLength('1694548', 'FIXED_LINE_OR_MOBILE', 'AD').should.equal('INVALID_LENGTH'); // No mobile phones.
  14. checkNumberLength('8123', 'FIXED_LINE_OR_MOBILE', 'TA').should.equal('IS_POSSIBLE'); // No "possible lengths" for "mobile".
  15. checkNumberLength('81234567', 'FIXED_LINE_OR_MOBILE', 'SZ').should.equal('IS_POSSIBLE');
  16. });
  17. it('should work for old metadata', function () {
  18. var _oldMetadata = new Metadata(oldMetadata);
  19. _oldMetadata.country('RU');
  20. checkNumberLengthForType('8005553535', 'FIXED_LINE', _oldMetadata).should.equal('IS_POSSIBLE');
  21. });
  22. });
  23. function checkNumberLength(number, type, country) {
  24. var _metadata = new Metadata(metadata);
  25. _metadata.country(country);
  26. return checkNumberLengthForType(number, type, _metadata);
  27. }
  28. //# sourceMappingURL=checkNumberLength.test.js.map