39 lines
984 B
TypeScript
39 lines
984 B
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import z from "zod";
|
|
import { createSchema } from "../src/schema";
|
|
|
|
describe("schema", () => {
|
|
const appData = z.object({
|
|
my: z.string(),
|
|
cool: z.string(),
|
|
});
|
|
|
|
const schema = createSchema(appData);
|
|
|
|
test("accepts valid identification request", () => {
|
|
const parsed = schema.identification.request.parse({
|
|
app_identifier: "app-1",
|
|
app_session_id: 42,
|
|
app_public_key: "base64key",
|
|
user_id: 123,
|
|
});
|
|
|
|
expect(parsed.user_id).toBe(123);
|
|
});
|
|
|
|
test("rejects invalid challenge response request", () => {
|
|
const result = schema.challenge_response.request.safeParse({
|
|
challenge: "not-base64",
|
|
});
|
|
|
|
expect(result.success).toBe(false);
|
|
});
|
|
|
|
test("accepts valid save_app_data request", () => {
|
|
const result = schema.save_app_data.request.safeParse({
|
|
app_data: JSON.stringify({ my: "a", cool: "b" }),
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
});
|
|
});
|