From acc4d08716632371566782b91cc2bdeb18122841 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 4 Feb 2025 11:32:33 -0800 Subject: [PATCH] add a test for cancelling notification --- test/resolvers/MutationResolverTests.test.ts | 65 +++++++++++++++----- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/test/resolvers/MutationResolverTests.test.ts b/test/resolvers/MutationResolverTests.test.ts index 5ab147f..de6e190 100644 --- a/test/resolvers/MutationResolverTests.test.ts +++ b/test/resolvers/MutationResolverTests.test.ts @@ -12,6 +12,17 @@ describe("MutationResolvers", () => { const holder = setupTestServerHolder() const context = setupTestServerContext(); + async function getServerResponse(query: string, notificationInput: { deviceId: string; shuttleId: string; stopId: string }) { + return await holder.testServer.executeOperation({ + query, + variables: { + input: notificationInput, + } + }, { + contextValue: context + }); + } + describe("scheduleNotification", () => { const query = ` mutation ScheduleNotification($input: NotificationInput!) { @@ -27,17 +38,6 @@ describe("MutationResolvers", () => { } ` - async function getServerResponse(notificationInput: { deviceId: string; shuttleId: string; stopId: string }) { - return await holder.testServer.executeOperation({ - query, - variables: { - input: notificationInput, - } - }, { - contextValue: context - }); - } - function assertFailedResponse(response: any, notificationInput: NotificationInput) { assert(response.body.kind === "single"); expect(response.body.singleResult.errors).toBeUndefined(); @@ -58,7 +58,7 @@ describe("MutationResolvers", () => { shuttleId: shuttle.id, stopId: stop.id, }; - const response = await getServerResponse(notificationInput); + const response = await getServerResponse(query, notificationInput); assert(response.body.kind === "single"); expect(response.body.singleResult.errors).toBeUndefined(); @@ -79,7 +79,7 @@ describe("MutationResolvers", () => { shuttleId: "1", stopId: stop.id, } - const response = await getServerResponse(notificationInput); + const response = await getServerResponse(query, notificationInput); assertFailedResponse(response, notificationInput); }); @@ -92,14 +92,51 @@ describe("MutationResolvers", () => { shuttleId: shuttle.id, stopId: "1", } - const response = await getServerResponse(notificationInput); + const response = await getServerResponse(query, notificationInput); assertFailedResponse(response, notificationInput); }); }); describe("cancelNotification", () => { + const query = ` + query CancelNotification($input: NotificationInput!) { + cancelNotification(input: $input) { + success + message + data { + deviceId + shuttleId + stopId + } + } + } + ` + it("removes the notification from the notification service", async () => { + const system = await addMockSystemToRepository(context.repository); + const shuttle = await addMockShuttleToRepository(context.repository, system.id); + const stop = await addMockStopToRepository(context.repository, system.id); + + const notificationInput = { + deviceId: "1", + shuttleId: shuttle.id, + stopId: stop.id, + } + await context.notificationService.scheduleNotification(notificationInput); + + const response = await getServerResponse(query, notificationInput); + + assert(response.body.kind === "single"); + expect(response.body.singleResult.errors).toBeUndefined(); + + const cancelledNotification = response.body.singleResult.data?.cancelNotification as any; + expect(cancelledNotification).toStrictEqual(notificationInput); + + expect(context.notificationService.isNotificationScheduled(notificationInput)).toBe(false); + }); + + it("fails if the notification doesn't exist", async () => { }); });