diff --git a/src/resolvers/QueryResolvers.ts b/src/resolvers/QueryResolvers.ts index 98c8965..725ae8d 100644 --- a/src/resolvers/QueryResolvers.ts +++ b/src/resolvers/QueryResolvers.ts @@ -3,10 +3,10 @@ import { Resolvers } from "../generated/graphql"; export const QueryResolvers: Resolvers = { Query: { - systems: async (parent, args, contextValue, info) => { + systems: async (_parent, args, contextValue, _info) => { return await contextValue.repository.getSystems(); }, - system: async (parent, args, contextValue, info) => { + system: async (_parent, args, contextValue, _info) => { if (!args.id) return null; const system = await contextValue.repository.getSystemById(args.id); if (system === null) return null; @@ -19,6 +19,10 @@ export const QueryResolvers: Resolvers = { isNotificationScheduled: async (_parent, args, contextValue, _info) => { const notificationData = args.input; return contextValue.notificationService.isNotificationScheduled(notificationData); - } + }, + secondsThresholdForNotification: async (_parent, args, contextValue, _info) => { + const notificationData = args.input; + return contextValue.notificationService.getSecondsThresholdForScheduledNotification(notificationData); + }, }, } diff --git a/test/resolvers/QueryResolverTests.test.ts b/test/resolvers/QueryResolverTests.test.ts index c35be13..ba00f5b 100644 --- a/test/resolvers/QueryResolverTests.test.ts +++ b/test/resolvers/QueryResolverTests.test.ts @@ -96,14 +96,15 @@ describe("QueryResolvers", () => { }); }); - describe("isNotificationScheduled", () => { + describe("isNotificationScheduled and secondsThresholdForNotification", () => { const query = ` - query IsNotificationScheduled($input: NotificationInput!) { + query IsNotificationScheduled($input: NotificationLookupArguments!) { isNotificationScheduled(input: $input) + secondsThresholdForNotification(input: $input) } - ` + `; - it("returns true if the notification is scheduled", async () => { + it("returns correct data if the notification is scheduled", async () => { // Arrange const shuttle = await addMockShuttleToRepository(context.repository, "1"); const stop = await addMockStopToRepository(context.repository, "1") @@ -112,16 +113,20 @@ describe("QueryResolvers", () => { shuttleId: shuttle.id, stopId: stop.id, deviceId: "1", + secondsThreshold: 240, }; await context.notificationService.scheduleNotification(notification); + const notificationLookup: any = { + ...notification, + } + delete notificationLookup.secondsThreshold; + // Act const response = await holder.testServer.executeOperation({ query, variables: { - input: { - ...notification, - }, + input: notificationLookup, } }, { contextValue: context, @@ -130,10 +135,11 @@ describe("QueryResolvers", () => { // Assert assert(response.body.kind === "single"); expect(response.body.singleResult.errors).toBeUndefined(); + expect(response.body.singleResult.data?.secondsThresholdForNotification).toEqual(240); expect(response.body.singleResult.data?.isNotificationScheduled).toBe(true); }); - it("returns false if the notification isn't scheduled", async () => { + it("returns false/null data if the notification isn't scheduled", async () => { // Act const response = await holder.testServer.executeOperation({ query, @@ -152,6 +158,7 @@ describe("QueryResolvers", () => { assert(response.body.kind === "single"); expect(response.body.singleResult.errors).toBeUndefined(); expect(response.body.singleResult.data?.isNotificationScheduled).toBe(false); + expect(response.body.singleResult.data?.secondsThresholdForNotification).toBe(null); }); }); });