add test for associated route

This commit is contained in:
2025-01-28 15:07:54 -08:00
parent 9ca432c5b4
commit 3aeaca6844

View File

@@ -208,28 +208,59 @@ describe("OrderedStopResolvers", () => {
describe("route", () => {
// Note that there is no `orderedStop(forRouteId)` resolver,
// so fetch all ordered stops for a stop instead
const query = `
query GetNextStop($systemId: ID!, $stopId: ID!) {
system(id: $systemId) {
stop(id: $stopId) {
orderedStops {
route {
id
name
// so fetch all ordered stops for a stop instead.
// If we went through the route ID, it would've
// relied on the parent data within the route.orderedStop resolver
async function getResponseForRouteQuery(stopId: string) {
const query = `
query GetNextStop($systemId: ID!, $stopId: ID!) {
system(id: $systemId) {
stop(id: $stopId) {
orderedStops {
route {
id
name
}
}
}
}
}
`;
return await testServer.executeOperation({
query,
variables: {
systemId: mockSystem.id,
stopId,
}
}, {
contextValue: {
repository,
}
});
}
`;
});
it("returns the associated route if it exists", async () => {
it("returns the associated route if it exists", async () => {
const orderedStops = generateMockOrderedStops();
orderedStops[0].routeId = mockRoute.id;
orderedStops[0].stopId = mockStops[0].id;
});
// Add one stop only
await repository.addOrUpdateOrderedStop(orderedStops[0]);
it("returns null if the route doesn't exist", async () => {
const response = await getResponseForRouteQuery(orderedStops[1].stopId);
assert(response.body.kind === "single");
expect(response.body.singleResult.errors).toBeUndefined();
const route = (response.body.singleResult.data?.system as any).stop.orderedStops[0].route
expect(route.id).toEqual(mockRoute.id);
expect(route.name).toEqual(mockRoute.name);
});
it("returns null if the route doesn't exist", async () => {
});
});