fix method calls and tests

This commit is contained in:
2025-03-27 10:56:57 -07:00
parent a665c29745
commit ef94a9aa7e
4 changed files with 17 additions and 16 deletions

View File

@@ -30,7 +30,7 @@ export const MutationResolvers: Resolvers<ServerContext> = {
: ETANotificationScheduler.defaultSecondsThresholdForNotificationToFire, : ETANotificationScheduler.defaultSecondsThresholdForNotificationToFire,
} }
await context.notificationRepository.scheduleNotification(notificationData); await context.notificationRepository.addOrUpdateNotification(notificationData);
const response: NotificationResponse = { const response: NotificationResponse = {
message: "Notification scheduled", message: "Notification scheduled",
@@ -40,8 +40,9 @@ export const MutationResolvers: Resolvers<ServerContext> = {
return response; return response;
}, },
cancelNotification: async (_parent, args, context, _info) => { cancelNotification: async (_parent, args, context, _info) => {
if (context.notificationRepository.isNotificationScheduled(args.input)) { const isScheduled = await context.notificationRepository.isNotificationScheduled(args.input)
await context.notificationRepository.cancelNotificationIfExists(args.input); if (isScheduled) {
await context.notificationRepository.deleteNotificationIfExists(args.input);
return { return {
success: true, success: true,
message: "Notification cancelled", message: "Notification cancelled",

View File

@@ -18,11 +18,11 @@ 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.notificationRepository.isNotificationScheduled(notificationData); return await contextValue.notificationRepository.isNotificationScheduled(notificationData);
}, },
secondsThresholdForNotification: async (_parent, args, contextValue, _info) => { secondsThresholdForNotification: async (_parent, args, contextValue, _info) => {
const notificationData = args.input; const notificationData = args.input;
return contextValue.notificationRepository.getSecondsThresholdForScheduledNotification(notificationData); return await contextValue.notificationRepository.getSecondsThresholdForNotificationIfExists(notificationData);
}, },
}, },
} }

View File

@@ -38,13 +38,13 @@ describe("MutationResolvers", () => {
} }
` `
function assertFailedResponse(response: any, notificationInput: NotificationInput) { async function assertFailedResponse(response: any, notificationInput: NotificationInput) {
assert(response.body.kind === "single"); assert(response.body.kind === "single");
expect(response.body.singleResult.errors).toBeUndefined(); expect(response.body.singleResult.errors).toBeUndefined();
const notificationResponse = response.body.singleResult.data?.scheduleNotification as any; const notificationResponse = response.body.singleResult.data?.scheduleNotification as any;
expect(notificationResponse.success).toBe(false); expect(notificationResponse.success).toBe(false);
expect(context.notificationRepository.isNotificationScheduled(notificationInput)).toBe(false); expect(await context.notificationRepository.isNotificationScheduled(notificationInput)).toBe(false);
} }
@@ -72,7 +72,7 @@ describe("MutationResolvers", () => {
expect(notificationResponse?.success).toBe(true); expect(notificationResponse?.success).toBe(true);
expect(notificationResponse?.data).toEqual(expectedNotificationData); expect(notificationResponse?.data).toEqual(expectedNotificationData);
expect(context.notificationRepository.getSecondsThresholdForScheduledNotification(expectedNotificationData)).toBe(240); expect(await context.notificationRepository.getSecondsThresholdForNotificationIfExists(expectedNotificationData)).toBe(240);
}); });
it("adds a notification with the default seconds threshold if none is provided", async () => { it("adds a notification with the default seconds threshold if none is provided", async () => {
@@ -93,7 +93,7 @@ describe("MutationResolvers", () => {
const notificationResponse = response.body.singleResult.data?.scheduleNotification as any; const notificationResponse = response.body.singleResult.data?.scheduleNotification as any;
expect(notificationResponse?.success).toBe(true); expect(notificationResponse?.success).toBe(true);
expect(context.notificationRepository.getSecondsThresholdForScheduledNotification(notificationInput)).toBe(180); expect(await context.notificationRepository.getSecondsThresholdForNotificationIfExists(notificationInput)).toBe(180);
}); });
it("fails if the shuttle ID doesn't exist", async () => { it("fails if the shuttle ID doesn't exist", async () => {
@@ -106,7 +106,7 @@ describe("MutationResolvers", () => {
stopId: stop.id, stopId: stop.id,
} }
const response = await getServerResponse(query, notificationInput); const response = await getServerResponse(query, notificationInput);
assertFailedResponse(response, notificationInput); await assertFailedResponse(response, notificationInput);
}); });
it("fails if the stop ID doesn't exist", async () => { it("fails if the stop ID doesn't exist", async () => {
@@ -120,7 +120,7 @@ describe("MutationResolvers", () => {
} }
const response = await getServerResponse(query, notificationInput); const response = await getServerResponse(query, notificationInput);
assertFailedResponse(response, notificationInput); await assertFailedResponse(response, notificationInput);
}); });
}); });
@@ -150,7 +150,7 @@ describe("MutationResolvers", () => {
stopId: stop.id, stopId: stop.id,
secondsThreshold: 180, secondsThreshold: 180,
} }
await context.notificationRepository.scheduleNotification(notificationInput); await context.notificationRepository.addOrUpdateNotification(notificationInput);
const notificationLookup = { const notificationLookup = {
...notificationInput ...notificationInput
@@ -166,7 +166,7 @@ describe("MutationResolvers", () => {
expect(notificationResponse.success).toBe(true); expect(notificationResponse.success).toBe(true);
expect(notificationResponse.data).toEqual(notificationLookup); expect(notificationResponse.data).toEqual(notificationLookup);
expect(context.notificationRepository.isNotificationScheduled(notificationLookup)).toBe(false); expect(await context.notificationRepository.isNotificationScheduled(notificationLookup)).toBe(false);
}); });
it("fails if the notification doesn't exist", async () => { it("fails if the notification doesn't exist", async () => {

View File

@@ -2,8 +2,8 @@ import { describe, expect, it } from "@jest/globals";
import { generateMockSystems } from "../testHelpers/mockDataGenerators"; import { generateMockSystems } from "../testHelpers/mockDataGenerators";
import { setupTestServerContext, setupTestServerHolder } from "../testHelpers/apolloTestServerHelpers"; import { setupTestServerContext, setupTestServerHolder } from "../testHelpers/apolloTestServerHelpers";
import assert = require("node:assert"); import assert = require("node:assert");
import { ScheduledNotification } from "../../src/notifications/schedulers/ETANotificationScheduler";
import { addMockShuttleToRepository, addMockStopToRepository } from "../testHelpers/repositorySetupHelpers"; import { addMockShuttleToRepository, addMockStopToRepository } from "../testHelpers/repositorySetupHelpers";
import { ScheduledNotification } from "../../src/repositories/NotificationRepository";
// See Apollo documentation for integration test guide // See Apollo documentation for integration test guide
// https://www.apollographql.com/docs/apollo-server/testing/testing // https://www.apollographql.com/docs/apollo-server/testing/testing
@@ -106,13 +106,13 @@ describe("QueryResolvers", () => {
const shuttle = await addMockShuttleToRepository(context.shuttleRepository, "1"); const shuttle = await addMockShuttleToRepository(context.shuttleRepository, "1");
const stop = await addMockStopToRepository(context.shuttleRepository, "1") const stop = await addMockStopToRepository(context.shuttleRepository, "1")
const notification: NotificationSchedulingArguments = { const notification: ScheduledNotification = {
shuttleId: shuttle.id, shuttleId: shuttle.id,
stopId: stop.id, stopId: stop.id,
deviceId: "1", deviceId: "1",
secondsThreshold: 240, secondsThreshold: 240,
}; };
await context.notificationRepository.scheduleNotification(notification); await context.notificationRepository.addOrUpdateNotification(notification);
const notificationLookup: any = { const notificationLookup: any = {
...notification, ...notification,