From 8160ed459a722c5f194ccc0fd073d603bc97e47b Mon Sep 17 00:00:00 2001 From: lenhanphung Date: Thu, 9 Oct 2025 14:59:21 +0700 Subject: [PATCH] feat: restore logging for status 201 in putEvent as requested in PR #54 - Restore test case to verify logging behavior --- __test__/features/Events/EventApi.test.tsx | 15 +++++++++++++++ src/features/Events/EventApi.ts | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/__test__/features/Events/EventApi.test.tsx b/__test__/features/Events/EventApi.test.tsx index 48e30cc..4b305b9 100644 --- a/__test__/features/Events/EventApi.test.tsx +++ b/__test__/features/Events/EventApi.test.tsx @@ -65,6 +65,21 @@ describe("eventApi", () => { expect(result).toBe(mockResponse); }); + it("putEvent logs when status is 201", async () => { + const consoleLogSpy = jest.spyOn(console, "log").mockImplementation(); + const mockResponse = { status: 201, url: "/dav/cals/test.ics" }; + (api as unknown as jest.Mock).mockReturnValue(mockResponse); + + await putEvent(mockEvent); + + expect(consoleLogSpy).toHaveBeenCalledWith( + "Event created successfully:", + "/dav/cals/test.ics" + ); + + consoleLogSpy.mockRestore(); + }); + test("moveEvent sends MOVE request with destination header", async () => { const mockResponse = { status: 204 }; (api as unknown as jest.Mock).mockReturnValue({ diff --git a/src/features/Events/EventApi.ts b/src/features/Events/EventApi.ts index ed68d98..df77f03 100644 --- a/src/features/Events/EventApi.ts +++ b/src/features/Events/EventApi.ts @@ -42,6 +42,11 @@ export async function putEvent(event: CalendarEvent, calOwnerEmail?: string) { "content-type": "text/calendar; charset=utf-8", }, }); + + if (response.status === 201) { + console.log("Event created successfully:", response.url || event.URL); + } + return response; }