34 lines
754 B
TypeScript
34 lines
754 B
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { userSchema } from "./user";
|
|
|
|
describe("userSchema", () => {
|
|
it("accepts a valid user", () => {
|
|
const result = userSchema.parse({
|
|
id: "1",
|
|
username: "alice",
|
|
passwordHash: "hashed_password_1",
|
|
});
|
|
expect(result.username).toBe("alice");
|
|
});
|
|
|
|
it("rejects username shorter than 3 chars", () => {
|
|
expect(() =>
|
|
userSchema.parse({
|
|
id: "1",
|
|
username: "ab",
|
|
passwordHash: "hashed_password_1",
|
|
}),
|
|
).toThrow();
|
|
});
|
|
|
|
it("rejects passwordHash shorter than 6 chars", () => {
|
|
expect(() =>
|
|
userSchema.parse({
|
|
id: "1",
|
|
username: "alice",
|
|
passwordHash: "abc",
|
|
}),
|
|
).toThrow();
|
|
});
|
|
});
|