d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
148 lines
5.0 KiB
TypeScript
148 lines
5.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { quickValidateEmail } from '@/lib/messaging/email/validation'
|
|
|
|
describe('quickValidateEmail', () => {
|
|
it.concurrent('should validate a correct email', () => {
|
|
const result = quickValidateEmail('user@example.com')
|
|
expect(result.isValid).toBe(true)
|
|
expect(result.checks.syntax).toBe(true)
|
|
expect(result.checks.disposable).toBe(true)
|
|
expect(result.checks.mxRecord).toBe(true)
|
|
expect(result.confidence).toBe('medium')
|
|
})
|
|
|
|
it.concurrent('should reject invalid syntax', () => {
|
|
const result = quickValidateEmail('invalid-email')
|
|
expect(result.isValid).toBe(false)
|
|
expect(result.reason).toBe('Invalid email format')
|
|
})
|
|
|
|
it.concurrent('should reject disposable email addresses', () => {
|
|
const disposableDomains = [
|
|
'mailinator.com',
|
|
'yopmail.com',
|
|
'guerrillamail.com',
|
|
'temp-mail.org',
|
|
'throwaway.email',
|
|
'getnada.com',
|
|
'sharklasers.com',
|
|
'spam4.me',
|
|
'sharebot.net',
|
|
'oakon.com',
|
|
'catchmail.io',
|
|
'salt.email',
|
|
'mail.gw',
|
|
'tempmail.org',
|
|
]
|
|
|
|
for (const domain of disposableDomains) {
|
|
const result = quickValidateEmail(`test@${domain}`)
|
|
expect(result.isValid).toBe(false)
|
|
expect(result.reason).toBe('Disposable email addresses are not allowed')
|
|
expect(result.checks.disposable).toBe(false)
|
|
}
|
|
})
|
|
|
|
it.concurrent('should reject consecutive dots (RFC violation)', () => {
|
|
const result = quickValidateEmail('user..name@example.com')
|
|
expect(result.isValid).toBe(false)
|
|
expect(result.reason).toBe('Email contains suspicious patterns')
|
|
expect(result.confidence).toBe('medium')
|
|
})
|
|
|
|
it.concurrent('should reject very long local parts (RFC violation)', () => {
|
|
const longLocalPart = 'a'.repeat(65)
|
|
const result = quickValidateEmail(`${longLocalPart}@example.com`)
|
|
expect(result.isValid).toBe(false)
|
|
expect(result.reason).toBe('Email contains suspicious patterns')
|
|
})
|
|
|
|
it.concurrent('should reject email with missing domain', () => {
|
|
const result = quickValidateEmail('user@')
|
|
expect(result.isValid).toBe(false)
|
|
expect(result.reason).toBe('Invalid email format')
|
|
})
|
|
|
|
it.concurrent('should reject email with domain starting with dot', () => {
|
|
const result = quickValidateEmail('user@.example.com')
|
|
expect(result.isValid).toBe(false)
|
|
expect(result.reason).toBe('Invalid email format')
|
|
})
|
|
|
|
it.concurrent('should reject email with domain ending with dot', () => {
|
|
const result = quickValidateEmail('user@example.')
|
|
expect(result.isValid).toBe(false)
|
|
expect(result.reason).toBe('Invalid email format')
|
|
})
|
|
|
|
it.concurrent('should reject email with domain missing TLD', () => {
|
|
const result = quickValidateEmail('user@localhost')
|
|
expect(result.isValid).toBe(false)
|
|
expect(result.reason).toBe('Invalid domain format')
|
|
})
|
|
|
|
it.concurrent('should reject email longer than 254 characters', () => {
|
|
const longLocal = 'a'.repeat(64)
|
|
const longDomain = `${'b'.repeat(180)}.com`
|
|
const result = quickValidateEmail(`${longLocal}@${longDomain}`)
|
|
expect(result.isValid).toBe(false)
|
|
})
|
|
|
|
it.concurrent('should accept valid email formats', () => {
|
|
const validEmails = [
|
|
'simple@example.com',
|
|
'very.common@example.com',
|
|
'disposable.style.email.with+symbol@example.com',
|
|
'other.email-with-hyphen@example.com',
|
|
'user.name+tag+sorting@example.com',
|
|
'x@example.com',
|
|
'example-indeed@strange-example.com',
|
|
'example@s.example',
|
|
]
|
|
|
|
for (const email of validEmails) {
|
|
const result = quickValidateEmail(email)
|
|
expect(result.isValid).toBe(true)
|
|
expect(result.checks.syntax).toBe(true)
|
|
expect(result.checks.disposable).toBe(true)
|
|
}
|
|
})
|
|
|
|
it.concurrent('should return high confidence for syntax errors', () => {
|
|
const result = quickValidateEmail('not-valid-email')
|
|
expect(result.confidence).toBe('high')
|
|
})
|
|
|
|
it.concurrent('should handle special characters in local part', () => {
|
|
const result = quickValidateEmail("user!#$%&'*+/=?^_`{|}~@example.com")
|
|
expect(result.checks.syntax).toBe(true)
|
|
})
|
|
|
|
it.concurrent('should handle empty string', () => {
|
|
const result = quickValidateEmail('')
|
|
expect(result.isValid).toBe(false)
|
|
expect(result.reason).toBe('Invalid email format')
|
|
})
|
|
|
|
it.concurrent('should handle email with only @ symbol', () => {
|
|
const result = quickValidateEmail('@')
|
|
expect(result.isValid).toBe(false)
|
|
})
|
|
|
|
it.concurrent('should handle email with spaces', () => {
|
|
const result = quickValidateEmail('user name@example.com')
|
|
expect(result.isValid).toBe(false)
|
|
})
|
|
|
|
it.concurrent('should handle email with multiple @ symbols', () => {
|
|
const result = quickValidateEmail('user@domain@example.com')
|
|
expect(result.isValid).toBe(false)
|
|
})
|
|
|
|
it.concurrent('should validate subdomains', () => {
|
|
const result = quickValidateEmail('user@mail.subdomain.example.com')
|
|
expect(result.isValid).toBe(true)
|
|
expect(result.checks.domain).toBe(true)
|
|
})
|
|
})
|