test(auth): Add tests for AuthService and Auth validations

This commit is contained in:
Yunxiao Xu
2026-02-11 19:34:19 -08:00
parent c222b33ba5
commit e3bc699c64
4 changed files with 247 additions and 15 deletions

View File

@@ -0,0 +1,50 @@
import { describe, it, expect } from "vitest"
import { loginSchema, registerSchema } from "./auth"
describe("Auth Validations", () => {
describe("loginSchema", () => {
it("validates correct input", () => {
const result = loginSchema.safeParse({
email: "test@example.com",
password: "password123",
})
expect(result.success).toBe(true)
})
it("fails on invalid email", () => {
const result = loginSchema.safeParse({
email: "not-an-email",
password: "password123",
})
expect(result.success).toBe(false)
})
it("fails on short password", () => {
const result = loginSchema.safeParse({
email: "test@example.com",
password: "123",
})
expect(result.success).toBe(false)
})
})
describe("registerSchema", () => {
it("validates correct input", () => {
const result = registerSchema.safeParse({
email: "test@example.com",
password: "password123",
confirmPassword: "password123",
})
expect(result.success).toBe(true)
})
it("fails if passwords do not match", () => {
const result = registerSchema.safeParse({
email: "test@example.com",
password: "password123",
confirmPassword: "different",
})
expect(result.success).toBe(false)
})
})
})