mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
update tests for mutation resolvers
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { NotificationInput, NotificationResponse, Resolvers } from "../generated/graphql";
|
import { NotificationResponse, Resolvers } from "../generated/graphql";
|
||||||
import { ServerContext } from "../ServerContext";
|
import { ServerContext } from "../ServerContext";
|
||||||
import {
|
import {
|
||||||
ETANotificationScheduler,
|
ETANotificationScheduler,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
addMockSystemToRepository
|
addMockSystemToRepository
|
||||||
} from "../testHelpers/repositorySetupHelpers";
|
} from "../testHelpers/repositorySetupHelpers";
|
||||||
import assert = require("node:assert");
|
import assert = require("node:assert");
|
||||||
import { NotificationInput } from "../../src/generated/graphql";
|
import { NotificationSchedulingArguments } from "../../src/generated/graphql";
|
||||||
|
|
||||||
describe("MutationResolvers", () => {
|
describe("MutationResolvers", () => {
|
||||||
const holder = setupTestServerHolder()
|
const holder = setupTestServerHolder()
|
||||||
@@ -25,7 +25,7 @@ describe("MutationResolvers", () => {
|
|||||||
|
|
||||||
describe("scheduleNotification", () => {
|
describe("scheduleNotification", () => {
|
||||||
const query = `
|
const query = `
|
||||||
mutation ScheduleNotification($input: NotificationInput!) {
|
mutation ScheduleNotification($input: NotificationSchedulingArguments!) {
|
||||||
scheduleNotification(input: $input) {
|
scheduleNotification(input: $input) {
|
||||||
success
|
success
|
||||||
message
|
message
|
||||||
@@ -38,7 +38,7 @@ describe("MutationResolvers", () => {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
function assertFailedResponse(response: any, notificationInput: NotificationInput) {
|
function assertFailedResponse(response: any, notificationInput: NotificationSchedulingArguments) {
|
||||||
assert(response.body.kind === "single");
|
assert(response.body.kind === "single");
|
||||||
expect(response.body.singleResult.errors).toBeUndefined();
|
expect(response.body.singleResult.errors).toBeUndefined();
|
||||||
const notificationResponse = response.body.singleResult.data?.scheduleNotification as any;
|
const notificationResponse = response.body.singleResult.data?.scheduleNotification as any;
|
||||||
@@ -53,6 +53,33 @@ describe("MutationResolvers", () => {
|
|||||||
const shuttle = await addMockShuttleToRepository(context.repository, system.id);
|
const shuttle = await addMockShuttleToRepository(context.repository, system.id);
|
||||||
const stop = await addMockStopToRepository(context.repository, system.id);
|
const stop = await addMockStopToRepository(context.repository, system.id);
|
||||||
|
|
||||||
|
const notificationInput = {
|
||||||
|
deviceId: "1",
|
||||||
|
shuttleId: shuttle.id,
|
||||||
|
stopId: stop.id,
|
||||||
|
secondsThreshold: 240,
|
||||||
|
};
|
||||||
|
const response = await getServerResponse(query, notificationInput);
|
||||||
|
|
||||||
|
assert(response.body.kind === "single");
|
||||||
|
expect(response.body.singleResult.errors).toBeUndefined();
|
||||||
|
|
||||||
|
const expectedNotificationData: any = {
|
||||||
|
...notificationInput,
|
||||||
|
}
|
||||||
|
delete expectedNotificationData.secondsThreshold;
|
||||||
|
const notificationResponse = response.body.singleResult.data?.scheduleNotification as any;
|
||||||
|
expect(notificationResponse?.success).toBe(true);
|
||||||
|
expect(notificationResponse?.data).toEqual(expectedNotificationData);
|
||||||
|
|
||||||
|
expect(context.notificationService.getSecondsThresholdForScheduledNotification(expectedNotificationData)).toBe(240);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds a notification with the default seconds threshold if none is provided", 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 = {
|
const notificationInput = {
|
||||||
deviceId: "1",
|
deviceId: "1",
|
||||||
shuttleId: shuttle.id,
|
shuttleId: shuttle.id,
|
||||||
@@ -65,9 +92,8 @@ describe("MutationResolvers", () => {
|
|||||||
|
|
||||||
const notificationResponse = response.body.singleResult.data?.scheduleNotification as any;
|
const notificationResponse = response.body.singleResult.data?.scheduleNotification as any;
|
||||||
expect(notificationResponse?.success).toBe(true);
|
expect(notificationResponse?.success).toBe(true);
|
||||||
expect(notificationResponse?.data).toEqual(notificationInput);
|
|
||||||
|
|
||||||
expect(context.notificationService.isNotificationScheduled(notificationInput)).toBe(true);
|
expect(context.notificationService.getSecondsThresholdForScheduledNotification(notificationInput)).toBe(180);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails if the shuttle ID doesn't exist", async () => {
|
it("fails if the shuttle ID doesn't exist", async () => {
|
||||||
@@ -100,7 +126,7 @@ describe("MutationResolvers", () => {
|
|||||||
|
|
||||||
describe("cancelNotification", () => {
|
describe("cancelNotification", () => {
|
||||||
const query = `
|
const query = `
|
||||||
mutation CancelNotification($input: NotificationInput!) {
|
mutation CancelNotification($input: NotificationLookupArguments!) {
|
||||||
cancelNotification(input: $input) {
|
cancelNotification(input: $input) {
|
||||||
success
|
success
|
||||||
message
|
message
|
||||||
@@ -118,23 +144,29 @@ describe("MutationResolvers", () => {
|
|||||||
const shuttle = await addMockShuttleToRepository(context.repository, system.id);
|
const shuttle = await addMockShuttleToRepository(context.repository, system.id);
|
||||||
const stop = await addMockStopToRepository(context.repository, system.id);
|
const stop = await addMockStopToRepository(context.repository, system.id);
|
||||||
|
|
||||||
const notificationInput = {
|
const notificationInput: any = {
|
||||||
deviceId: "1",
|
deviceId: "1",
|
||||||
shuttleId: shuttle.id,
|
shuttleId: shuttle.id,
|
||||||
stopId: stop.id,
|
stopId: stop.id,
|
||||||
|
secondsThreshold: 180,
|
||||||
}
|
}
|
||||||
await context.notificationService.scheduleNotification(notificationInput);
|
await context.notificationService.scheduleNotification(notificationInput);
|
||||||
|
|
||||||
const response = await getServerResponse(query, notificationInput);
|
const notificationLookup = {
|
||||||
|
...notificationInput
|
||||||
|
}
|
||||||
|
delete notificationLookup.secondsThreshold;
|
||||||
|
|
||||||
|
const response = await getServerResponse(query, notificationLookup);
|
||||||
|
|
||||||
assert(response.body.kind === "single");
|
assert(response.body.kind === "single");
|
||||||
expect(response.body.singleResult.errors).toBeUndefined();
|
expect(response.body.singleResult.errors).toBeUndefined();
|
||||||
|
|
||||||
const notificationResponse = response.body.singleResult.data?.cancelNotification as any;
|
const notificationResponse = response.body.singleResult.data?.cancelNotification as any;
|
||||||
expect(notificationResponse.success).toBe(true);
|
expect(notificationResponse.success).toBe(true);
|
||||||
expect(notificationResponse.data).toEqual(notificationInput);
|
expect(notificationResponse.data).toEqual(notificationLookup);
|
||||||
|
|
||||||
expect(context.notificationService.isNotificationScheduled(notificationInput)).toBe(false);
|
expect(context.notificationService.isNotificationScheduled(notificationLookup)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails if the notification doesn't exist", async () => {
|
it("fails if the notification doesn't exist", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user