EmailHelperTests.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const { expect } = require('chai')
  2. const {
  3. parseEmail,
  4. } = require('../../../../app/src/Features/Helpers/EmailHelper')
  5. describe('EmailHelper', function () {
  6. it('should parse a single email', function () {
  7. const address = 'test@example.com'
  8. const expected = 'test@example.com'
  9. expect(parseEmail(address)).to.equal(expected)
  10. expect(parseEmail(address, true)).to.equal(expected)
  11. })
  12. it('should parse a valid email address', function () {
  13. const address = '"Test Person" <test@example.com>'
  14. const expected = 'test@example.com'
  15. expect(parseEmail(address)).to.equal(null)
  16. expect(parseEmail(address, true)).to.equal(expected)
  17. })
  18. it('should return null for garbage input', function () {
  19. const cases = [
  20. undefined,
  21. null,
  22. '',
  23. 42,
  24. ['test@example.com'],
  25. {},
  26. { length: 42 },
  27. { trim: true, match: true },
  28. { toString: true },
  29. ]
  30. for (const input of cases) {
  31. expect(parseEmail(input)).to.equal(null, input)
  32. expect(parseEmail(input, true)).to.equal(null, input)
  33. }
  34. })
  35. it('should return null for an invalid single email', function () {
  36. const address = 'testexample.com'
  37. expect(parseEmail(address)).to.equal(null)
  38. expect(parseEmail(address, true)).to.equal(null)
  39. })
  40. it('should return null for an invalid email address', function () {
  41. const address = '"Test Person" test@example.com>'
  42. expect(parseEmail(address)).to.equal(null)
  43. expect(parseEmail(address, true)).to.equal(null)
  44. })
  45. it('should return null for a group of addresses', function () {
  46. const address = 'Group name:test1@example.com,test2@example.com;'
  47. expect(parseEmail(address)).to.equal(null)
  48. expect(parseEmail(address, true)).to.equal(null)
  49. })
  50. })