mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
rename repository to server repository in server context
This commit is contained in:
@@ -2,6 +2,6 @@ import { ETANotificationScheduler } from "./notifications/schedulers/ETANotifica
|
||||
import { ShuttleGetterSetterRepository } from "./repositories/ShuttleGetterSetterRepository";
|
||||
|
||||
export interface ServerContext {
|
||||
repository: ShuttleGetterSetterRepository;
|
||||
shuttleRepository: ShuttleGetterSetterRepository;
|
||||
notificationService: ETANotificationScheduler;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import { ServerContext } from "../ServerContext";
|
||||
export const EtaResolvers: Resolvers<ServerContext> = {
|
||||
ETA: {
|
||||
stop: async (parent, args, contextValue, info) => {
|
||||
return await contextValue.repository.getStopById(parent.stopId);
|
||||
return await contextValue.shuttleRepository.getStopById(parent.stopId);
|
||||
},
|
||||
shuttle: async (parent, args, contextValue, info) => {
|
||||
return await contextValue.repository.getShuttleById(parent.shuttleId);
|
||||
return await contextValue.shuttleRepository.getShuttleById(parent.shuttleId);
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -8,14 +8,14 @@ import { ScheduledNotification } from "../repositories/NotificationRepository";
|
||||
export const MutationResolvers: Resolvers<ServerContext> = {
|
||||
Mutation: {
|
||||
scheduleNotification: async (_parent, args, context, _info) => {
|
||||
const shuttle = await context.repository.getShuttleById(args.input.shuttleId);
|
||||
const shuttle = await context.shuttleRepository.getShuttleById(args.input.shuttleId);
|
||||
if (!shuttle) {
|
||||
return {
|
||||
message: "Shuttle ID doesn't exist",
|
||||
success: false,
|
||||
}
|
||||
}
|
||||
const stop = await context.repository.getStopById(args.input.stopId);
|
||||
const stop = await context.shuttleRepository.getStopById(args.input.stopId);
|
||||
if (!stop) {
|
||||
return {
|
||||
message: "Stop ID doesn't exist",
|
||||
|
||||
@@ -7,13 +7,13 @@ export const OrderedStopResolvers: Resolvers<ServerContext> = {
|
||||
const routeId = parent.routeId;
|
||||
const stopId = parent.stopId;
|
||||
|
||||
const currentOrderedStop = await contextValue.repository.getOrderedStopByRouteAndStopId(routeId, stopId);
|
||||
const currentOrderedStop = await contextValue.shuttleRepository.getOrderedStopByRouteAndStopId(routeId, stopId);
|
||||
if (!currentOrderedStop) return null;
|
||||
|
||||
const nextOrderedStop = currentOrderedStop.nextStop;
|
||||
if (!nextOrderedStop) return null;
|
||||
|
||||
const nextOrderedStopObject = await contextValue.repository.getStopById(nextOrderedStop.stopId);
|
||||
const nextOrderedStopObject = await contextValue.shuttleRepository.getStopById(nextOrderedStop.stopId);
|
||||
if (!nextOrderedStopObject) return null;
|
||||
|
||||
return {
|
||||
@@ -26,13 +26,13 @@ export const OrderedStopResolvers: Resolvers<ServerContext> = {
|
||||
const routeId = parent.routeId;
|
||||
const stopId = parent.stopId;
|
||||
|
||||
const currentOrderedStop = await contextValue.repository.getOrderedStopByRouteAndStopId(routeId, stopId);
|
||||
const currentOrderedStop = await contextValue.shuttleRepository.getOrderedStopByRouteAndStopId(routeId, stopId);
|
||||
if (!currentOrderedStop) return null;
|
||||
|
||||
const previousOrderedStop = currentOrderedStop.previousStop;
|
||||
if (!previousOrderedStop) return null;
|
||||
|
||||
const previousOrderedStopObject = await contextValue.repository.getStopById(previousOrderedStop.stopId);
|
||||
const previousOrderedStopObject = await contextValue.shuttleRepository.getStopById(previousOrderedStop.stopId);
|
||||
if (!previousOrderedStopObject) return null;
|
||||
|
||||
return {
|
||||
@@ -42,10 +42,10 @@ export const OrderedStopResolvers: Resolvers<ServerContext> = {
|
||||
}
|
||||
},
|
||||
stop: async (parent, args, contextValue, info) => {
|
||||
return await contextValue.repository.getStopById(parent.stopId);
|
||||
return await contextValue.shuttleRepository.getStopById(parent.stopId);
|
||||
},
|
||||
route: async (parent, args, contextValue, info) => {
|
||||
return await contextValue.repository.getRouteById(parent.routeId);
|
||||
return await contextValue.shuttleRepository.getRouteById(parent.routeId);
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ import { Resolvers } from "../generated/graphql";
|
||||
export const QueryResolvers: Resolvers<ServerContext> = {
|
||||
Query: {
|
||||
systems: async (_parent, args, contextValue, _info) => {
|
||||
return await contextValue.repository.getSystems();
|
||||
return await contextValue.shuttleRepository.getSystems();
|
||||
},
|
||||
system: async (_parent, args, contextValue, _info) => {
|
||||
if (!args.id) return null;
|
||||
const system = await contextValue.repository.getSystemById(args.id);
|
||||
const system = await contextValue.shuttleRepository.getSystemById(args.id);
|
||||
if (system === null) return null;
|
||||
|
||||
return {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ServerContext } from "../ServerContext";
|
||||
export const RouteResolvers: Resolvers<ServerContext> = {
|
||||
Route: {
|
||||
shuttles: async (parent, args, contextValue, info) => {
|
||||
const shuttles = await contextValue.repository.getShuttlesByRouteId(parent.id);
|
||||
const shuttles = await contextValue.shuttleRepository.getShuttlesByRouteId(parent.id);
|
||||
|
||||
return shuttles.map(({
|
||||
coordinates,
|
||||
@@ -22,10 +22,10 @@ export const RouteResolvers: Resolvers<ServerContext> = {
|
||||
},
|
||||
orderedStop: async (parent, args, contextValue, info) => {
|
||||
if (!args.forStopId) return null;
|
||||
const orderedStop = await contextValue.repository.getOrderedStopByRouteAndStopId(parent.id, args.forStopId);
|
||||
const orderedStop = await contextValue.shuttleRepository.getOrderedStopByRouteAndStopId(parent.id, args.forStopId);
|
||||
if (!orderedStop) return null;
|
||||
|
||||
const stop = await contextValue.repository.getStopById(orderedStop.stopId);
|
||||
const stop = await contextValue.shuttleRepository.getStopById(orderedStop.stopId);
|
||||
if (!stop) return null;
|
||||
|
||||
return {
|
||||
|
||||
@@ -5,7 +5,7 @@ export const ShuttleResolvers: Resolvers<ServerContext> = {
|
||||
Shuttle: {
|
||||
eta: async (parent, args, contextValue, info) => {
|
||||
if (!args.forStopId) return null;
|
||||
const etaForStopId = await contextValue.repository.getEtaForShuttleAndStopId(parent.id, args.forStopId);
|
||||
const etaForStopId = await contextValue.shuttleRepository.getEtaForShuttleAndStopId(parent.id, args.forStopId);
|
||||
if (etaForStopId === null) return null;
|
||||
|
||||
return {
|
||||
@@ -16,7 +16,7 @@ export const ShuttleResolvers: Resolvers<ServerContext> = {
|
||||
};
|
||||
},
|
||||
etas: async (parent, args, contextValue, info) => {
|
||||
const etasForShuttle = await contextValue.repository.getEtasForShuttleId(parent.id);
|
||||
const etasForShuttle = await contextValue.shuttleRepository.getEtasForShuttleId(parent.id);
|
||||
if (!etasForShuttle) return null;
|
||||
|
||||
const computedEtas = await Promise.all(etasForShuttle.map(async ({
|
||||
@@ -38,7 +38,7 @@ export const ShuttleResolvers: Resolvers<ServerContext> = {
|
||||
return [];
|
||||
},
|
||||
route: async (parent, args, contextValue, info) => {
|
||||
const route = await contextValue.repository.getRouteById(parent.routeId);
|
||||
const route = await contextValue.shuttleRepository.getRouteById(parent.routeId);
|
||||
if (route === null) return null;
|
||||
|
||||
return {
|
||||
|
||||
@@ -4,10 +4,10 @@ import { ServerContext } from "../ServerContext";
|
||||
export const StopResolvers: Resolvers<ServerContext> = {
|
||||
Stop: {
|
||||
orderedStops: async (parent, args, contextValue, info) => {
|
||||
return await contextValue.repository.getOrderedStopsByStopId(parent.id);
|
||||
return await contextValue.shuttleRepository.getOrderedStopsByStopId(parent.id);
|
||||
},
|
||||
etas: async (parent, args, contextValue, info) => {
|
||||
return await contextValue.repository.getEtasForStopId(parent.id);
|
||||
return await contextValue.shuttleRepository.getEtasForStopId(parent.id);
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -4,14 +4,14 @@ import { ServerContext } from "../ServerContext";
|
||||
export const SystemResolvers: Resolvers<ServerContext> = {
|
||||
System: {
|
||||
routes: async (parent, args, contextValue, info) => {
|
||||
return await contextValue.repository.getRoutesBySystemId(parent.id);
|
||||
return await contextValue.shuttleRepository.getRoutesBySystemId(parent.id);
|
||||
},
|
||||
stops: async (parent, args, contextValue, info) => {
|
||||
return await contextValue.repository.getStopsBySystemId(parent.id);
|
||||
return await contextValue.shuttleRepository.getStopsBySystemId(parent.id);
|
||||
},
|
||||
stop: async (parent, args, contextValue, info) => {
|
||||
if (!args.id) return null;
|
||||
const stop = await contextValue.repository.getStopById(args.id);
|
||||
const stop = await contextValue.shuttleRepository.getStopById(args.id);
|
||||
if (stop === null) return null;
|
||||
|
||||
if (stop.systemId !== parent.id) return null;
|
||||
@@ -24,7 +24,7 @@ export const SystemResolvers: Resolvers<ServerContext> = {
|
||||
},
|
||||
route: async (parent, args, contextValue, info) => {
|
||||
if (!args.id) return null;
|
||||
const route = await contextValue.repository.getRouteById(args.id);
|
||||
const route = await contextValue.shuttleRepository.getRouteById(args.id);
|
||||
if (route === null) return null;
|
||||
|
||||
if (route.systemId !== parent.id) return null;
|
||||
@@ -38,7 +38,7 @@ export const SystemResolvers: Resolvers<ServerContext> = {
|
||||
},
|
||||
shuttle: async (parent, args, contextValue, info) => {
|
||||
if (!args.id) return null;
|
||||
const shuttle = await contextValue.repository.getShuttleById(args.id);
|
||||
const shuttle = await contextValue.shuttleRepository.getShuttleById(args.id);
|
||||
if (shuttle === null) return null;
|
||||
|
||||
if (shuttle.systemId !== parent.id) return null;
|
||||
@@ -46,7 +46,7 @@ export const SystemResolvers: Resolvers<ServerContext> = {
|
||||
return shuttle;
|
||||
},
|
||||
shuttles: async (parent, args, contextValue, info) => {
|
||||
return await contextValue.repository.getShuttlesBySystemId(parent.id);
|
||||
return await contextValue.shuttleRepository.getShuttlesBySystemId(parent.id);
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -18,10 +18,10 @@ describe("EtaResolvers", () => {
|
||||
let expectedEta: IEta;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockSystem = await addMockSystemToRepository(context.repository);
|
||||
mockShuttle = await addMockShuttleToRepository(context.repository, mockSystem.id);
|
||||
mockStop = await addMockStopToRepository(context.repository, mockSystem.id);
|
||||
expectedEta = await addMockEtaToRepository(context.repository, mockStop.id, mockShuttle.id);
|
||||
mockSystem = await addMockSystemToRepository(context.shuttleRepository);
|
||||
mockShuttle = await addMockShuttleToRepository(context.shuttleRepository, mockSystem.id);
|
||||
mockStop = await addMockStopToRepository(context.shuttleRepository, mockSystem.id);
|
||||
expectedEta = await addMockEtaToRepository(context.shuttleRepository, mockStop.id, mockShuttle.id);
|
||||
});
|
||||
|
||||
async function getResponseForEtaQuery(query: string) {
|
||||
@@ -32,9 +32,8 @@ describe("EtaResolvers", () => {
|
||||
shuttleId: mockShuttle.id,
|
||||
},
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -49,9 +49,9 @@ describe("MutationResolvers", () => {
|
||||
|
||||
|
||||
it("adds a notification to 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 system = await addMockSystemToRepository(context.shuttleRepository);
|
||||
const shuttle = await addMockShuttleToRepository(context.shuttleRepository, system.id);
|
||||
const stop = await addMockStopToRepository(context.shuttleRepository, system.id);
|
||||
|
||||
const notificationInput = {
|
||||
deviceId: "1",
|
||||
@@ -76,9 +76,9 @@ describe("MutationResolvers", () => {
|
||||
});
|
||||
|
||||
it("adds a notification with the default seconds threshold if none is provided", async () => {
|
||||
const system = await addMockSystemToRepository(context.repository);
|
||||
const shuttle = await addMockShuttleToRepository(context.repository, system.id);
|
||||
const stop = await addMockStopToRepository(context.repository, system.id);
|
||||
const system = await addMockSystemToRepository(context.shuttleRepository);
|
||||
const shuttle = await addMockShuttleToRepository(context.shuttleRepository, system.id);
|
||||
const stop = await addMockStopToRepository(context.shuttleRepository, system.id);
|
||||
|
||||
const notificationInput = {
|
||||
deviceId: "1",
|
||||
@@ -97,8 +97,8 @@ describe("MutationResolvers", () => {
|
||||
});
|
||||
|
||||
it("fails if the shuttle ID doesn't exist", async () => {
|
||||
const system = await addMockSystemToRepository(context.repository);
|
||||
const stop = await addMockStopToRepository(context.repository, system.id);
|
||||
const system = await addMockSystemToRepository(context.shuttleRepository);
|
||||
const stop = await addMockStopToRepository(context.shuttleRepository, system.id);
|
||||
|
||||
const notificationInput = {
|
||||
deviceId: "1",
|
||||
@@ -110,8 +110,8 @@ describe("MutationResolvers", () => {
|
||||
});
|
||||
|
||||
it("fails if the stop ID doesn't exist", async () => {
|
||||
const system = await addMockSystemToRepository(context.repository);
|
||||
const shuttle = await addMockShuttleToRepository(context.repository, system.id);
|
||||
const system = await addMockSystemToRepository(context.shuttleRepository);
|
||||
const shuttle = await addMockShuttleToRepository(context.shuttleRepository, system.id);
|
||||
|
||||
const notificationInput = {
|
||||
deviceId: "1",
|
||||
@@ -140,9 +140,9 @@ describe("MutationResolvers", () => {
|
||||
`
|
||||
|
||||
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 system = await addMockSystemToRepository(context.shuttleRepository);
|
||||
const shuttle = await addMockShuttleToRepository(context.shuttleRepository, system.id);
|
||||
const stop = await addMockStopToRepository(context.shuttleRepository, system.id);
|
||||
|
||||
const notificationInput: any = {
|
||||
deviceId: "1",
|
||||
|
||||
@@ -14,13 +14,13 @@ describe("OrderedStopResolvers", () => {
|
||||
let mockStops: IStop[];
|
||||
|
||||
beforeEach(async () => {
|
||||
mockSystem = await addMockSystemToRepository(context.repository);
|
||||
mockRoute = await addMockRouteToRepository(context.repository, mockSystem.id);
|
||||
mockSystem = await addMockSystemToRepository(context.shuttleRepository);
|
||||
mockRoute = await addMockRouteToRepository(context.shuttleRepository, mockSystem.id);
|
||||
|
||||
mockStops = generateMockStops();
|
||||
await Promise.all(mockStops.map(async (mockStop) => {
|
||||
mockStop.systemId = mockSystem.id;
|
||||
await context.repository.addOrUpdateStop(mockStop);
|
||||
await context.shuttleRepository.addOrUpdateStop(mockStop);
|
||||
}));
|
||||
});
|
||||
|
||||
@@ -38,8 +38,8 @@ describe("OrderedStopResolvers", () => {
|
||||
// Link the stops together
|
||||
orderedStops[0].nextStop = orderedStops[1];
|
||||
orderedStops[1].previousStop = orderedStops[0];
|
||||
await context.repository.addOrUpdateOrderedStop(orderedStops[0]);
|
||||
await context.repository.addOrUpdateOrderedStop(orderedStops[1]);
|
||||
await context.shuttleRepository.addOrUpdateOrderedStop(orderedStops[0]);
|
||||
await context.shuttleRepository.addOrUpdateOrderedStop(orderedStops[1]);
|
||||
return orderedStops;
|
||||
}
|
||||
|
||||
@@ -68,9 +68,8 @@ describe("OrderedStopResolvers", () => {
|
||||
stopId,
|
||||
},
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -94,7 +93,7 @@ describe("OrderedStopResolvers", () => {
|
||||
it("returns null if there is no next stop in the repository", async () => {
|
||||
const orderedStops = await setUpOrderedStopsInRepository();
|
||||
orderedStops[0].nextStop = undefined;
|
||||
await context.repository.addOrUpdateOrderedStop(orderedStops[0]);
|
||||
await context.shuttleRepository.addOrUpdateOrderedStop(orderedStops[0]);
|
||||
|
||||
const response = await getResponseForNextStopQuery(orderedStops[0].stopId);
|
||||
|
||||
@@ -105,7 +104,7 @@ describe("OrderedStopResolvers", () => {
|
||||
|
||||
it("returns null if the next stop object no longer exists", async () => {
|
||||
const orderedStops = await setUpOrderedStopsInRepository();
|
||||
await context.repository.removeStopIfExists(orderedStops[1].stopId);
|
||||
await context.shuttleRepository.removeStopIfExists(orderedStops[1].stopId);
|
||||
|
||||
const response = await getResponseForNextStopQuery(orderedStops[0].stopId);
|
||||
|
||||
@@ -140,9 +139,8 @@ describe("OrderedStopResolvers", () => {
|
||||
stopId,
|
||||
},
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -165,7 +163,7 @@ describe("OrderedStopResolvers", () => {
|
||||
it("returns null if there is no previous stop in the repository", async () => {
|
||||
const orderedStops = await setUpOrderedStopsInRepository();
|
||||
orderedStops[1].previousStop = undefined;
|
||||
await context.repository.addOrUpdateOrderedStop(orderedStops[1]);
|
||||
await context.shuttleRepository.addOrUpdateOrderedStop(orderedStops[1]);
|
||||
|
||||
const response = await getResponseForPreviousStopQuery(orderedStops[1].stopId);
|
||||
|
||||
@@ -176,7 +174,7 @@ describe("OrderedStopResolvers", () => {
|
||||
|
||||
it("returns null if the current stop no longer exists", async () => {
|
||||
const orderedStops = await setUpOrderedStopsInRepository();
|
||||
await context.repository.removeStopIfExists(orderedStops[0].stopId);
|
||||
await context.shuttleRepository.removeStopIfExists(orderedStops[0].stopId);
|
||||
|
||||
const response = await getResponseForPreviousStopQuery(orderedStops[1].stopId);
|
||||
|
||||
@@ -214,9 +212,8 @@ describe("OrderedStopResolvers", () => {
|
||||
stopId,
|
||||
}
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -226,7 +223,7 @@ describe("OrderedStopResolvers", () => {
|
||||
orderedStops[0].stopId = mockStops[0].id;
|
||||
|
||||
// Add one stop only
|
||||
await context.repository.addOrUpdateOrderedStop(orderedStops[0]);
|
||||
await context.shuttleRepository.addOrUpdateOrderedStop(orderedStops[0]);
|
||||
|
||||
const response = await getResponseForRouteQuery(orderedStops[1].stopId);
|
||||
|
||||
@@ -265,16 +262,15 @@ describe("OrderedStopResolvers", () => {
|
||||
stopId,
|
||||
}
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
it("returns the associated stop if it exists", async () => {
|
||||
const orderedStops = await setUpOrderedStopsInRepository();
|
||||
orderedStops[0].stopId = mockStops[0].id;
|
||||
await context.repository.addOrUpdateOrderedStop(orderedStops[0]);
|
||||
await context.shuttleRepository.addOrUpdateOrderedStop(orderedStops[0]);
|
||||
|
||||
const response = await getResponseForStopQuery(orderedStops[0].stopId);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ describe("QueryResolvers", () => {
|
||||
async function addMockSystems() {
|
||||
const systems = generateMockSystems();
|
||||
await Promise.all(systems.map(async (system) => {
|
||||
await context.repository.addOrUpdateSystem(system);
|
||||
await context.shuttleRepository.addOrUpdateSystem(system);
|
||||
}));
|
||||
return systems;
|
||||
}
|
||||
@@ -36,9 +36,8 @@ describe("QueryResolvers", () => {
|
||||
const response = await holder.testServer.executeOperation({
|
||||
query,
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
},
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
|
||||
assert(response.body.kind === "single");
|
||||
@@ -68,9 +67,8 @@ describe("QueryResolvers", () => {
|
||||
id: systemToGet.id,
|
||||
}
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
|
||||
assert(response.body.kind === "single");
|
||||
@@ -85,9 +83,8 @@ describe("QueryResolvers", () => {
|
||||
id: "nonexistent-id",
|
||||
}
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
|
||||
assert(response.body.kind === "single");
|
||||
@@ -106,8 +103,8 @@ describe("QueryResolvers", () => {
|
||||
|
||||
it("returns correct data if the notification is scheduled", async () => {
|
||||
// Arrange
|
||||
const shuttle = await addMockShuttleToRepository(context.repository, "1");
|
||||
const stop = await addMockStopToRepository(context.repository, "1")
|
||||
const shuttle = await addMockShuttleToRepository(context.shuttleRepository, "1");
|
||||
const stop = await addMockStopToRepository(context.shuttleRepository, "1")
|
||||
|
||||
const notification: NotificationSchedulingArguments = {
|
||||
shuttleId: shuttle.id,
|
||||
|
||||
@@ -18,11 +18,11 @@ describe("RouteResolvers", () => {
|
||||
let mockStop: IStop;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockSystem = await addMockSystemToRepository(context.repository);
|
||||
mockSystem = await addMockSystemToRepository(context.shuttleRepository);
|
||||
const systemId = mockSystem.id;
|
||||
|
||||
mockRoute = await addMockRouteToRepository(context.repository, systemId);
|
||||
mockStop = await addMockStopToRepository(context.repository, systemId);
|
||||
mockRoute = await addMockRouteToRepository(context.shuttleRepository, systemId);
|
||||
mockStop = await addMockStopToRepository(context.shuttleRepository, systemId);
|
||||
});
|
||||
|
||||
|
||||
@@ -48,9 +48,8 @@ describe("RouteResolvers", () => {
|
||||
routeId: mockRoute.id,
|
||||
},
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -59,7 +58,7 @@ describe("RouteResolvers", () => {
|
||||
const expectedShuttle = expectedShuttles[0];
|
||||
expectedShuttle.systemId = mockSystem.id;
|
||||
expectedShuttle.routeId = mockRoute.id;
|
||||
await context.repository.addOrUpdateShuttle(expectedShuttle);
|
||||
await context.shuttleRepository.addOrUpdateShuttle(expectedShuttle);
|
||||
|
||||
const response = await getResponseForShuttlesQuery();
|
||||
|
||||
@@ -104,9 +103,8 @@ describe("RouteResolvers", () => {
|
||||
stopId: mockStop.id,
|
||||
}
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -115,7 +113,7 @@ describe("RouteResolvers", () => {
|
||||
const expectedOrderedStop = orderedStops[0];
|
||||
expectedOrderedStop.stopId = mockStop.id;
|
||||
expectedOrderedStop.routeId = mockRoute.id;
|
||||
await context.repository.addOrUpdateOrderedStop(expectedOrderedStop);
|
||||
await context.shuttleRepository.addOrUpdateOrderedStop(expectedOrderedStop);
|
||||
|
||||
const response = await getResponseForOrderedStopQuery();
|
||||
|
||||
@@ -132,9 +130,9 @@ describe("RouteResolvers", () => {
|
||||
const expectedOrderedStop = orderedStops[0];
|
||||
expectedOrderedStop.stopId = mockStop.id;
|
||||
expectedOrderedStop.routeId = mockRoute.id;
|
||||
await context.repository.addOrUpdateOrderedStop(expectedOrderedStop);
|
||||
await context.shuttleRepository.addOrUpdateOrderedStop(expectedOrderedStop);
|
||||
|
||||
await context.repository.removeStopIfExists(mockStop.id);
|
||||
await context.shuttleRepository.removeStopIfExists(mockStop.id);
|
||||
|
||||
const response = await getResponseForOrderedStopQuery();
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ describe("ShuttleResolvers", () => {
|
||||
let mockShuttle: IShuttle;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockSystem = await addMockSystemToRepository(context.repository);
|
||||
mockShuttle = await addMockShuttleToRepository(context.repository,
|
||||
mockSystem = await addMockSystemToRepository(context.shuttleRepository);
|
||||
mockShuttle = await addMockShuttleToRepository(context.shuttleRepository,
|
||||
mockSystem.id);
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ describe("ShuttleResolvers", () => {
|
||||
const etas = generateMockEtas();
|
||||
await Promise.all(etas.map(async (eta) => {
|
||||
eta.shuttleId = shuttleId;
|
||||
await context.repository.addOrUpdateEta(eta);
|
||||
await context.shuttleRepository.addOrUpdateEta(eta);
|
||||
}));
|
||||
return etas;
|
||||
}
|
||||
@@ -56,9 +56,8 @@ describe("ShuttleResolvers", () => {
|
||||
stopId: mockEta.stopId,
|
||||
},
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
},
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
|
||||
// Assert
|
||||
@@ -77,9 +76,8 @@ describe("ShuttleResolvers", () => {
|
||||
stopId: "nonexistent-stop",
|
||||
}
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
|
||||
// Assert
|
||||
@@ -114,9 +112,8 @@ describe("ShuttleResolvers", () => {
|
||||
shuttleId: mockShuttle.id,
|
||||
},
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
|
||||
assert(response.body.kind === "single");
|
||||
@@ -133,9 +130,8 @@ describe("ShuttleResolvers", () => {
|
||||
shuttleId: mockShuttle.id,
|
||||
},
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
|
||||
assert(response.body.kind === "single");
|
||||
@@ -172,15 +168,14 @@ describe("ShuttleResolvers", () => {
|
||||
shuttleId: mockShuttle.id,
|
||||
}
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
it("returns the route if it exists", async () => {
|
||||
const mockRoute = generateMockRoutes()[0];
|
||||
await context.repository.addOrUpdateRoute(mockRoute);
|
||||
await context.shuttleRepository.addOrUpdateRoute(mockRoute);
|
||||
|
||||
const response = await getResponseForQuery();
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ describe("StopResolvers", () => {
|
||||
let mockSystem: ISystem;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockSystem = await addMockSystemToRepository(context.repository);
|
||||
mockStop = await addMockStopToRepository(context.repository, mockSystem.id);
|
||||
mockSystem = await addMockSystemToRepository(context.shuttleRepository);
|
||||
mockStop = await addMockStopToRepository(context.shuttleRepository, mockSystem.id);
|
||||
})
|
||||
|
||||
async function getResponseForQuery(query: string) {
|
||||
@@ -25,9 +25,7 @@ describe("StopResolvers", () => {
|
||||
stopId: mockStop.id,
|
||||
},
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -51,7 +49,7 @@ describe("StopResolvers", () => {
|
||||
mockOrderedStops = mockOrderedStops.filter((orderedStop) => orderedStop.stopId === mockOrderedStops[0].stopId);
|
||||
await Promise.all(mockOrderedStops.map(async orderedStop => {
|
||||
orderedStop.stopId = mockStop.id;
|
||||
await context.repository.addOrUpdateOrderedStop(orderedStop);
|
||||
await context.shuttleRepository.addOrUpdateOrderedStop(orderedStop);
|
||||
}));
|
||||
|
||||
const response = await getResponseForQuery(query);
|
||||
@@ -88,7 +86,7 @@ describe("StopResolvers", () => {
|
||||
mockEtas = mockEtas.filter((eta) => eta.stopId === mockEtas[0].stopId);
|
||||
await Promise.all(mockEtas.map(async eta => {
|
||||
eta.stopId = mockStop.id;
|
||||
await context.repository.addOrUpdateEta(eta);
|
||||
await context.shuttleRepository.addOrUpdateEta(eta);
|
||||
}));
|
||||
|
||||
const response = await getResponseForQuery(query);
|
||||
|
||||
@@ -17,7 +17,7 @@ describe("SystemResolvers", () => {
|
||||
let mockSystem: ISystem;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockSystem = await addMockSystemToRepository(context.repository);
|
||||
mockSystem = await addMockSystemToRepository(context.shuttleRepository);
|
||||
});
|
||||
|
||||
// TODO: Consolidate these into one single method taking an object
|
||||
@@ -29,7 +29,7 @@ describe("SystemResolvers", () => {
|
||||
},
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository
|
||||
shuttleRepository: context.shuttleRepository
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -50,7 +50,7 @@ describe("SystemResolvers", () => {
|
||||
const expectedRoutes = generateMockRoutes();
|
||||
await Promise.all(expectedRoutes.map(async (route) => {
|
||||
route.systemId = mockSystem.id;
|
||||
await context.repository.addOrUpdateRoute(route);
|
||||
await context.shuttleRepository.addOrUpdateRoute(route);
|
||||
}));
|
||||
|
||||
const response = await getResponseFromQueryNeedingSystemId(query);
|
||||
@@ -78,7 +78,7 @@ describe("SystemResolvers", () => {
|
||||
const expectedStops = generateMockStops();
|
||||
await Promise.all(expectedStops.map(async (stop) => {
|
||||
stop.systemId = mockSystem.id;
|
||||
await context.repository.addOrUpdateStop(stop);
|
||||
await context.shuttleRepository.addOrUpdateStop(stop);
|
||||
}));
|
||||
|
||||
const response = await getResponseFromQueryNeedingSystemId(query);
|
||||
@@ -111,13 +111,13 @@ describe("SystemResolvers", () => {
|
||||
},
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
shuttleRepository: context.shuttleRepository,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
it("gets the stop with the correct id", async () => {
|
||||
const mockStop = await addMockStopToRepository(context.repository, mockSystem.id);
|
||||
const mockStop = await addMockStopToRepository(context.shuttleRepository, mockSystem.id);
|
||||
|
||||
const response = await getResponseForStopQuery(mockStop.id);
|
||||
|
||||
@@ -133,9 +133,9 @@ describe("SystemResolvers", () => {
|
||||
...mockSystem,
|
||||
id: "2",
|
||||
}
|
||||
await context.repository.addOrUpdateSystem(updatedSystem);
|
||||
await context.shuttleRepository.addOrUpdateSystem(updatedSystem);
|
||||
|
||||
const mockStop = await addMockStopToRepository(context.repository, updatedSystem.id);
|
||||
const mockStop = await addMockStopToRepository(context.shuttleRepository, updatedSystem.id);
|
||||
|
||||
const response = await getResponseForStopQuery(mockStop.id);
|
||||
|
||||
@@ -177,14 +177,12 @@ describe("SystemResolvers", () => {
|
||||
routeId,
|
||||
},
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context
|
||||
});
|
||||
}
|
||||
|
||||
it("gets the route with the correct id", async () => {
|
||||
const mockRoute = await addMockRouteToRepository(context.repository, mockSystem.id);
|
||||
const mockRoute = await addMockRouteToRepository(context.shuttleRepository, mockSystem.id);
|
||||
|
||||
const response = await getResponseForRouteQuery(mockRoute.id);
|
||||
|
||||
@@ -201,9 +199,9 @@ describe("SystemResolvers", () => {
|
||||
...mockSystem,
|
||||
id: "2",
|
||||
}
|
||||
await context.repository.addOrUpdateSystem(updatedSystem);
|
||||
await context.shuttleRepository.addOrUpdateSystem(updatedSystem);
|
||||
|
||||
const mockRoute = await addMockRouteToRepository(context.repository, updatedSystem.id);
|
||||
const mockRoute = await addMockRouteToRepository(context.shuttleRepository, updatedSystem.id);
|
||||
|
||||
const response = await getResponseForRouteQuery(mockRoute.id);
|
||||
|
||||
@@ -245,14 +243,13 @@ describe("SystemResolvers", () => {
|
||||
shuttleId: shuttleId,
|
||||
}
|
||||
}, {
|
||||
contextValue: {
|
||||
repository: context.repository,
|
||||
}
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
it("gets the shuttle with the correct id", async () => {
|
||||
const mockShuttle = await addMockShuttleToRepository(context.repository, mockSystem.id);
|
||||
const mockShuttle = await addMockShuttleToRepository(context.shuttleRepository, mockSystem.id);
|
||||
|
||||
const response = await getResponseForShuttleQuery(mockShuttle.id);
|
||||
|
||||
@@ -268,9 +265,9 @@ describe("SystemResolvers", () => {
|
||||
...mockSystem,
|
||||
id: "2",
|
||||
}
|
||||
await context.repository.addOrUpdateSystem(updatedSystem);
|
||||
await context.shuttleRepository.addOrUpdateSystem(updatedSystem);
|
||||
|
||||
const mockShuttle = await addMockShuttleToRepository(context.repository, updatedSystem.id);
|
||||
const mockShuttle = await addMockShuttleToRepository(context.shuttleRepository, updatedSystem.id);
|
||||
|
||||
const response = await getResponseForShuttleQuery(mockShuttle.id);
|
||||
|
||||
@@ -308,7 +305,7 @@ describe("SystemResolvers", () => {
|
||||
const expectedShuttles = generateMockShuttles();
|
||||
await Promise.all(expectedShuttles.map(async (shuttle) => {
|
||||
shuttle.systemId = mockSystem.id;
|
||||
await context.repository.addOrUpdateShuttle(shuttle);
|
||||
await context.shuttleRepository.addOrUpdateShuttle(shuttle);
|
||||
}));
|
||||
|
||||
const response = await getResponseFromQueryNeedingSystemId(query);
|
||||
|
||||
@@ -25,7 +25,7 @@ export function setupTestServerContext() {
|
||||
const context: { [key: string] : any } = {};
|
||||
|
||||
beforeEach(() => {
|
||||
context.repository = new UnoptimizedInMemoryShuttleRepository();
|
||||
context.shuttleRepository = new UnoptimizedInMemoryShuttleRepository();
|
||||
context.notificationService = new ETANotificationScheduler(context.repository);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user