add tests
This commit is contained in:
1 parent
ab7f2cd8f4
commit
9001a8d294
3 files changed
+218
-4
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from "@jest/globals";
|
||||
import { createStatusPageBodyValidation } from "../../../src/api/validation/statusPageValidation.ts";
|
||||
import { createStatusPageBodyValidation, getStatusPageQueryValidation } from "../../../src/api/validation/statusPageValidation.ts";
|
||||
import { StatusPageRanges } from "../../../src/domain/status-pages/status-page.type.ts";
|
||||
|
||||
const baseCreateBody = (overrides: Record<string, unknown> = {}) => ({
|
||||
type: "uptime",
|
||||
@@ -61,3 +62,31 @@ describe("createStatusPageBodyValidation", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("getStatusPageQueryValidation", () => {
|
||||
it("defaults range to latest when absent", () => {
|
||||
const result = getStatusPageQueryValidation.safeParse({ type: "uptime" });
|
||||
expect(result.success).toBe(true);
|
||||
if (result.success) {
|
||||
expect(result.data.range).toBe("latest");
|
||||
}
|
||||
});
|
||||
|
||||
it("accepts every supported range", () => {
|
||||
for (const range of StatusPageRanges) {
|
||||
const result = getStatusPageQueryValidation.safeParse({ type: "uptime", range });
|
||||
expect(result.success).toBe(true);
|
||||
if (result.success) {
|
||||
expect(result.data.range).toBe(range);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects an unsupported range", () => {
|
||||
const result = getStatusPageQueryValidation.safeParse({ type: "uptime", range: "45d" });
|
||||
expect(result.success).toBe(false);
|
||||
if (!result.success) {
|
||||
expect(result.error.issues).toEqual(expect.arrayContaining([expect.objectContaining({ path: ["range"] })]));
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user