You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

80 lines
2.2 KiB

import { describe, it, expect } from 'vitest'
import { registerSchema, clientRegisterSchema } from '../auth-schema'
describe('registerSchema', () => {
const validBody = {
username: 'testuser',
password: 'password123',
confirmPassword: 'password123',
captchaToken: 'token-abc',
captchaText: 'abcde',
}
it('passes with valid input', () => {
expect(registerSchema.safeParse(validBody).success).toBe(true)
})
it('fails on short username', () => {
const r = registerSchema.safeParse({ ...validBody, username: 'ab' })
expect(r.success).toBe(false)
if (!r.success) {
expect(r.error.issues[0].path).toContain('username')
}
})
it('fails on short password', () => {
const r = registerSchema.safeParse({ ...validBody, password: '1234567' })
expect(r.success).toBe(false)
if (!r.success) {
expect(r.error.issues[0].path).toContain('password')
}
})
it('fails on password mismatch', () => {
const r = registerSchema.safeParse({
...validBody,
confirmPassword: 'different',
})
expect(r.success).toBe(false)
if (!r.success) {
expect(r.error.issues[0].path).toContain('confirmPassword')
}
})
it('fails on empty captchaText', () => {
const r = registerSchema.safeParse({ ...validBody, captchaText: '' })
expect(r.success).toBe(false)
if (!r.success) {
expect(r.error.issues[0].path).toContain('captchaText')
}
})
it('fails on empty captchaToken', () => {
const r = registerSchema.safeParse({ ...validBody, captchaToken: '' })
expect(r.success).toBe(false)
if (!r.success) {
expect(r.error.issues[0].path).toContain('captchaToken')
}
})
})
describe('clientRegisterSchema', () => {
it('still requires captchaText field', () => {
const r = clientRegisterSchema.safeParse({
username: 'testuser',
password: 'password123',
confirmPassword: 'password123',
})
expect(r.success).toBe(false)
})
it('validates without captchaToken field', () => {
const r = clientRegisterSchema.safeParse({
username: 'testuser',
password: 'password123',
confirmPassword: 'password123',
captchaText: 'abcde',
})
expect(r.success).toBe(true)
})
})