rename repository to server repository in server context

This commit is contained in:
2025-03-27 10:38:02 -07:00
parent bba00eb067
commit bda46d6808
18 changed files with 128 additions and 148 deletions

View File

@@ -2,6 +2,6 @@ import { ETANotificationScheduler } from "./notifications/schedulers/ETANotifica
import { ShuttleGetterSetterRepository } from "./repositories/ShuttleGetterSetterRepository"; import { ShuttleGetterSetterRepository } from "./repositories/ShuttleGetterSetterRepository";
export interface ServerContext { export interface ServerContext {
repository: ShuttleGetterSetterRepository; shuttleRepository: ShuttleGetterSetterRepository;
notificationService: ETANotificationScheduler; notificationService: ETANotificationScheduler;
} }

View File

@@ -4,10 +4,10 @@ import { ServerContext } from "../ServerContext";
export const EtaResolvers: Resolvers<ServerContext> = { export const EtaResolvers: Resolvers<ServerContext> = {
ETA: { ETA: {
stop: async (parent, args, contextValue, info) => { 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) => { shuttle: async (parent, args, contextValue, info) => {
return await contextValue.repository.getShuttleById(parent.shuttleId); return await contextValue.shuttleRepository.getShuttleById(parent.shuttleId);
}, },
}, },
} }

View File

