Initial Commit
This commit is contained in:
64
packages/api-stack/api/api-schemas/src/admin/ping.test.ts
Normal file
64
packages/api-stack/api/api-schemas/src/admin/ping.test.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import { AdminPingInput, AdminPingOutput } from "./ping.js";
|
||||
|
||||
describe("AdminPingInput", () => {
|
||||
it("parses empty object", { timeout: 5000 }, () => {
|
||||
const result = AdminPingInput.parse({});
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
|
||||
it("parses object with extra fields (stripped)", { timeout: 5000 }, () => {
|
||||
// Zod strips extra keys by default
|
||||
const result = AdminPingInput.parse({ extra: "ignored" });
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe("AdminPingOutput", () => {
|
||||
const valid = {
|
||||
pong: true as const,
|
||||
timestamp: "2024-06-01T12:00:00.000Z",
|
||||
};
|
||||
|
||||
it("parses valid ping output", { timeout: 5000 }, () => {
|
||||
const result = AdminPingOutput.parse(valid);
|
||||
expect(result.pong).toBe(true);
|
||||
expect(result.timestamp).toBe("2024-06-01T12:00:00.000Z");
|
||||
});
|
||||
|
||||
it("parses with timezone offset timestamp", { timeout: 5000 }, () => {
|
||||
const result = AdminPingOutput.parse({
|
||||
...valid,
|
||||
timestamp: "2024-06-01T12:00:00+02:00",
|
||||
});
|
||||
expect(result.timestamp).toBe("2024-06-01T12:00:00+02:00");
|
||||
});
|
||||
|
||||
it("rejects pong: false", { timeout: 5000 }, () => {
|
||||
expect(() =>
|
||||
AdminPingOutput.parse({ ...valid, pong: false })
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it("rejects pong as string", { timeout: 5000 }, () => {
|
||||
expect(() =>
|
||||
AdminPingOutput.parse({ ...valid, pong: "true" })
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it("rejects invalid timestamp format", { timeout: 5000 }, () => {
|
||||
expect(() =>
|
||||
AdminPingOutput.parse({ ...valid, timestamp: "2024-06-01" })
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it("rejects missing timestamp", { timeout: 5000 }, () => {
|
||||
expect(() => AdminPingOutput.parse({ pong: true })).toThrow();
|
||||
});
|
||||
|
||||
it("rejects missing pong", { timeout: 5000 }, () => {
|
||||
expect(() =>
|
||||
AdminPingOutput.parse({ timestamp: "2024-06-01T12:00:00Z" })
|
||||
).toThrow();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user