(feat): better connection management, utility functions & tests
This commit is contained in:
parent
b8889812c5
commit
822dfea577
14 changed files with 448 additions and 39 deletions
39
test/schema.test.ts
Normal file
39
test/schema.test.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
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);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue