mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add a test for cancelling notification
This commit is contained in:
@@ -12,6 +12,17 @@ describe("MutationResolvers", () => {
|
|||||||
const holder = setupTestServerHolder()
|
const holder = setupTestServerHolder()
|
||||||
const context = setupTestServerContext();
|
const context = setupTestServerContext();
|
||||||
|
|
||||||
|
async function getServerResponse(query: string, notificationInput: { deviceId: string; shuttleId: string; stopId: string }) {
|
||||||
|
return await holder.testServer.executeOperation({
|
||||||
|
query,
|
||||||
|
variables: {
|
||||||
|
input: notificationInput,
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
contextValue: context
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
describe("scheduleNotification", () => {
|
describe("scheduleNotification", () => {
|
||||||
const query = `
|
const query = `
|
||||||
mutation ScheduleNotification($input: NotificationInput!) {
|
mutation ScheduleNotification($input: NotificationInput!) {
|
||||||
@@ -27,17 +38,6 @@ describe("MutationResolvers", () => {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
async function getServerResponse(notificationInput: { deviceId: string; shuttleId: string; stopId: string }) {
|
|
||||||
return await holder.testServer.executeOperation({
|
|
||||||
query,
|
|
||||||
variables: {
|
|
||||||
input: notificationInput,
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
contextValue: context
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function assertFailedResponse(response: any, notificationInput: NotificationInput) {
|
function assertFailedResponse(response: any, notificationInput: NotificationInput) {
|
||||||
assert(response.body.kind === "single");
|
assert(response.body.kind === "single");
|
||||||
expect(response.body.singleResult.errors).toBeUndefined();
|
expect(response.body.singleResult.errors).toBeUndefined();
|
||||||
@@ -58,7 +58,7 @@ describe("MutationResolvers", () => {
|
|||||||
shuttleId: shuttle.id,
|
shuttleId: shuttle.id,
|
||||||
stopId: stop.id,
|
stopId: stop.id,
|
||||||
};
|
};
|
||||||
const response = await getServerResponse(notificationInput);
|
const response = await getServerResponse(query, notificationInput);
|
||||||
|
|
||||||
assert(response.body.kind === "single");
|
assert(response.body.kind === "single");
|
||||||
expect(response.body.singleResult.errors).toBeUndefined();
|
expect(response.body.singleResult.errors).toBeUndefined();
|
||||||
@@ -79,7 +79,7 @@ describe("MutationResolvers", () => {
|
|||||||
shuttleId: "1",
|
shuttleId: "1",
|
||||||
stopId: stop.id,
|
stopId: stop.id,
|
||||||
}
|
}
|
||||||
const response = await getServerResponse(notificationInput);
|
const response = await getServerResponse(query, notificationInput);
|
||||||
assertFailedResponse(response, notificationInput);
|
assertFailedResponse(response, notificationInput);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -92,14 +92,51 @@ describe("MutationResolvers", () => {
|
|||||||
shuttleId: shuttle.id,
|
shuttleId: shuttle.id,
|
||||||
stopId: "1",
|
stopId: "1",
|
||||||
}
|
}
|
||||||
const response = await getServerResponse(notificationInput);
|
const response = await getServerResponse(query, notificationInput);
|
||||||
|
|
||||||
assertFailedResponse(response, notificationInput);
|
assertFailedResponse(response, notificationInput);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("cancelNotification", () => {
|
describe("cancelNotification", () => {
|
||||||
|
const query = `
|
||||||
|
query CancelNotification($input: NotificationInput!) {
|
||||||
|
cancelNotification(input: $input) {
|
||||||
|
success
|
||||||
|
message
|
||||||
|
data {
|
||||||
|
deviceId
|
||||||
|
shuttleId
|
||||||
|
stopId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
it("removes the notification from the notification service", async () => {
|
it("removes the notification from 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,
|
||||||
|
}
|
||||||
|
await context.notificationService.scheduleNotification(notificationInput);
|
||||||
|
|
||||||
|
const response = await getServerResponse(query, notificationInput);
|
||||||
|
|
||||||
|
assert(response.body.kind === "single");
|
||||||
|
expect(response.body.singleResult.errors).toBeUndefined();
|
||||||
|
|
||||||
|
const cancelledNotification = response.body.singleResult.data?.cancelNotification as any;
|
||||||
|
expect(cancelledNotification).toStrictEqual(notificationInput);
|
||||||
|
|
||||||
|
expect(context.notificationService.isNotificationScheduled(notificationInput)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("fails if the notification doesn't exist", async () => {
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user