add a test for cancelling notification

This commit is contained in:
2025-02-04 11:32:33 -08:00
parent d7b15812f3
commit acc4d08716

View File

@@ -12,6 +12,17 @@ describe("MutationResolvers", () => {
const holder = setupTestServerHolder()
const context = setupTestServerContext();
async function getServerResponse(query: string, notificationInput: { deviceId: string; shuttleId: string; stopId: string }) {
return await holder.testServer.executeOperation({
query,
variables: {
input: notificationInput,
}
}, {
contextValue: context
});
}
describe("scheduleNotification", () => {
const query = `
mutation ScheduleNotification($input: NotificationInput!) {
@@ -27,17 +38,6 @@ describe("MutationResolvers", () => {
}
`
async function getServerResponse(notificationInput: { deviceId: string; shuttleId: string; stopId: string }) {
return await holder.testServer.executeOperation({
query,
variables: {
input: notificationInput,
}
}, {
contextValue: context
});
}
function assertFailedResponse(response: any, notificationInput: NotificationInput) {
assert(response.body.kind === "single");
expect(response.body.singleResult.errors).toBeUndefined();
@@ -58,7 +58,7 @@ describe("MutationResolvers", () => {
shuttleId: shuttle.id,
stopId: stop.id,
};
const response = await getServerResponse(notificationInput);
const response = await getServerResponse(query, notificationInput);
assert(response.body.kind === "single");
expect(response.body.singleResult.errors).toBeUndefined();
@@ -79,7 +79,7 @@ describe("MutationResolvers", () => {
shuttleId: "1",
stopId: stop.id,
}
const response = await getServerResponse(notificationInput);
const response = await getServerResponse(query, notificationInput);
assertFailedResponse(response, notificationInput);
});
@@ -92,14 +92,51 @@ describe("MutationResolvers", () => {
shuttleId: shuttle.id,
stopId: "1",
}
const response = await getServerResponse(notificationInput);
const response = await getServerResponse(query, notificationInput);
assertFailedResponse(response, notificationInput);
});
});
describe("cancelNotification", () => {
const query = `
query CancelNotification($input: NotificationInput!) {
cancelNotification(input: $input) {
success
message
data {
deviceId
shuttleId
stopId
}
}
}
`
it("removes the notification from the notification service", async () => {
const system = await addMockSystemToRepository(context.repository);
const shuttle = await addMockShuttleToRepository(context.repository, system.id);
const stop = await addMockStopToRepository(context.repository, system.id);
const notificationInput = {
deviceId: "1",
shuttleId: shuttle.id,
stopId: stop.id,
}
await context.notificationService.scheduleNotification(notificationInput);
const response = await getServerResponse(query, notificationInput);
assert(response.body.kind === "single");
expect(response.body.singleResult.errors).toBeUndefined();
const cancelledNotification = response.body.singleResult.data?.cancelNotification as any;
expect(cancelledNotification).toStrictEqual(notificationInput);
expect(context.notificationService.isNotificationScheduled(notificationInput)).toBe(false);
});
it("fails if the notification doesn't exist", async () => {
});
});