diff --git a/test/resolvers/MutationResolverTests.test.ts b/test/resolvers/MutationResolverTests.test.ts index 4731199..9e8b887 100644 --- a/test/resolvers/MutationResolverTests.test.ts +++ b/test/resolvers/MutationResolverTests.test.ts @@ -1,15 +1,61 @@ -import { describe, it } from "@jest/globals"; -import { setupTestServerHolder } from "../testHelpers/apolloTestServerHelpers"; +import { describe, expect, it } from "@jest/globals"; +import { setupTestServerContext, setupTestServerHolder } from "../testHelpers/apolloTestServerHelpers"; +import assert = require("node:assert"); +import { + addMockShuttleToRepository, + addMockStopToRepository, + addMockSystemToRepository +} from "../testHelpers/repositorySetupHelpers"; describe("MutationResolvers", () => { - const testServerHolder = setupTestServerHolder() + const holder = setupTestServerHolder() + const context = setupTestServerContext(); describe("scheduleNotification", () => { + const query = ` + mutation ScheduleNotification($input: NotificationInput!) { + scheduleNotification(input: $input) { + success + message + notification { + deviceId + shuttleId + stopId + } + } + } + ` + it("adds a notification to 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, + }; + const response = await holder.testServer.executeOperation({ + query, + variables: { + input: notificationInput, + } + }); + + assert(response.body.kind === "single"); + expect(response.body.singleResult.errors).toBeUndefined(); + + const returnedData = response.body.singleResult.data; + expect(returnedData?.success).toBe(true); + expect(returnedData?.notification).toStrictEqual(notificationInput); + }); + + it("fails if the shuttle ID doesn't exist", async () => { }); - it("ensures that notifications fire when the ETA changes to below threshold", async () => { + it("fails if the stop ID doesn't exist", async () => { }); });