forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesktop-prompts-toggle.test.ts
More file actions
39 lines (35 loc) · 1.22 KB
/
Copy pathdesktop-prompts-toggle.test.ts
File metadata and controls
39 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { describe, expect, it, vi } from "vitest";
import { patchPromptActive } from "@/lib/desktop-prompts-toggle";
describe("patchPromptActive (kill-switch honesty)", () => {
it("reports success only when the PATCH succeeded", async () => {
const fetchImpl = vi.fn(async () => ({ ok: true }) as Response);
await expect(patchPromptActive(fetchImpl, "p1", false)).resolves.toEqual({
ok: true,
});
expect(fetchImpl).toHaveBeenCalledWith(
"/api/omi/desktop-prompts/p1",
expect.objectContaining({
method: "PATCH",
body: JSON.stringify({ active: false }),
}),
);
});
it("reports a failed kill-switch request instead of pretending it landed", async () => {
const fetchImpl = vi.fn(
async () => ({ ok: false, status: 502 }) as Response,
);
await expect(patchPromptActive(fetchImpl, "p1", false)).resolves.toEqual({
ok: false,
error: "toggle failed (502)",
});
});
it("reports network failures the same way", async () => {
const fetchImpl = vi.fn(async () => {
throw new Error("offline");
});
await expect(patchPromptActive(fetchImpl, "p1", true)).resolves.toEqual({
ok: false,
error: "offline",
});
});
});