Initial commit
This commit is contained in:
26
test/unit/login-schema.test.ts
Normal file
26
test/unit/login-schema.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
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')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user