update query resolvers to add the seconds threshold

This commit is contained in:
2025-03-25 16:00:13 -07:00
parent 99672e749f
commit 717575e004
2 changed files with 22 additions and 11 deletions

View File

@@ -3,10 +3,10 @@ import { Resolvers } from "../generated/graphql";
export const QueryResolvers: Resolvers<ServerContext> = {
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<ServerContext> = {
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);
},
},
}

View File

@@ -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);
});
});
});