mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
update query resolvers to add the seconds threshold
This commit is contained in:
@@ -3,10 +3,10 @@ import { Resolvers } from "../generated/graphql";
|
|||||||
|
|
||||||
export const QueryResolvers: Resolvers<ServerContext> = {
|
export const QueryResolvers: Resolvers<ServerContext> = {
|
||||||
Query: {
|
Query: {
|
||||||
systems: async (parent, args, contextValue, info) => {
|
systems: async (_parent, args, contextValue, _info) => {
|
||||||
return await contextValue.repository.getSystems();
|
return await contextValue.repository.getSystems();
|
||||||
},
|
},
|
||||||
system: async (parent, args, contextValue, info) => {
|
system: async (_parent, args, contextValue, _info) => {
|
||||||
if (!args.id) return null;
|
if (!args.id) return null;
|
||||||
const system = await contextValue.repository.getSystemById(args.id);
|
const system = await contextValue.repository.getSystemById(args.id);
|
||||||
if (system === null) return null;
|
if (system === null) return null;
|
||||||
@@ -19,6 +19,10 @@ export const QueryResolvers: Resolvers<ServerContext> = {
|
|||||||
isNotificationScheduled: async (_parent, args, contextValue, _info) => {
|
isNotificationScheduled: async (_parent, args, contextValue, _info) => {
|
||||||
const notificationData = args.input;
|
const notificationData = args.input;
|
||||||
return contextValue.notificationService.isNotificationScheduled(notificationData);
|
return contextValue.notificationService.isNotificationScheduled(notificationData);
|
||||||
}
|
},
|
||||||
|
secondsThresholdForNotification: async (_parent, args, contextValue, _info) => {
|
||||||
|
const notificationData = args.input;
|
||||||
|
return contextValue.notificationService.getSecondsThresholdForScheduledNotification(notificationData);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,14 +96,15 @@ describe("QueryResolvers", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("isNotificationScheduled", () => {
|
describe("isNotificationScheduled and secondsThresholdForNotification", () => {
|
||||||
const query = `
|
const query = `
|
||||||
query IsNotificationScheduled($input: NotificationInput!) {
|
query IsNotificationScheduled($input: NotificationLookupArguments!) {
|
||||||
isNotificationScheduled(input: $input)
|
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
|
// Arrange
|
||||||
const shuttle = await addMockShuttleToRepository(context.repository, "1");
|
const shuttle = await addMockShuttleToRepository(context.repository, "1");
|
||||||
const stop = await addMockStopToRepository(context.repository, "1")
|
const stop = await addMockStopToRepository(context.repository, "1")
|
||||||
@@ -112,16 +113,20 @@ describe("QueryResolvers", () => {
|
|||||||
shuttleId: shuttle.id,
|
shuttleId: shuttle.id,
|
||||||
stopId: stop.id,
|
stopId: stop.id,
|
||||||
deviceId: "1",
|
deviceId: "1",
|
||||||
|
secondsThreshold: 240,
|
||||||
};
|
};
|
||||||
await context.notificationService.scheduleNotification(notification);
|
await context.notificationService.scheduleNotification(notification);
|
||||||
|
|
||||||
|
const notificationLookup: any = {
|
||||||
|
...notification,
|
||||||
|
}
|
||||||
|
delete notificationLookup.secondsThreshold;
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const response = await holder.testServer.executeOperation({
|
const response = await holder.testServer.executeOperation({
|
||||||
query,
|
query,
|
||||||
variables: {
|
variables: {
|
||||||
input: {
|
input: notificationLookup,
|
||||||
...notification,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
contextValue: context,
|
contextValue: context,
|
||||||
@@ -130,10 +135,11 @@ describe("QueryResolvers", () => {
|
|||||||
// Assert
|
// Assert
|
||||||
assert(response.body.kind === "single");
|
assert(response.body.kind === "single");
|
||||||
expect(response.body.singleResult.errors).toBeUndefined();
|
expect(response.body.singleResult.errors).toBeUndefined();
|
||||||
|
expect(response.body.singleResult.data?.secondsThresholdForNotification).toEqual(240);
|
||||||
expect(response.body.singleResult.data?.isNotificationScheduled).toBe(true);
|
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
|
// Act
|
||||||
const response = await holder.testServer.executeOperation({
|
const response = await holder.testServer.executeOperation({
|
||||||
query,
|
query,
|
||||||
@@ -152,6 +158,7 @@ describe("QueryResolvers", () => {
|
|||||||
assert(response.body.kind === "single");
|
assert(response.body.kind === "single");
|
||||||
expect(response.body.singleResult.errors).toBeUndefined();
|
expect(response.body.singleResult.errors).toBeUndefined();
|
||||||
expect(response.body.singleResult.data?.isNotificationScheduled).toBe(false);
|
expect(response.body.singleResult.data?.isNotificationScheduled).toBe(false);
|
||||||
|
expect(response.body.singleResult.data?.secondsThresholdForNotification).toBe(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user