diff --git a/test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts b/test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts index aa92546..0f0a804 100644 --- a/test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts +++ b/test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts @@ -7,7 +7,7 @@ import { UnoptimizedInMemoryRepository } from "../../src/repositories/Unoptimize // or GetterSetterRepository instance // Full disclosure: most of this was generated by ChatGPT -// https://chatgpt.com/share/67901f14-c4ac-800d-8bcd-d2e622c522bf +// https://chatgpt.com/share/67902072-3adc-800d-bd22-06f7b3e6f4a4 describe("UnoptimizedInMemoryRepository", () => { let repository: UnoptimizedInMemoryRepository; @@ -81,6 +81,98 @@ describe("UnoptimizedInMemoryRepository", () => { }); }); + describe("getStopById", () => { + test("gets a stop by ID if it exists", async () => { + const mockStop = { id: "st1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } }; + await repository.addOrUpdateStop(mockStop); + + const result = await repository.getStopById("st1"); + expect(result).toEqual(mockStop); + }); + + test("returns null if the stop does not exist", async () => { + const result = await repository.getStopById("nonexistent-stop"); + expect(result).toBeNull(); + }); + }); + + describe("getRoutesBySystemId", () => { + test("gets all routes for a specific system ID", async () => { + const mockRoutes = [ + { id: "r1", name: "Route 1", color: "red", systemId: "sys1", polylineCoordinates: [] }, + { id: "r2", name: "Route 2", color: "blue", systemId: "sys1", polylineCoordinates: [] }, + { id: "r3", name: "Route 3", color: "green", systemId: "sys2", polylineCoordinates: [] }, + ]; + for (const route of mockRoutes) { + await repository.addOrUpdateRoute(route); + } + + const result = await repository.getRoutesBySystemId("sys1"); + expect(result).toEqual(mockRoutes.filter((route) => route.systemId === "sys1")); + }); + + test("returns an empty list if there are no routes for the system ID", async () => { + const result = await repository.getRoutesBySystemId("nonexistent-system"); + expect(result).toEqual([]); + }); + }); + + describe("getRouteById", () => { + test("gets a route by ID if it exists", async () => { + const mockRoute = { id: "r1", name: "Route 1", color: "red", systemId: "sys1", polylineCoordinates: [] }; + await repository.addOrUpdateRoute(mockRoute); + + const result = await repository.getRouteById("r1"); + expect(result).toEqual(mockRoute); + }); + + test("returns null if the route does not exist", async () => { + const result = await repository.getRouteById("nonexistent-route"); + expect(result).toBeNull(); + }); + }); + describe("getShuttlesBySystemId", () => { + test("gets all shuttles for a specific system ID", async () => { + const mockShuttles = [ + { id: "sh1", name: "Shuttle A", routeId: "r1", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } }, + { id: "sh2", name: "Shuttle B", routeId: "r2", systemId: "sys1", coordinates: { latitude: 15, longitude: 25 } }, + { id: "sh3", name: "Shuttle C", routeId: "r3", systemId: "sys2", coordinates: { latitude: 30, longitude: 40 } }, + ]; + for (const shuttle of mockShuttles) { + await repository.addOrUpdateShuttle(shuttle); + } + + const result = await repository.getShuttlesBySystemId("sys1"); + expect(result).toEqual(mockShuttles.filter((sh) => sh.systemId === "sys1")); + }); + + test("returns an empty list if there are no shuttles for the system ID", async () => { + const result = await repository.getShuttlesBySystemId("nonexistent-system"); + expect(result).toEqual([]); + }); + }); + + describe("getShuttlesByRouteId", () => { + test("gets all shuttles for a specific route ID", async () => { + const mockShuttles = [ + { id: "sh1", name: "Shuttle A", routeId: "r1", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } }, + { id: "sh2", name: "Shuttle B", routeId: "r1", systemId: "sys1", coordinates: { latitude: 15, longitude: 25 } }, + { id: "sh3", name: "Shuttle C", routeId: "r2", systemId: "sys2", coordinates: { latitude: 30, longitude: 40 } }, + ]; + for (const shuttle of mockShuttles) { + await repository.addOrUpdateShuttle(shuttle); + } + + const result = await repository.getShuttlesByRouteId("r1"); + expect(result).toEqual(mockShuttles.filter((sh) => sh.routeId === "r1")); + }); + + test("returns an empty list if there are no shuttles for the route ID", async () => { + const result = await repository.getShuttlesByRouteId("nonexistent-route"); + expect(result).toEqual([]); + }); + }); + describe("getShuttleById", () => { test("gets a shuttle by ID if it exists", async () => { const mockShuttles = [ @@ -101,6 +193,27 @@ describe("UnoptimizedInMemoryRepository", () => { }); }); + describe("getEtasForShuttleId", () => { + test("gets ETAs for a specific shuttle ID", async () => { + const mockEtas = [ + { shuttleId: "sh1", stopId: "st1", secondsRemaining: 120 }, + { shuttleId: "sh1", stopId: "st2", secondsRemaining: 180 }, + { shuttleId: "sh2", stopId: "st3", secondsRemaining: 240 }, + ]; + for (const eta of mockEtas) { + await repository.addOrUpdateEta(eta); + } + + const result = await repository.getEtasForShuttleId("sh1"); + expect(result).toEqual(mockEtas.filter((eta) => eta.shuttleId === "sh1")); + }); + + test("returns an empty list if there are no ETAs for the shuttle ID", async () => { + const result = await repository.getEtasForShuttleId("nonexistent-shuttle"); + expect(result).toEqual([]); + }); + }); + describe("getEtasForStopId", () => { test("gets ETAs for a specific stop ID", async () => { const mockEtas = [ @@ -122,6 +235,21 @@ describe("UnoptimizedInMemoryRepository", () => { }); }); + describe("getEtaForShuttleAndStopId", () => { + test("gets a single ETA for a specific shuttle and stop ID", async () => { + const mockEta = { shuttleId: "sh1", stopId: "st1", secondsRemaining: 120 }; + await repository.addOrUpdateEta(mockEta); + + const result = await repository.getEtaForShuttleAndStopId("sh1", "st1"); + expect(result).toEqual(mockEta); + }); + + test("returns null if no ETA matches the shuttle and stop ID", async () => { + const result = await repository.getEtaForShuttleAndStopId("nonexistent-shuttle", "nonexistent-stop"); + expect(result).toBeNull(); + }); + }); + describe("getOrderedStopByRouteAndStopId", () => { test("gets an ordered stop by route ID and stop ID", async () => { const mockOrderedStop = { @@ -140,4 +268,46 @@ describe("UnoptimizedInMemoryRepository", () => { expect(result).toBeNull(); }); }); + + describe("getOrderedStopsByStopId", () => { + test("gets all ordered stops for a specific stop ID", async () => { + const mockOrderedStops = [ + { stopId: "st1", routeId: "r1", position: 1 }, + { stopId: "st1", routeId: "r2", position: 2 }, + { stopId: "st2", routeId: "r3", position: 3 }, + ]; + for (const orderedStop of mockOrderedStops) { + await repository.addOrUpdateOrderedStop(orderedStop); + } + + const result = await repository.getOrderedStopsByStopId("st1"); + expect(result).toEqual(mockOrderedStops.filter((os) => os.stopId === "st1")); + }); + + test("returns an empty list if there are no ordered stops for the stop ID", async () => { + const result = await repository.getOrderedStopsByStopId("nonexistent-stop"); + expect(result).toEqual([]); + }); + }); + + describe("getOrderedStopsByRouteId", () => { + test("gets all ordered stops for a specific route ID", async () => { + const mockOrderedStops = [ + { stopId: "st1", routeId: "r1", position: 1 }, + { stopId: "st2", routeId: "r1", position: 2 }, + { stopId: "st3", routeId: "r2", position: 3 }, + ]; + for (const orderedStop of mockOrderedStops) { + await repository.addOrUpdateOrderedStop(orderedStop); + } + + const result = await repository.getOrderedStopsByRouteId("r1"); + expect(result).toEqual(mockOrderedStops.filter((os) => os.routeId === "r1")); + }); + + test("returns an empty list if there are no ordered stops for the route ID", async () => { + const result = await repository.getOrderedStopsByRouteId("nonexistent-route"); + expect(result).toEqual([]); + }); + }); }); \ No newline at end of file