desktopTelemetryFetch.test.ts 863 B

1234567891011121314151617181920
  1. import { describe, expect, it, vi } from "vitest";
  2. describe("desktop telemetry fetch", () => {
  3. it("delegates telemetry requests to Electron net.fetch", async () => {
  4. const { createDesktopTelemetryFetch } = await import("../src/main/desktopTelemetryFetch.js");
  5. const response = new Response("ok", { status: 200 });
  6. const electronFetch = vi.fn(async () => response);
  7. const telemetryFetch = createDesktopTelemetryFetch({ fetch: electronFetch });
  8. const init: RequestInit = {
  9. method: "POST",
  10. headers: { "Content-Type": "application/json" },
  11. body: JSON.stringify({ event_id: "event-1" }),
  12. };
  13. const result = await telemetryFetch("https://zcode.z.ai/api/v1/event/report", init);
  14. expect(result).toBe(response);
  15. expect(electronFetch).toHaveBeenCalledWith("https://zcode.z.ai/api/v1/event/report", init);
  16. });
  17. });