@@ -8,14 +8,14 @@ import { ScheduledNotification } from "../repositories/NotificationRepository";
export const MutationResolvers: Resolvers<ServerContext> = { export const MutationResolvers: Resolvers<ServerContext> = {
Mutation: { Mutation: {
scheduleNotification: async (_parent, args, context, _info) => { 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) { if (!shuttle) {
return { return {
message: "Shuttle ID doesn't exist", message: "Shuttle ID doesn't exist",
success: false, success: false,
} }
} }
const stop = await context.repository.getStopById(args.input.stopId); const stop = await context.shuttleRepository.getStopById(args.input.stopId);
if (!stop) { if (!stop) {
return { return {
message: "Stop ID doesn't exist", message: "Stop ID doesn't exist",

View File

@@ -7,13 +7,13 @@ export const OrderedStopResolvers: Resolvers<ServerContext> = {
const routeId = parent.routeId; const routeId = parent.routeId;
const stopId = parent.stopId; const stopId = parent.stopId;
const currentOrderedStop = await contextValue.repository.getOrderedStopByRouteAndStopId(routeId, stopId); const currentOrderedStop = await contextValue.shuttleRepository.getOrderedStopByRouteAndStopId(routeId, stopId);
if (!currentOrderedStop) return null; if (!currentOrderedStop) return null;
const nextOrderedStop = currentOrderedStop.nextStop; const nextOrderedStop = currentOrderedStop.nextStop;
if (!nextOrderedStop) return null; if (!nextOrderedStop) return null;
const nextOrderedStopObject = await contextValue.repository.getStopById(nextOrderedStop.stopId); const nextOrderedStopObject = await contextValue.shuttleRepository.getStopById(nextOrderedStop.stopId);
if (!nextOrderedStopObject) return null; if (!nextOrderedStopObject) return null;
return { return {
@@ -26,13 +26,13 @@ export const OrderedStopResolvers: Resolvers<ServerContext> = {
const routeId = parent.routeId; const routeId = parent.routeId;
const stopId = parent.stopId; const stopId = parent.stopId;
const currentOrderedStop = await contextValue.repository.getOrderedStopByRouteAndStopId(routeId, stopId); const currentOrderedStop = await contextValue.shuttleRepository.getOrderedStopByRouteAndStopId(routeId, stopId);
if (!currentOrderedStop) return null; if (!currentOrderedStop) return null;
const previousOrderedStop = currentOrderedStop.previousStop; const previousOrderedStop = currentOrderedStop.previousStop;
if (!previousOrderedStop) return null; if (!previousOrderedStop) return null;
const previousOrderedStopObject = await contextValue.repository.getStopById(previousOrderedStop.stopId); const previousOrderedStopObject = await contextValue.shuttleRepository.getStopById(previousOrderedStop.stopId);
if (!previousOrderedStopObject) return null; if (!previousOrderedStopObject) return null;
return { return {
@@ -42,11 +42,11 @@ export const OrderedStopResolvers: Resolvers<ServerContext> = {
} }
}, },
stop: async (parent, args, contextValue, info) => { 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) => { route: async (parent, args, contextValue, info) => {
return await contextValue.repository.getRouteById(parent.routeId); return await contextValue.shuttleRepository.getRouteById(parent.routeId);
}, },
}, },
} }

View File

@@ -4,11 +4,11 @@ import { Resolvers } from "../generated/graphql";
export const QueryResolvers: Resolvers<ServerContext> = { export const QueryResolvers: Resolvers<ServerContext> = {
Query: { Query: {
systems: async (_parent, args, contextValue, _info) => { systems: async (_parent, args, contextValue, _info) => {
return await contextValue.repository.getSystems(); return await contextValue.shuttleRepository.getSystems();
}, },
system: async (_parent, args, contextValue, _info) => { system: async (_parent, args, contextValue, _info) => {
if (!args.id) return null; 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; if (system === null) return null;
return { return {

View File

@@ -4,7 +4,7 @@ import { ServerContext } from "../ServerContext";
export const RouteResolvers: Resolvers<ServerContext> = { export const RouteResolvers: Resolvers<ServerContext> = {
Route: { Route: {
shuttles: async (parent, args, contextValue, info) => { 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(({ return shuttles.map(({
coordinates, coordinates,
@@ -22,10 +22,10 @@ export const RouteResolvers: Resolvers<ServerContext> = {
}, },
orderedStop: async (parent, args, contextValue, info) => { orderedStop: async (parent, args, contextValue, info) => {
if (!args.forStopId) return null; 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; if (!orderedStop) return null;
const stop = await contextValue.repository.getStopById(orderedStop.stopId); const stop = await contextValue.shuttleRepository.getStopById(orderedStop.stopId);
if (!stop) return null; if (!stop) return null;
return { return {

View File

@@ -5,7 +5,7 @@ export const ShuttleResolvers: Resolvers<ServerContext> = {
Shuttle: { Shuttle: {
eta: async (parent, args, contextValue, info) => { eta: async (parent, args, contextValue, info) => {
if (!args.forStopId) return null; 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; if (etaForStopId === null) return null;
return { return {
@@ -16,7 +16,7 @@ export const ShuttleResolvers: Resolvers<ServerContext> = {
}; };
}, },
etas: async (parent, args, contextValue, info) => { 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; if (!etasForShuttle) return null;
const computedEtas = await Promise.all(etasForShuttle.map(async ({ const computedEtas = await Promise.all(etasForShuttle.map(async ({
@@ -38,7 +38,7 @@ export const ShuttleResolvers: Resolvers<ServerContext> = {
return []; return [];
}, },
route: async (parent, args, contextValue, info) => { 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; if (route === null) return null;
return { return {
@@ -49,4 +49,4 @@ export const ShuttleResolvers: Resolvers<ServerContext> = {
} }
} }
}, },
} }

View File

@@ -4,10 +4,10 @@ import { ServerContext } from "../ServerContext";
export const StopResolvers: Resolvers<ServerContext> = { export const StopResolvers: Resolvers<ServerContext> = {
Stop: { Stop: {
orderedStops: async (parent, args, contextValue, info) => { 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) => { etas: async (parent, args, contextValue, info) => {
return await contextValue.repository.getEtasForStopId(parent.id); return await contextValue.shuttleRepository.getEtasForStopId(parent.id);
}, },
}, },
} }

View File

@@ -4,14 +4,14 @@ import { ServerContext } from "../ServerContext";
export const SystemResolvers: Resolvers<ServerContext> = { export const SystemResolvers: Resolvers<ServerContext> = {
System: { System: {
routes: async (parent, args, contextValue, info) => { 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) => { 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) => { stop: async (parent, args, contextValue, info) => {
if (!args.id) return null; 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 === null) return null;
if (stop.systemId !== parent.id) return null; if (stop.systemId !== parent.id) return null;
@@ -24,7 +24,7 @@ export const SystemResolvers: Resolvers<ServerContext> = {
}, },
route: async (parent, args, contextValue, info) => { route: async (parent, args, contextValue, info) => {
if (!args.id) return null; 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 === null) return null;
if (route.systemId !== parent.id) return null; if (route.systemId !== parent.id) return null;
@@ -38,7 +38,7 @@ export const SystemResolvers: Resolvers<ServerContext> = {
}, },
shuttle: async (parent, args, contextValue, info) => { shuttle: async (parent, args, contextValue, info) => {
if (!args.id) return null; 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 === null) return null;
if (shuttle.systemId !== parent.id) return null; if (shuttle.systemId !== parent.id) return null;
@@ -46,7 +46,7 @@ export const SystemResolvers: Resolvers<ServerContext> = {
return shuttle; return shuttle;
}, },
shuttles: async (parent, args, contextValue, info) => { shuttles: async (parent, args, contextValue, info) => {
return await contextValue.repository.getShuttlesBySystemId(parent.id); return await contextValue.shuttleRepository.getShuttlesBySystemId(parent.id);
} }
}, },
} }

View File

@@ -18,10 +18,10 @@ describe("EtaResolvers", () => {
let expectedEta: IEta; let expectedEta: IEta;
beforeEach(async () => { beforeEach(async () => {
mockSystem = await addMockSystemToRepository(context.repository); mockSystem = await addMockSystemToRepository(context.shuttleRepository);
mockShuttle = await addMockShuttleToRepository(context.repository, mockSystem.id); mockShuttle = await addMockShuttleToRepository(context.shuttleRepository, mockSystem.id);
mockStop = await addMockStopToRepository(context.repository, mockSystem.id); mockStop = await addMockStopToRepository(context.shuttleRepository, mockSystem.id);
expectedEta = await addMockEtaToRepository(context.repository, mockStop.id, mockShuttle.id); expectedEta = await addMockEtaToRepository(context.shuttleRepository, mockStop.id, mockShuttle.id);
}); });
async function getResponseForEtaQuery(query: string) { async function getResponseForEtaQuery(query: string) {
@@ -32,9 +32,8 @@ describe("EtaResolvers", () => {
shuttleId: mockShuttle.id, shuttleId: mockShuttle.id,
}, },
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
}
}); });
return response; return response;
} }

View File

@@ -49,9 +49,9 @@ describe("MutationResolvers", () => {
it("adds a notification to the notification service", async () => { it("adds a notification to the notification service", async () => {
const system = await addMockSystemToRepository(context.repository); const system = await addMockSystemToRepository(context.shuttleRepository);
const shuttle = await addMockShuttleToRepository(context.repository, system.id); const shuttle = await addMockShuttleToRepository(context.shuttleRepository, system.id);
const stop = await addMockStopToRepository(context.repository, system.id); const stop = await addMockStopToRepository(context.shuttleRepository, system.id);
const notificationInput = { const notificationInput = {
deviceId: "1", deviceId: "1",
@@ -76,9 +76,9 @@ describe("MutationResolvers", () => {
}); });
it("adds a notification with the default seconds threshold if none is provided", async () => { it("adds a notification with the default seconds threshold if none is provided", async () => {
const system = await addMockSystemToRepository(context.repository); const system = await addMockSystemToRepository(context.shuttleRepository);
const shuttle = await addMockShuttleToRepository(context.repository, system.id); const shuttle = await addMockShuttleToRepository(context.shuttleRepository, system.id);
const stop = await addMockStopToRepository(context.repository, system.id); const stop = await addMockStopToRepository(context.shuttleRepository, system.id);
const notificationInput = { const notificationInput = {
deviceId: "1", deviceId: "1",
@@ -97,8 +97,8 @@ describe("MutationResolvers", () => {
}); });
it("fails if the shuttle ID doesn't exist", async () => { it("fails if the shuttle ID doesn't exist", async () => {
const system = await addMockSystemToRepository(context.repository); const system = await addMockSystemToRepository(context.shuttleRepository);
const stop = await addMockStopToRepository(context.repository, system.id); const stop = await addMockStopToRepository(context.shuttleRepository, system.id);
const notificationInput = { const notificationInput = {
deviceId: "1", deviceId: "1",
@@ -110,8 +110,8 @@ describe("MutationResolvers", () => {
}); });
it("fails if the stop ID doesn't exist", async () => { it("fails if the stop ID doesn't exist", async () => {
const system = await addMockSystemToRepository(context.repository); const system = await addMockSystemToRepository(context.shuttleRepository);
const shuttle = await addMockShuttleToRepository(context.repository, system.id); const shuttle = await addMockShuttleToRepository(context.shuttleRepository, system.id);
const notificationInput = { const notificationInput = {
deviceId: "1", deviceId: "1",
@@ -140,9 +140,9 @@ describe("MutationResolvers", () => {
` `
it("removes the notification from the notification service", async () => { it("removes the notification from the notification service", async () => {
const system = await addMockSystemToRepository(context.repository); const system = await addMockSystemToRepository(context.shuttleRepository);
const shuttle = await addMockShuttleToRepository(context.repository, system.id); const shuttle = await addMockShuttleToRepository(context.shuttleRepository, system.id);
const stop = await addMockStopToRepository(context.repository, system.id); const stop = await addMockStopToRepository(context.shuttleRepository, system.id);
const notificationInput: any = { const notificationInput: any = {
deviceId: "1", deviceId: "1",

View File

@@ -14,13 +14,13 @@ describe("OrderedStopResolvers", () => {
let mockStops: IStop[]; let mockStops: IStop[];
beforeEach(async () => { beforeEach(async () => {
mockSystem = await addMockSystemToRepository(context.repository); mockSystem = await addMockSystemToRepository(context.shuttleRepository);
mockRoute = await addMockRouteToRepository(context.repository, mockSystem.id); mockRoute = await addMockRouteToRepository(context.shuttleRepository, mockSystem.id);
mockStops = generateMockStops(); mockStops = generateMockStops();
await Promise.all(mockStops.map(async (mockStop) => { await Promise.all(mockStops.map(async (mockStop) => {
mockStop.systemId = mockSystem.id; mockStop.systemId = mockSystem.id;
await context.repository.addOrUpdateStop(mockStop); await context.shuttleRepository.addOrUpdateStop(mockStop);
})); }));
}); });
@@ -38,8 +38,8 @@ describe("OrderedStopResolvers", () => {
// Link the stops together // Link the stops together
orderedStops[0].nextStop = orderedStops[1]; orderedStops[0].nextStop = orderedStops[1];
orderedStops[1].previousStop = orderedStops[0]; orderedStops[1].previousStop = orderedStops[0];
await context.repository.addOrUpdateOrderedStop(orderedStops[0]); await context.shuttleRepository.addOrUpdateOrderedStop(orderedStops[0]);
await context.repository.addOrUpdateOrderedStop(orderedStops[1]); await context.shuttleRepository.addOrUpdateOrderedStop(orderedStops[1]);
return orderedStops; return orderedStops;
} }
@@ -68,9 +68,8 @@ describe("OrderedStopResolvers", () => {
stopId, stopId,
}, },
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
}
}); });
} }
@@ -94,7 +93,7 @@ describe("OrderedStopResolvers", () => {
it("returns null if there is no next stop in the repository", async () => { it("returns null if there is no next stop in the repository", async () => {
const orderedStops = await setUpOrderedStopsInRepository(); const orderedStops = await setUpOrderedStopsInRepository();
orderedStops[0].nextStop = undefined; orderedStops[0].nextStop = undefined;
await context.repository.addOrUpdateOrderedStop(orderedStops[0]); await context.shuttleRepository.addOrUpdateOrderedStop(orderedStops[0]);
const response = await getResponseForNextStopQuery(orderedStops[0].stopId); 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 () => { it("returns null if the next stop object no longer exists", async () => {
const orderedStops = await setUpOrderedStopsInRepository(); 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); const response = await getResponseForNextStopQuery(orderedStops[0].stopId);
@@ -140,9 +139,8 @@ describe("OrderedStopResolvers", () => {
stopId, stopId,
}, },
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
}
}); });
} }
@@ -165,7 +163,7 @@ describe("OrderedStopResolvers", () => {
it("returns null if there is no previous stop in the repository", async () => { it("returns null if there is no previous stop in the repository", async () => {
const orderedStops = await setUpOrderedStopsInRepository(); const orderedStops = await setUpOrderedStopsInRepository();
orderedStops[1].previousStop = undefined; orderedStops[1].previousStop = undefined;
await context.repository.addOrUpdateOrderedStop(orderedStops[1]); await context.shuttleRepository.addOrUpdateOrderedStop(orderedStops[1]);
const response = await getResponseForPreviousStopQuery(orderedStops[1].stopId); const response = await getResponseForPreviousStopQuery(orderedStops[1].stopId);
@@ -176,7 +174,7 @@ describe("OrderedStopResolvers", () => {
it("returns null if the current stop no longer exists", async () => { it("returns null if the current stop no longer exists", async () => {
const orderedStops = await setUpOrderedStopsInRepository(); 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); const response = await getResponseForPreviousStopQuery(orderedStops[1].stopId);
@@ -214,9 +212,8 @@ describe("OrderedStopResolvers", () => {
stopId, stopId,
} }
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
}
}); });
} }
@@ -226,7 +223,7 @@ describe("OrderedStopResolvers", () => {
orderedStops[0].stopId = mockStops[0].id; orderedStops[0].stopId = mockStops[0].id;
// Add one stop only // Add one stop only
await context.repository.addOrUpdateOrderedStop(orderedStops[0]); await context.shuttleRepository.addOrUpdateOrderedStop(orderedStops[0]);
const response = await getResponseForRouteQuery(orderedStops[1].stopId); const response = await getResponseForRouteQuery(orderedStops[1].stopId);
@@ -265,16 +262,15 @@ describe("OrderedStopResolvers", () => {
stopId, stopId,
} }
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
}
}); });
} }
it("returns the associated stop if it exists", async () => { it("returns the associated stop if it exists", async () => {
const orderedStops = await setUpOrderedStopsInRepository(); const orderedStops = await setUpOrderedStopsInRepository();
orderedStops[0].stopId = mockStops[0].id; 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); const response = await getResponseForStopQuery(orderedStops[0].stopId);

View File

@@ -15,7 +15,7 @@ describe("QueryResolvers", () => {
async function addMockSystems() { async function addMockSystems() {
const systems = generateMockSystems(); const systems = generateMockSystems();
await Promise.all(systems.map(async (system) => { await Promise.all(systems.map(async (system) => {
await context.repository.addOrUpdateSystem(system); await context.shuttleRepository.addOrUpdateSystem(system);
})); }));
return systems; return systems;
} }
@@ -36,9 +36,8 @@ describe("QueryResolvers", () => {
const response = await holder.testServer.executeOperation({ const response = await holder.testServer.executeOperation({
query, query,
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
},
}); });
assert(response.body.kind === "single"); assert(response.body.kind === "single");
@@ -68,9 +67,8 @@ describe("QueryResolvers", () => {
id: systemToGet.id, id: systemToGet.id,
} }
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
}
}); });
assert(response.body.kind === "single"); assert(response.body.kind === "single");
@@ -85,9 +83,8 @@ describe("QueryResolvers", () => {
id: "nonexistent-id", id: "nonexistent-id",
} }
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
}
}); });
assert(response.body.kind === "single"); assert(response.body.kind === "single");
@@ -106,8 +103,8 @@ describe("QueryResolvers", () => {
it("returns correct data if the notification is scheduled", async () => { it("returns correct data if the notification is scheduled", async () => {
// Arrange // Arrange
const shuttle = await addMockShuttleToRepository(context.repository, "1"); const shuttle = await addMockShuttleToRepository(context.shuttleRepository, "1");
const stop = await addMockStopToRepository(context.repository, "1") const stop = await addMockStopToRepository(context.shuttleRepository, "1")
const notification: NotificationSchedulingArguments = { const notification: NotificationSchedulingArguments = {
shuttleId: shuttle.id, shuttleId: shuttle.id,

View File

@@ -18,11 +18,11 @@ describe("RouteResolvers", () => {
let mockStop: IStop; let mockStop: IStop;
beforeEach(async () => { beforeEach(async () => {
mockSystem = await addMockSystemToRepository(context.repository); mockSystem = await addMockSystemToRepository(context.shuttleRepository);
const systemId = mockSystem.id; const systemId = mockSystem.id;
mockRoute = await addMockRouteToRepository(context.repository, systemId); mockRoute = await addMockRouteToRepository(context.shuttleRepository, systemId);
mockStop = await addMockStopToRepository(context.repository, systemId); mockStop = await addMockStopToRepository(context.shuttleRepository, systemId);
}); });
@@ -48,9 +48,8 @@ describe("RouteResolvers", () => {
routeId: mockRoute.id, routeId: mockRoute.id,
}, },
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
}
}); });
} }
@@ -59,7 +58,7 @@ describe("RouteResolvers", () => {
const expectedShuttle = expectedShuttles[0]; const expectedShuttle = expectedShuttles[0];
expectedShuttle.systemId = mockSystem.id; expectedShuttle.systemId = mockSystem.id;
expectedShuttle.routeId = mockRoute.id; expectedShuttle.routeId = mockRoute.id;
await context.repository.addOrUpdateShuttle(expectedShuttle); await context.shuttleRepository.addOrUpdateShuttle(expectedShuttle);
const response = await getResponseForShuttlesQuery(); const response = await getResponseForShuttlesQuery();
@@ -104,9 +103,8 @@ describe("RouteResolvers", () => {
stopId: mockStop.id, stopId: mockStop.id,
} }
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
}
}); });
} }
@@ -115,7 +113,7 @@ describe("RouteResolvers", () => {
const expectedOrderedStop = orderedStops[0]; const expectedOrderedStop = orderedStops[0];
expectedOrderedStop.stopId = mockStop.id; expectedOrderedStop.stopId = mockStop.id;
expectedOrderedStop.routeId = mockRoute.id; expectedOrderedStop.routeId = mockRoute.id;
await context.repository.addOrUpdateOrderedStop(expectedOrderedStop); await context.shuttleRepository.addOrUpdateOrderedStop(expectedOrderedStop);
const response = await getResponseForOrderedStopQuery(); const response = await getResponseForOrderedStopQuery();
@@ -132,9 +130,9 @@ describe("RouteResolvers", () => {
const expectedOrderedStop = orderedStops[0]; const expectedOrderedStop = orderedStops[0];
expectedOrderedStop.stopId = mockStop.id; expectedOrderedStop.stopId = mockStop.id;
expectedOrderedStop.routeId = mockRoute.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(); const response = await getResponseForOrderedStopQuery();

View File

@@ -14,8 +14,8 @@ describe("ShuttleResolvers", () => {
let mockShuttle: IShuttle; let mockShuttle: IShuttle;
beforeEach(async () => { beforeEach(async () => {
mockSystem = await addMockSystemToRepository(context.repository); mockSystem = await addMockSystemToRepository(context.shuttleRepository);
mockShuttle = await addMockShuttleToRepository(context.repository, mockShuttle = await addMockShuttleToRepository(context.shuttleRepository,
mockSystem.id); mockSystem.id);
}); });
@@ -24,7 +24,7 @@ describe("ShuttleResolvers", () => {
const etas = generateMockEtas(); const etas = generateMockEtas();
await Promise.all(etas.map(async (eta) => { await Promise.all(etas.map(async (eta) => {
eta.shuttleId = shuttleId; eta.shuttleId = shuttleId;
await context.repository.addOrUpdateEta(eta); await context.shuttleRepository.addOrUpdateEta(eta);
})); }));
return etas; return etas;
} }
@@ -56,9 +56,8 @@ describe("ShuttleResolvers", () => {
stopId: mockEta.stopId, stopId: mockEta.stopId,
}, },
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
},
}); });
// Assert // Assert
@@ -77,9 +76,8 @@ describe("ShuttleResolvers", () => {
stopId: "nonexistent-stop", stopId: "nonexistent-stop",
} }
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
}
}); });
// Assert // Assert
@@ -114,9 +112,8 @@ describe("ShuttleResolvers", () => {
shuttleId: mockShuttle.id, shuttleId: mockShuttle.id,
}, },
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
}
}); });
assert(response.body.kind === "single"); assert(response.body.kind === "single");
@@ -133,9 +130,8 @@ describe("ShuttleResolvers", () => {
shuttleId: mockShuttle.id, shuttleId: mockShuttle.id,
}, },
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
}
}); });
assert(response.body.kind === "single"); assert(response.body.kind === "single");
@@ -172,15 +168,14 @@ describe("ShuttleResolvers", () => {
shuttleId: mockShuttle.id, shuttleId: mockShuttle.id,
} }
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
}
}); });
} }
it("returns the route if it exists", async () => { it("returns the route if it exists", async () => {
const mockRoute = generateMockRoutes()[0]; const mockRoute = generateMockRoutes()[0];
await context.repository.addOrUpdateRoute(mockRoute); await context.shuttleRepository.addOrUpdateRoute(mockRoute);
const response = await getResponseForQuery(); const response = await getResponseForQuery();

View File

@@ -13,8 +13,8 @@ describe("StopResolvers", () => {
let mockSystem: ISystem; let mockSystem: ISystem;
beforeEach(async () => { beforeEach(async () => {
mockSystem = await addMockSystemToRepository(context.repository); mockSystem = await addMockSystemToRepository(context.shuttleRepository);
mockStop = await addMockStopToRepository(context.repository, mockSystem.id); mockStop = await addMockStopToRepository(context.shuttleRepository, mockSystem.id);
}) })
async function getResponseForQuery(query: string) { async function getResponseForQuery(query: string) {
@@ -25,9 +25,7 @@ describe("StopResolvers", () => {
stopId: mockStop.id, stopId: mockStop.id,
}, },
}, { }, {
contextValue: { contextValue: context,
repository: context.repository,
}
}); });
} }
@@ -51,7 +49,7 @@ describe("StopResolvers", () => {
mockOrderedStops = mockOrderedStops.filter((orderedStop) => orderedStop.stopId === mockOrderedStops[0].stopId); mockOrderedStops = mockOrderedStops.filter((orderedStop) => orderedStop.stopId === mockOrderedStops[0].stopId);
await Promise.all(mockOrderedStops.map(async orderedStop => { await Promise.all(mockOrderedStops.map(async orderedStop => {
orderedStop.stopId = mockStop.id; orderedStop.stopId = mockStop.id;
await context.repository.addOrUpdateOrderedStop(orderedStop); await context.shuttleRepository.addOrUpdateOrderedStop(orderedStop);
})); }));
const response = await getResponseForQuery(query); const response = await getResponseForQuery(query);
@@ -88,7 +86,7 @@ describe("StopResolvers", () => {
mockEtas = mockEtas.filter((eta) => eta.stopId === mockEtas[0].stopId); mockEtas = mockEtas.filter((eta) => eta.stopId === mockEtas[0].stopId);
await Promise.all(mockEtas.map(async eta => { await Promise.all(mockEtas.map(async eta => {
eta.stopId = mockStop.id; eta.stopId = mockStop.id;
await context.repository.addOrUpdateEta(eta); await context.shuttleRepository.addOrUpdateEta(eta);
})); }));
const response = await getResponseForQuery(query); const response = await getResponseForQuery(query);

View File

@@ -17,7 +17,7 @@ describe("SystemResolvers", () => {
let mockSystem: ISystem; let mockSystem: ISystem;
beforeEach(async () => { beforeEach(async () => {
mockSystem = await addMockSystemToRepository(context.repository); mockSystem = await addMockSystemToRepository(context.shuttleRepository);
}); });
// TODO: Consolidate these into one single method taking an object // TODO: Consolidate these into one single method taking an object
@@ -29,7 +29,7 @@ describe("SystemResolvers", () => {
}, },
}, { }, {
contextValue: { contextValue: {
repository: context.repository shuttleRepository: context.shuttleRepository
}, },
}); });
} }
@@ -50,7 +50,7 @@ describe("SystemResolvers", () => {
const expectedRoutes = generateMockRoutes(); const expectedRoutes = generateMockRoutes();
await Promise.all(expectedRoutes.map(async (route) => { await Promise.all(expectedRoutes.map(async (route) => {
route.systemId = mockSystem.id; route.systemId = mockSystem.id;
await context.repository.addOrUpdateRoute(route); await context.shuttleRepository.addOrUpdateRoute(route);
})); }));
const response = await getResponseFromQueryNeedingSystemId(query); const response = await getResponseFromQueryNeedingSystemId(query);
@@ -78,7 +78,7 @@ describe("SystemResolvers", () => {
const expectedStops = generateMockStops(); const expectedStops = generateMockStops();
await Promise.all(expectedStops.map(async (stop) => { await Promise.all(expectedStops.map(async (stop) => {
stop.systemId = mockSystem.id; stop.systemId = mockSystem.id;
await context.repository.addOrUpdateStop(stop); await context.shuttleRepository.addOrUpdateStop(stop);
})); }));
const response = await getResponseFromQueryNeedingSystemId(query); const response = await getResponseFromQueryNeedingSystemId(query);
@@ -111,13 +111,13 @@ describe("SystemResolvers", () => {
}, },
}, { }, {
contextValue: { contextValue: {
repository: context.repository, shuttleRepository: context.shuttleRepository,
} }
}); });
} }
it("gets the stop with the correct id", async () => { 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); const response = await getResponseForStopQuery(mockStop.id);
@@ -133,9 +133,9 @@ describe("SystemResolvers", () => {
...mockSystem, ...mockSystem,
id: "2", 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); const response = await getResponseForStopQuery(mockStop.id);
@@ -177,14 +177,12 @@ describe("SystemResolvers", () => {
routeId, routeId,
}, },
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
}
}); });
} }
it("gets the route with the correct id", async () => { 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); const response = await getResponseForRouteQuery(mockRoute.id);
@@ -201,9 +199,9 @@ describe("SystemResolvers", () => {
...mockSystem, ...mockSystem,
id: "2", 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); const response = await getResponseForRouteQuery(mockRoute.id);
@@ -245,14 +243,13 @@ describe("SystemResolvers", () => {
shuttleId: shuttleId, shuttleId: shuttleId,
} }
}, { }, {
contextValue: { contextValue: context
repository: context.repository,
}
}); });
} }
it("gets the shuttle with the correct id", async () => { 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); const response = await getResponseForShuttleQuery(mockShuttle.id);
@@ -268,9 +265,9 @@ describe("SystemResolvers", () => {
...mockSystem, ...mockSystem,
id: "2", 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); const response = await getResponseForShuttleQuery(mockShuttle.id);
@@ -308,7 +305,7 @@ describe("SystemResolvers", () => {
const expectedShuttles = generateMockShuttles(); const expectedShuttles = generateMockShuttles();
await Promise.all(expectedShuttles.map(async (shuttle) => { await Promise.all(expectedShuttles.map(async (shuttle) => {
shuttle.systemId = mockSystem.id; shuttle.systemId = mockSystem.id;
await context.repository.addOrUpdateShuttle(shuttle); await context.shuttleRepository.addOrUpdateShuttle(shuttle);
})); }));
const response = await getResponseFromQueryNeedingSystemId(query); const response = await getResponseFromQueryNeedingSystemId(query);

View File

@@ -25,7 +25,7 @@ export function setupTestServerContext() {
const context: { [key: string] : any } = {}; const context: { [key: string] : any } = {};
beforeEach(() => { beforeEach(() => {
context.repository = new UnoptimizedInMemoryShuttleRepository(); context.shuttleRepository = new UnoptimizedInMemoryShuttleRepository();
context.notificationService = new ETANotificationScheduler(context.repository); context.notificationService = new ETANotificationScheduler(context.repository);
}); });