27 lines
842 B
TypeScript
27 lines
842 B
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import * as z from 'zod'
|
|
|
|
// Mirrors the schema defined in app/pages/login.vue
|
|
const schema = z.object({
|
|
email: z.email(),
|
|
otp: z.array(z.string()).optional().transform(val => val?.join(''))
|
|
})
|
|
|
|
describe('login schema', () => {
|
|
it('accepts a valid email', () => {
|
|
const result = schema.safeParse({ email: 'user@example.com' })
|
|
expect(result.success).toBe(true)
|
|
})
|
|
|
|
it('rejects an invalid email', () => {
|
|
const result = schema.safeParse({ email: 'not-an-email' })
|
|
expect(result.success).toBe(false)
|
|
})
|
|
|
|
it('joins otp array into a single string', () => {
|
|
const result = schema.safeParse({ email: 'user@example.com', otp: ['1', '2', '3', '4', '5', '6'] })
|
|
expect(result.success).toBe(true)
|
|
if (result.success) expect(result.data.otp).toBe('123456')
|
|
})
|
|
})
|