@@ -10,6 +10,7 @@ import type { NewLinkWithNotes } from "@plotday/twister";
1010import type { Thread } from "@plotday/twister" ;
1111import type { CalendarSyncHost } from "./sync" ;
1212import {
13+ cancelEventWithApiFn ,
1314 cancellationWasSelfInitiatedFn ,
1415 extractRSVPParamsFn ,
1516 getWatchRenewalScheduleFn ,
@@ -780,6 +781,45 @@ describe("updateEventRSVPWithApiFn", () => {
780781 } ) ;
781782} ) ;
782783
784+ describe ( "cancelEventWithApiFn" , ( ) => {
785+ afterEach ( ( ) => vi . unstubAllGlobals ( ) ) ;
786+
787+ it ( "issues a DELETE against the event's own calendar/eventId" , async ( ) => {
788+ const calendarId = "user@example.com" ;
789+ const eventId = "event-abc" ;
790+
791+ const fetchSpy = vi . fn ( async ( url : string , init ?: RequestInit ) => {
792+ if (
793+ url ===
794+ `https://www.googleapis.com/calendar/v3/calendars/${ calendarId } /events/${ eventId } ` &&
795+ init ?. method === "DELETE"
796+ ) {
797+ return new Response ( null , { status : 204 } ) ;
798+ }
799+ throw new Error ( `Unexpected fetch: ${ url } ` ) ;
800+ } ) ;
801+ vi . stubGlobal ( "fetch" , fetchSpy ) ;
802+
803+ const api = new GoogleApi ( "fake-token" ) ;
804+ await cancelEventWithApiFn ( api , calendarId , eventId ) ;
805+
806+ expect ( fetchSpy ) . toHaveBeenCalledTimes ( 1 ) ;
807+ } ) ;
808+
809+ it ( "is a no-op (doesn't throw) when the event is already gone" , async ( ) => {
810+ const calendarId = "user@example.com" ;
811+ const eventId = "event-already-deleted" ;
812+
813+ const fetchSpy = vi . fn ( async ( ) => new Response ( null , { status : 410 } ) ) ;
814+ vi . stubGlobal ( "fetch" , fetchSpy ) ;
815+
816+ const api = new GoogleApi ( "fake-token" ) ;
817+ await expect (
818+ cancelEventWithApiFn ( api , calendarId , eventId )
819+ ) . resolves . toBeUndefined ( ) ;
820+ } ) ;
821+ } ) ;
822+
783823describe ( "setupCalendarWatchFn" , ( ) => {
784824 afterEach ( ( ) => vi . unstubAllGlobals ( ) ) ;
785825
0 commit comments