move duplicate code to method

This commit is contained in:
2025-02-04 11:27:34 -08:00
parent 69e2748eec
commit 1627bc39fe

View File

@@ -6,6 +6,7 @@ import {
addMockSystemToRepository addMockSystemToRepository
} from "../testHelpers/repositorySetupHelpers"; } from "../testHelpers/repositorySetupHelpers";
import assert = require("node:assert"); import assert = require("node:assert");
import { NotificationInput } from "../../src/generated/graphql";
describe("MutationResolvers", () => { describe("MutationResolvers", () => {
const holder = setupTestServerHolder() const holder = setupTestServerHolder()
@@ -37,6 +38,15 @@ describe("MutationResolvers", () => {
}); });
} }
function assertFailedResponse(response: any, notificationInput: NotificationInput) {
assert(response.body.kind === "single");
expect(response.body.singleResult.errors).toBeUndefined();
const notificationResponse = response.body.singleResult.data?.scheduleNotification as any;
expect(notificationResponse.success).toBe(false);
expect(context.notificationService.isNotificationScheduled(notificationInput)).toBe(false);
}
it("adds a notification to the notification service", async () => { it("adds a notification to the notification service", async () => {
const system = await addMockSystemToRepository(context.repository); const system = await addMockSystemToRepository(context.repository);
@@ -70,13 +80,7 @@ describe("MutationResolvers", () => {
stopId: stop.id, stopId: stop.id,
} }
const response = await getServerResponse(notificationInput); const response = await getServerResponse(notificationInput);
assertFailedResponse(response, notificationInput);
assert(response.body.kind === "single");
expect(response.body.singleResult.errors).toBeUndefined();
const notificationResponse = response.body.singleResult.data?.scheduleNotification as any;
expect(notificationResponse.success).toBe(false);
expect(context.notificationService.isNotificationScheduled(notificationInput)).toBe(false);
}); });
it("fails if the stop ID doesn't exist", async () => { it("fails if the stop ID doesn't exist", async () => {
@@ -90,12 +94,7 @@ describe("MutationResolvers", () => {
} }
const response = await getServerResponse(notificationInput); const response = await getServerResponse(notificationInput);
assert(response.body.kind === "single"); assertFailedResponse(response, notificationInput);
expect(response.body.singleResult.errors).toBeUndefined();
const notificationResponse = response.body.singleResult.data?.scheduleNotification as any;
expect(notificationResponse.success).toBe(false);
expect(context.notificationService.isNotificationScheduled(notificationInput)).toBe(false);
}); });
}); });