feat(web): monitor config API route
Implement GET and PATCH endpoints for monitor configuration, matching the existing discover config pattern. GET returns stored or default values; PATCH upserts known keys with allowlist filtering. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { GET, PATCH } from "./route";
|
||||
|
||||
function patch(body: unknown) {
|
||||
return PATCH(new Request("http://localhost/api/monitor/config", {
|
||||
method: "PATCH", headers: { "content-type": "application/json" }, body: JSON.stringify(body),
|
||||
}));
|
||||
}
|
||||
|
||||
describe("monitor config API", () => {
|
||||
it("GET returns defaults when nothing is stored", async () => {
|
||||
const body = await (await GET()).json();
|
||||
expect(body).toMatchObject({
|
||||
"monitor.enabled": "false", "monitor.autoMonitorFuture": "false",
|
||||
"monitor.pollIntervalHours": "24", "monitor.retryIntervalHours": "6",
|
||||
"monitor.qualityCutoff": "2", "monitor.upgradeWindowDays": "14",
|
||||
});
|
||||
});
|
||||
|
||||
it("PATCH upserts known keys and ignores unknown ones", async () => {
|
||||
const res = await patch({ "monitor.enabled": "true", "monitor.pollIntervalHours": 12, "nope": "x" });
|
||||
expect((await res.json()).updated).toBe(2);
|
||||
const body = await (await GET()).json();
|
||||
expect(body["monitor.enabled"]).toBe("true");
|
||||
expect(body["monitor.pollIntervalHours"]).toBe("12");
|
||||
expect(await prisma.config.findUnique({ where: { key: "nope" } })).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user