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