mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
move duplicate code to method
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
addMockSystemToRepository
|
||||
} from "../testHelpers/repositorySetupHelpers";
|
||||
import assert = require("node:assert");
|
||||
import { NotificationInput } from "../../src/generated/graphql";
|
||||
|
||||
describe("MutationResolvers", () => {
|
||||
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 () => {
|
||||
const system = await addMockSystemToRepository(context.repository);
|
||||
@@ -70,13 +80,7 @@ describe("MutationResolvers", () => {
|
||||
stopId: stop.id,
|
||||
}
|
||||
const response = await getServerResponse(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);
|
||||
assertFailedResponse(response, notificationInput);
|
||||
});
|
||||
|
||||
it("fails if the stop ID doesn't exist", async () => {
|
||||
@@ -90,12 +94,7 @@ describe("MutationResolvers", () => {
|
||||
}
|
||||
const response = await getServerResponse(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);
|
||||
assertFailedResponse(response, notificationInput);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user