mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add same test for stop resolvers + extract apollo request to function
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
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";
|
||||
import assert = require("node:assert");
|
||||
|
||||
describe("MutationResolvers", () => {
|
||||
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 () => {
|
||||
const system = await addMockSystemToRepository(context.repository);
|
||||
const shuttle = await addMockShuttleToRepository(context.repository, system.id);
|
||||
@@ -36,14 +48,7 @@ describe("MutationResolvers", () => {
|
||||
shuttleId: shuttle.id,
|
||||
stopId: stop.id,
|
||||
};
|
||||
const response = await holder.testServer.executeOperation({
|
||||
query,
|
||||
variables: {
|
||||
input: notificationInput,
|
||||
}
|
||||
}, {
|
||||
contextValue: context,
|
||||
});
|
||||
const response = await getServerResponse(notificationInput);
|
||||
|
||||
assert(response.body.kind === "single");
|
||||
expect(response.body.singleResult.errors).toBeUndefined();
|
||||
@@ -62,14 +67,7 @@ describe("MutationResolvers", () => {
|
||||
shuttleId: "1",
|
||||
stopId: stop.id,
|
||||
}
|
||||
const response = await holder.testServer.executeOperation({
|
||||
query,
|
||||
variables: {
|
||||
input: notificationInput,
|
||||
}
|
||||
}, {
|
||||
contextValue: context
|
||||
});
|
||||
const response = await getServerResponse(notificationInput);
|
||||
|
||||
assert(response.body.kind === "single");
|
||||
expect(response.body.singleResult.errors).toBeUndefined();
|
||||
@@ -78,7 +76,20 @@ describe("MutationResolvers", () => {
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user