mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
add test for associated route
This commit is contained in:
@@ -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 () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user