about summary refs log tree commit diff
path: root/__tests__/lib/email.test.ts
blob: 4dfda658f7c0a13b8b7dbcff2897dafe8d8ec638 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import {describe, expect, it} from '@jest/globals'
import tldts from 'tldts'

import {isEmailMaybeInvalid} from '#/lib/strings/email'

describe('emailTypoChecker', () => {
  const invalidCases = [
    'gnail.com',
    'gnail.co',
    'gmaill.com',
    'gmaill.co',
    'gmai.com',
    'gmai.co',
    'gmal.com',
    'gmal.co',
    'gmail.co',
    'iclod.com',
    'iclod.co',
    'outllok.com',
    'outllok.co',
    'outlook.co',
    'yaoo.com',
    'yaoo.co',
    'yaho.com',
    'yaho.co',
    'yahooo.com',
    'yahooo.co',
    'yahoo.co',
    'hithere.jul',
    'agpowj.notshop',
    'thisisnot.avalid.tld.nope',
    // old tld for czechoslovakia
    'czechoslovakia.cs',
    // tlds that cbs was registering in 2024 but cancelled
    'liveon.cbs',
    'its.showtime',
  ]
  const validCases = [
    'gmail.com',
    // subdomains (tests end of string)
    'gnail.com.test.com',
    'outlook.com',
    'yahoo.com',
    'icloud.com',
    'firefox.com',
    'firefox.co',
    'hello.world.com',
    'buy.me.a.coffee.shop',
    'mayotte.yt',
    'aland.ax',
    'bouvet.bv',
    'uk.gb',
    'chad.td',
    'somalia.so',
    'plane.aero',
    'cute.cat',
    'together.coop',
    'findme.jobs',
    'nightatthe.museum',
    'industrial.mil',
    'czechrepublic.cz',
    'lovakia.sk',
    // new gtlds in 2024
    'whatsinyour.locker',
    'letsmakea.deal',
    'skeet.now',
    'everyone.みんな',
    'bourgeois.lifestyle',
    'california.living',
    'skeet.ing',
    'listeningto.music',
    'createa.meme',
  ]

  it.each(invalidCases)(`should be invalid: abcde@%s`, domain => {
    expect(isEmailMaybeInvalid(`abcde@${domain}`, tldts)).toEqual(true)
  })

  it.each(validCases)(`should be valid: abcde@%s`, domain => {
    expect(isEmailMaybeInvalid(`abcde@${domain}`, tldts)).toEqual(false)
  })
})