From 1627bc39fe247f95c80df7a4eebb47e2aea696ea Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 4 Feb 2025 11:27:34 -0800 Subject: [PATCH] move duplicate code to method --- test/resolvers/MutationResolverTests.test.ts | 25 ++++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/test/resolvers/MutationResolverTests.test.ts b/test/resolvers/MutationResolverTests.test.ts index afad9d8..5ab147f 100644 --- a/test/resolvers/MutationResolverTests.test.ts +++ b/test/resolvers/MutationResolverTests.test.ts @@ -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); }); });