forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 💫
1import {describe, expect, it} from '@jest/globals'
2import tldts from 'tldts'
3
4import {isEmailMaybeInvalid} from '#/lib/strings/email'
5
6describe('emailTypoChecker', () => {
7 const invalidCases = [
8 'gnail.com',
9 'gnail.co',
10 'gmaill.com',
11 'gmaill.co',
12 'gmai.com',
13 'gmai.co',
14 'gmal.com',
15 'gmal.co',
16 'gmail.co',
17 'iclod.com',
18 'iclod.co',
19 'outllok.com',
20 'outllok.co',
21 'outlook.co',
22 'yaoo.com',
23 'yaoo.co',
24 'yaho.com',
25 'yaho.co',
26 'yahooo.com',
27 'yahooo.co',
28 'yahoo.co',
29 'hithere.jul',
30 'agpowj.notshop',
31 'thisisnot.avalid.tld.nope',
32 // old tld for czechoslovakia
33 'czechoslovakia.cs',
34 // tlds that cbs was registering in 2024 but cancelled
35 'liveon.cbs',
36 'its.showtime',
37 ]
38 const validCases = [
39 'gmail.com',
40 // subdomains (tests end of string)
41 'gnail.com.test.com',
42 'outlook.com',
43 'yahoo.com',
44 'icloud.com',
45 'firefox.com',
46 'firefox.co',
47 'hello.world.com',
48 'buy.me.a.coffee.shop',
49 'mayotte.yt',
50 'aland.ax',
51 'bouvet.bv',
52 'uk.gb',
53 'chad.td',
54 'somalia.so',
55 'plane.aero',
56 'cute.cat',
57 'together.coop',
58 'findme.jobs',
59 'nightatthe.museum',
60 'industrial.mil',
61 'czechrepublic.cz',
62 'lovakia.sk',
63 // new gtlds in 2024
64 'whatsinyour.locker',
65 'letsmakea.deal',
66 'skeet.now',
67 'everyone.みんな',
68 'bourgeois.lifestyle',
69 'california.living',
70 'skeet.ing',
71 'listeningto.music',
72 'createa.meme',
73 ]
74
75 it.each(invalidCases)(`should be invalid: abcde@%s`, domain => {
76 expect(isEmailMaybeInvalid(`abcde@${domain}`, tldts)).toEqual(true)
77 })
78
79 it.each(validCases)(`should be valid: abcde@%s`, domain => {
80 expect(isEmailMaybeInvalid(`abcde@${domain}`, tldts)).toEqual(false)
81 })
82})