searchPhoneNumbersInText.test.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import searchPhoneNumbersInText from './searchPhoneNumbersInText.js'
  2. import metadata from '../metadata.min.json' assert { type: 'json' }
  3. describe('searchPhoneNumbersInText', () => {
  4. it('should find phone numbers (with default country)', () => {
  5. const NUMBERS = ['+78005553535', '+12133734253']
  6. for (const number of searchPhoneNumbersInText('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', metadata)) {
  7. number.number.number.should.equal(NUMBERS[0])
  8. NUMBERS.shift()
  9. }
  10. })
  11. it('should find phone numbers', () => {
  12. const NUMBERS = ['+78005553535', '+12133734253']
  13. for (const number of searchPhoneNumbersInText('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', metadata)) {
  14. number.number.number.should.equal(NUMBERS[0])
  15. NUMBERS.shift()
  16. }
  17. })
  18. it('should find phone numbers in text', () => {
  19. const expectedNumbers = [{
  20. country: 'RU',
  21. nationalNumber: '8005553535',
  22. startsAt: 14,
  23. endsAt: 32
  24. }, {
  25. country: 'US',
  26. nationalNumber: '2133734253',
  27. startsAt: 41,
  28. endsAt: 55
  29. }]
  30. for (const number of searchPhoneNumbersInText('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', metadata)) {
  31. const expected = expectedNumbers.shift()
  32. number.startsAt.should.equal(expected.startsAt)
  33. number.endsAt.should.equal(expected.endsAt)
  34. number.number.nationalNumber.should.equal(expected.nationalNumber)
  35. number.number.country.should.equal(expected.country)
  36. }
  37. expectedNumbers.length.should.equal(0)
  38. })
  39. })