22 lines
754 B
TypeScript
22 lines
754 B
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { hashPin, isValidPin, verifyPin } from "@/lib/auth/pin";
|
|
|
|
describe("pin", () => {
|
|
it("hashes with salt and verifies only the right PIN", async () => {
|
|
const a = await hashPin("4711");
|
|
const b = await hashPin("4711");
|
|
expect(a).not.toBe(b);
|
|
expect(a).not.toContain("4711");
|
|
expect(await verifyPin("4711", a)).toBe(true);
|
|
expect(await verifyPin("4712", a)).toBe(false);
|
|
expect(await verifyPin("4711", null)).toBe(false);
|
|
expect(await verifyPin("4711", "kaputt")).toBe(false);
|
|
});
|
|
|
|
it("accepts exactly four digits", () => {
|
|
expect(isValidPin("0042")).toBe(true);
|
|
expect(isValidPin("123")).toBe(false);
|
|
expect(isValidPin("12a4")).toBe(false);
|
|
});
|
|
});
|