add same test for stop resolvers + extract apollo request to function

This commit is contained in:
2025-02-04 11:24:37 -08:00
parent cea7b48323
commit 94c15f93dd

View File

@@ -1,11 +1,11 @@
import { describe, expect, it } from "@jest/globals"; import { describe, expect, it } from "@jest/globals";
import { setupTestServerContext, setupTestServerHolder } from "../testHelpers/apolloTestServerHelpers"; import { setupTestServerContext, setupTestServerHolder } from "../testHelpers/apolloTestServerHelpers";
import assert = require("node:assert");
import { import {
addMockShuttleToRepository, addMockShuttleToRepository,
addMockStopToRepository, addMockStopToRepository,
addMockSystemToRepository addMockSystemToRepository
} from "../testHelpers/repositorySetupHelpers"; } from "../testHelpers/repositorySetupHelpers";
import assert = require("node:assert");
describe("MutationResolvers", () => { describe("MutationResolvers", () => {
const holder = setupTestServerHolder() const holder = setupTestServerHolder()
@@ -26,6 +26,18 @@ describe("MutationResolvers", () => {
} }
` `
async function getServerResponse(notificationInput: { deviceId: string; shuttleId: string; stopId: string }) {
return await holder.testServer.executeOperation({
query,
variables: {
input: notificationInput,
}
}, {
contextValue: context
});
}
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);
const shuttle = await addMockShuttleToRepository(context.repository, system.id); const shuttle = await addMockShuttleToRepository(context.repository, system.id);
@@ -36,14 +48,7 @@ describe("MutationResolvers", () => {
shuttleId: shuttle.id, shuttleId: shuttle.id,
stopId: stop.id, stopId: stop.id,
}; };
const response = await holder.testServer.executeOperation({ const response = await getServerResponse(notificationInput);
query,
variables: {
input: notificationInput,
}
}, {
contextValue: context,
});
assert(response.body.kind === "single"); assert(response.body.kind === "single");
expect(response.body.singleResult.errors).toBeUndefined(); expect(response.body.singleResult.errors).toBeUndefined();
@@ -62,14 +67,7 @@ describe("MutationResolvers", () => {
shuttleId: "1", shuttleId: "1",
stopId: stop.id, stopId: stop.id,
} }
const response = await holder.testServer.executeOperation({ const response = await getServerResponse(notificationInput);
query,
variables: {
input: notificationInput,
}
}, {
contextValue: context
});
assert(response.body.kind === "single"); assert(response.body.kind === "single");
expect(response.body.singleResult.errors).toBeUndefined(); expect(response.body.singleResult.errors).toBeUndefined();
@@ -78,7 +76,20 @@ describe("MutationResolvers", () => {
}); });
it("fails if the stop ID doesn't exist", async () => { it("fails if the stop ID doesn't exist", async () => {
const system = await addMockSystemToRepository(context.repository);
const shuttle = await addMockShuttleToRepository(context.repository, system.id);
const notificationInput = {
deviceId: "1",
shuttleId: shuttle.id,
stopId: "1",
}
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);
}); });
}); });