Files
project-inter-server/test/resolvers/MutationResolverTests.test.ts

90 lines
2.6 KiB
TypeScript

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 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,
}
}, {
contextValue: context,
});
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 () => {
const system = await addMockSystemToRepository(context.repository);
const stop = await addMockStopToRepository(context.repository, system.id);
const notificationInput = {
deviceId: "1",
shuttleId: "1",
stopId: stop.id,
}
const response = await holder.testServer.executeOperation({
query,
variables: {
input: notificationInput,
}
}, {
contextValue: context
});
assert(response.body.kind === "single");
expect(response.body.singleResult.errors).toBeUndefined();
expect(response.body.singleResult.data?.success).toBe(false);
});
it("fails if the stop ID doesn't exist", async () => {
});
});
describe("cancelNotification", () => {
it("removes the notification from the notification service", async () => {
});
});
});