refactor: consolidate and debloat calendar sync implementation

Merge duplicated Google/Outlook engines, background handlers, and API
layers into shared calendarSync modules to cut complexity without changing
user-facing sync behavior.
This commit is contained in:
SethBurkart123
2026-06-28 10:45:45 +10:00
parent f4230e02b9
commit 7779edb063
52 changed files with 1965 additions and 3258 deletions
@@ -1,48 +1,31 @@
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
import { upsertOutlookCalendarEvent, deleteOutlookCalendarEvent } from "./upsertEvent";
const fetchMock = jest.fn();
global.fetch = fetchMock as unknown as typeof fetch;
const mockFetch = jest.fn<typeof fetch>();
global.fetch = mockFetch as typeof fetch;
describe("upsertOutlookCalendarEvent", () => {
import {
deleteOutlookCalendarEvent,
upsertOutlookCalendarEvent,
} from "@/seqta/utils/calendarSync/remoteEvents";
describe("outlook calendar remote events", () => {
beforeEach(() => {
fetchMock.mockReset();
mockFetch.mockReset();
});
it("creates a new event when no existing id", async () => {
fetchMock.mockResolvedValue({
ok: true,
status: 200,
json: async () => ({ id: "evt-1" }),
});
it("creates a new event when none exists", async () => {
mockFetch.mockResolvedValueOnce(
new Response(JSON.stringify({ id: "evt-1" }), { status: 201 }),
);
const id = await upsertOutlookCalendarEvent("token", undefined, { subject: "Math" });
expect(id).toBe("evt-1");
expect(fetchMock).toHaveBeenCalledWith(
"https://graph.microsoft.com/v1.0/me/events",
expect.objectContaining({ method: "POST" }),
);
expect(mockFetch).toHaveBeenCalledTimes(1);
});
it("patches when an existing id is provided", async () => {
fetchMock.mockResolvedValue({ ok: true, status: 200, json: async () => ({}) });
it("deletes an event", async () => {
mockFetch.mockResolvedValueOnce(new Response(null, { status: 204 }));
const id = await upsertOutlookCalendarEvent("token", "evt-1", { subject: "Math" });
expect(id).toBe("evt-1");
expect(fetchMock).toHaveBeenCalledWith(
"https://graph.microsoft.com/v1.0/me/events/evt-1",
expect.objectContaining({ method: "PATCH" }),
);
});
});
describe("deleteOutlookCalendarEvent", () => {
beforeEach(() => {
fetchMock.mockReset();
});
it("treats 404 as success", async () => {
fetchMock.mockResolvedValue({ ok: false, status: 404, json: async () => ({}) });
await expect(deleteOutlookCalendarEvent("token", "evt-1")).resolves.toBeUndefined();
});
});