From 8971e3514d62146b1aa27454f2af1ac8d768d957 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 12 Feb 2025 19:51:42 -0800 Subject: [PATCH] add isNotificationScheduled resolver and test cases --- src/resolvers/QueryResolvers.ts | 5 ++- test/resolvers/QueryResolverTests.test.ts | 44 +++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/resolvers/QueryResolvers.ts b/src/resolvers/QueryResolvers.ts index 8bb439d..e676218 100644 --- a/src/resolvers/QueryResolvers.ts +++ b/src/resolvers/QueryResolvers.ts @@ -15,6 +15,9 @@ export const QueryResolvers: Resolvers = { name: system.name, id: system.id, }; + }, + isNotificationScheduled: async (_parent, args, contextValue, _info) => { + return false; } }, -} \ No newline at end of file +} diff --git a/test/resolvers/QueryResolverTests.test.ts b/test/resolvers/QueryResolverTests.test.ts index af73aca..f75d436 100644 --- a/test/resolvers/QueryResolverTests.test.ts +++ b/test/resolvers/QueryResolverTests.test.ts @@ -2,6 +2,8 @@ import { describe, expect, it } from "@jest/globals"; import { generateMockSystems } from "../testHelpers/mockDataGenerators"; import { setupTestServerContext, setupTestServerHolder } from "../testHelpers/apolloTestServerHelpers"; import assert = require("node:assert"); +import { ScheduledNotificationData } from "../../src/services/NotificationService"; +import { addMockShuttleToRepository, addMockStopToRepository } from "../testHelpers/repositorySetupHelpers"; // See Apollo documentation for integration test guide // https://www.apollographql.com/docs/apollo-server/testing/testing @@ -93,4 +95,46 @@ describe("QueryResolvers", () => { expect(response.body.singleResult.data?.system).toBeNull(); }); }); + + describe("isNotificationScheduled", () => { + const query = ` + query IsNotificationScheduled($input: NotificationInput!) { + isNotificationScheduled(input: $input) + } + ` + + it("returns true if the notification is scheduled", async () => { + // Arrange + const shuttle = await addMockShuttleToRepository(context.repository, "1"); + const stop = await addMockStopToRepository(context.repository, "1") + + const notification: ScheduledNotificationData = { + shuttleId: shuttle.id, + stopId: stop.id, + deviceId: "1", + }; + await context.notificationService.scheduleNotification(notification); + + // Act + const response = await holder.testServer.executeOperation({ + query, + variables: { + input: { + ...notification, + }, + } + }, { + contextValue: context, + }); + + // Assert + assert(response.body.kind === "single"); + expect(response.body.singleResult.errors).toBeUndefined(); + expect(response.body.singleResult.data?.isNotificationScheduled).toBe(true); + }); + + it("returns false if the notification isn't scheduled", async () => { + + }); + }); });