add tests
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import {RichText} from '@atproto/api'
|
import {RichText} from '@atproto/api'
|
||||||
|
import tldts from 'tldts'
|
||||||
|
|
||||||
|
import {emailTypoCheck} from 'lib/strings/email-typo'
|
||||||
import {parseEmbedPlayerFromUrl} from 'lib/strings/embed-player'
|
import {parseEmbedPlayerFromUrl} from 'lib/strings/embed-player'
|
||||||
import {
|
import {
|
||||||
createStarterPackGooglePlayUri,
|
createStarterPackGooglePlayUri,
|
||||||
@@ -985,3 +987,83 @@ describe('createStarterPackGooglePlayUri', () => {
|
|||||||
expect(createStarterPackGooglePlayUri(undefined, 'rkey')).toEqual(null)
|
expect(createStarterPackGooglePlayUri(undefined, 'rkey')).toEqual(null)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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',
|
||||||
|
'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',
|
||||||
|
]
|
||||||
|
|
||||||
|
for (const domain of invalidCases) {
|
||||||
|
it(`returns true when calling emailTypoCheck for abcde@${domain}`, () => {
|
||||||
|
expect(emailTypoCheck(`abcde@${domain}`, tldts)).toEqual(true)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const domain of validCases) {
|
||||||
|
it(`returns false when calling emailTypoCheck for abcde@${domain}`, () => {
|
||||||
|
expect(emailTypoCheck(`abcde@${domain}`, tldts)).toEqual(false)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import type tldts from 'tldts'
|
||||||
|
|
||||||
|
const COMMON_ERROR_PATTERN =
|
||||||
|
/\b([a-zA-Z0-9._%+-]+)@(gnail\.(co|com)|gmaill\.(co|com)|gmai\.(co|com)|gmail\.co|gmal\.(co|com)|iclod\.(co|com)|icloud\.co|outllok\.(co|com)|outlok\.(co|com)|outlook\.co|yaoo\.(co|com)|yaho\.(co|com)|yahoo\.co|yahooo\.(co|com))\b/
|
||||||
|
|
||||||
|
export function emailTypoCheck(email: string, dynamicTldts: typeof tldts) {
|
||||||
|
const isIcann = dynamicTldts.parse(email).isIcann
|
||||||
|
return !isIcann || COMMON_ERROR_PATTERN.test(email)
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import type tldts from 'tldts'
|
|||||||
|
|
||||||
import {logEvent} from '#/lib/statsig/statsig'
|
import {logEvent} from '#/lib/statsig/statsig'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
|
import {emailTypoCheck} from 'lib/strings/email-typo'
|
||||||
import {ScreenTransition} from '#/screens/Login/ScreenTransition'
|
import {ScreenTransition} from '#/screens/Login/ScreenTransition'
|
||||||
import {is13, is18, useSignupContext} from '#/screens/Signup/state'
|
import {is13, is18, useSignupContext} from '#/screens/Signup/state'
|
||||||
import {Policies} from '#/screens/Signup/StepInfo/Policies'
|
import {Policies} from '#/screens/Signup/StepInfo/Policies'
|
||||||
@@ -31,9 +32,6 @@ function sanitizeDate(date: Date): Date {
|
|||||||
return date
|
return date
|
||||||
}
|
}
|
||||||
|
|
||||||
const COMMON_ERROR_PATTERN =
|
|
||||||
/\b([a-zA-Z0-9._%+-]+)@(gnail\.com|gmaill\.com|gmai\.com|gmail\.co|gmal\.com|iclod\.com|icloud\.co|outllok\.com|outlok\.com|outlook\.co|yaoo\.com|yaho\.com|yahoo\.co|yahooo\.com)\b/
|
|
||||||
|
|
||||||
export function StepInfo({
|
export function StepInfo({
|
||||||
onPressBack,
|
onPressBack,
|
||||||
isServerError,
|
isServerError,
|
||||||
@@ -50,6 +48,7 @@ export function StepInfo({
|
|||||||
|
|
||||||
const inviteCodeValueRef = useRef<string>(state.inviteCode)
|
const inviteCodeValueRef = useRef<string>(state.inviteCode)
|
||||||
const emailValueRef = useRef<string>(state.email)
|
const emailValueRef = useRef<string>(state.email)
|
||||||
|
const prevEmailValueRef = useRef<string>(state.email)
|
||||||
const passwordValueRef = useRef<string>(state.password)
|
const passwordValueRef = useRef<string>(state.password)
|
||||||
|
|
||||||
const [hasWarnedEmail, setHasWarnedEmail] = React.useState<boolean>(false)
|
const [hasWarnedEmail, setHasWarnedEmail] = React.useState<boolean>(false)
|
||||||
@@ -67,11 +66,12 @@ export function StepInfo({
|
|||||||
const onNextPress = () => {
|
const onNextPress = () => {
|
||||||
const inviteCode = inviteCodeValueRef.current
|
const inviteCode = inviteCodeValueRef.current
|
||||||
const email = emailValueRef.current
|
const email = emailValueRef.current
|
||||||
|
const emailChanged = prevEmailValueRef.current !== email
|
||||||
const password = passwordValueRef.current
|
const password = passwordValueRef.current
|
||||||
|
|
||||||
if (!hasWarnedEmail && tldtsRef.current) {
|
if (emailChanged && tldtsRef.current) {
|
||||||
const isIcann = tldtsRef.current.parse(email).isIcann
|
if (emailTypoCheck(email, tldtsRef.current)) {
|
||||||
if (!isIcann || COMMON_ERROR_PATTERN.test(email)) {
|
prevEmailValueRef.current = email
|
||||||
setHasWarnedEmail(true)
|
setHasWarnedEmail(true)
|
||||||
return dispatch({
|
return dispatch({
|
||||||
type: 'setError',
|
type: 'setError',
|
||||||
@@ -83,6 +83,7 @@ export function StepInfo({
|
|||||||
} else if (hasWarnedEmail) {
|
} else if (hasWarnedEmail) {
|
||||||
setHasWarnedEmail(false)
|
setHasWarnedEmail(false)
|
||||||
}
|
}
|
||||||
|
prevEmailValueRef.current = email
|
||||||
|
|
||||||
if (!is13(state.dateOfBirth)) {
|
if (!is13(state.dateOfBirth)) {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user