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", () => { describe("route", () => {
// Note that there is no `orderedStop(forRouteId)` resolver, // Note that there is no `orderedStop(forRouteId)` resolver,
// so fetch all ordered stops for a stop instead // so fetch all ordered stops for a stop instead.
const query = ` // If we went through the route ID, it would've
query GetNextStop($systemId: ID!, $stopId: ID!) { // relied on the parent data within the route.orderedStop resolver
system(id: $systemId) { async function getResponseForRouteQuery(stopId: string) {
stop(id: $stopId) { const query = `
orderedStops { query GetNextStop($systemId: ID!, $stopId: ID!) {
route { system(id: $systemId) {
id stop(id: $stopId) {
name 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 () => {
});
}); });