feat: support outlook for calendar plus minor fixes

This commit is contained in:
2026-06-27 15:07:10 +09:30
parent 2163f06de9
commit d34333ca38
31 changed files with 1791 additions and 231 deletions
@@ -0,0 +1,48 @@
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;
describe("upsertOutlookCalendarEvent", () => {
beforeEach(() => {
fetchMock.mockReset();
});
it("creates a new event when no existing id", async () => {
fetchMock.mockResolvedValue({
ok: true,
status: 200,
json: async () => ({ id: "evt-1" }),
});
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" }),
);
});
it("patches when an existing id is provided", async () => {
fetchMock.mockResolvedValue({ ok: true, status: 200, json: async () => ({}) });
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();
});
});