Guest User

Untitled

a guest
Dec 26th, 2017
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. /* eslint-env jasmine */
  2.  
  3. import { validate, suggest } from './email';
  4.  
  5. describe('email', () => {
  6. describe('validate', () => {
  7. it('should correctly validate correct email addresses', (done) => {
  8. const promises = [
  9. validate('user@gmail.com'),
  10. validate('user+dix@host.ca'),
  11. validate('user+dix@sub.domain.tld'),
  12. validate('gianni@butt.zone')
  13. ];
  14.  
  15. Promise.all(promises).then(done, done.fail);
  16. });
  17.  
  18. it('should correctly validate incorrect email addresses', (done) => {
  19. const promises = [
  20. validate('@').then(() => { throw 'fail'; }, () => true),
  21. validate('user name@domain.com').then(() => { throw 'fail'; }, () => true),
  22. validate('user@domain lol.com').then(() => { throw 'fail'; }, () => true),
  23. validate('user@domain.c om').then(() => { throw 'fail'; }, () => true),
  24. validate('gmail.com').then(() => { throw 'fail'; }, () => true),
  25. validate('@gmail.com').then(() => { throw 'fail'; }, () => true),
  26. validate('user@gmail.').then(() => { throw 'fail'; }, () => true),
  27. validate('user@.com').then(() => { throw 'fail'; }, () => true)
  28. ];
  29.  
  30. Promise.all(promises).then(done, done.fail);
  31. });
  32.  
  33. it('should correctly validate an email address with unicode characters', (done) => {
  34. validate('snædis@💩.com').then(done, done.fail);
  35. });
  36. });
  37.  
  38. describe('suggest', () => {
  39. it('should not suggest correct domains & tlds', (done) => {
  40. const promises = [
  41. suggest('user@gmail.com').then(e => { throw `fail: ${e}`; }, () => true),
  42. suggest('user@hotmail.co.uk').then(e => { throw `fail: ${e}`; }, () => true)
  43. ];
  44.  
  45. Promise.all(promises).then(done, done.fail);
  46. });
  47.  
  48. it('should not suggest correct but unknown domains & tlds', (done) => {
  49. const promises = [
  50. suggest('user@universe.com').then(e => { throw `fail: ${e}`; }, () => true)
  51. ];
  52.  
  53. Promise.all(promises).then(done, done.fail);
  54. });
  55.  
  56. it('should not suggest emails that are too far gone', (done) => {
  57. const promises = [
  58. suggest('user@gmaillolobuzz').then(e => { throw `fail: ${e}`; }, () => true),
  59. suggest('user@mailhotmail.co.uk.mailhotmail').then(e => { throw `fail: ${e}`; }, () => true)
  60. ];
  61.  
  62. Promise.all(promises).then(done, done.fail);
  63. });
  64.  
  65. it('should suggest misspelled domains', (done) => {
  66. const promises = [
  67. suggest('user@gnail.com').then(e => expect(e).toEqual('user@gmail.com'), () => { throw 'fail: user@gnail.com'; }),
  68. suggest('user@hotmale.co.uk').then(e => expect(e).toEqual('user@hotmail.co.uk'), () => { throw 'fail: user@hotmale.co.uk'; })
  69. ];
  70.  
  71. Promise.all(promises).then(done, done.fail);
  72. });
  73.  
  74. it('should suggest misspelled TLDs', (done) => {
  75. const promises = [
  76. suggest('user@gmail.cmo').then(e => expect(e).toEqual('user@gmail.com'), () => { throw 'fail: user@gmail.cmo'; }),
  77. suggest('user@gmail.cm').then(e => expect(e).toEqual('user@gmail.com'), () => { throw 'fail: user@gmail.cm'; }),
  78. suggest('user@hotmail.ci.uk').then(e => expect(e).toEqual('user@hotmail.co.uk'), () => { throw 'fail: user@hotmail.ci.uk'; }),
  79. suggest('user@hotmail.couk').then(e => expect(e).toEqual('user@hotmail.co.uk'), () => { throw 'fail: user@hotmail.couk'; })
  80. ];
  81.  
  82. Promise.all(promises).then(done, done.fail);
  83. });
  84.  
  85. it('should suggest misspelled TLDs for unknown domains', (done) => {
  86. const promises = [
  87. suggest('gianni@universe.cmo').then(e => expect(e).toEqual('gianni@universe.com'), () => { throw 'fail: gianni@universe.cmo'; }),
  88. suggest('gianni@universecom').then(e => expect(e).toEqual('gianni@universe.com'), () => { throw 'fail: gianni@universecom'; })
  89. ];
  90.  
  91. Promise.all(promises).then(done, done.fail);
  92. });
  93.  
  94. it('should suggest misspelled domains and TLDs', (done) => {
  95. const promises = [
  96. suggest('user@gmailcom').then(e => expect(e).toEqual('user@gmail.com'), () => { throw 'fail: user@gmailcom'; }),
  97. suggest('user@gnailcon').then(e => expect(e).toEqual('user@gmail.com'), () => { throw 'fail: user@gnailcon'; }),
  98. suggest('user@hotmailco.uk').then(e => expect(e).toEqual('user@hotmail.co.uk'), () => { throw 'fail: user@hotmailco.uk'; })
  99. ];
  100.  
  101. Promise.all(promises).then(done, done.fail);
  102. });
  103. });
  104. });
Add Comment
Please, Sign In to add comment