add rest of tests (mostly generated)

This commit is contained in:
2025-01-21 14:27:18 -08:00
parent 70717d6476
commit 0d9d935a9e

View File

@@ -6,6 +6,9 @@ import { UnoptimizedInMemoryRepository } from "../../src/repositories/Unoptimize
// Do this by creating a function which takes a GetterRepository
// or GetterSetterRepository instance
// Full disclosure: most of this was generated by ChatGPT
// https://chatgpt.com/share/67901f14-c4ac-800d-8bcd-d2e622c522bf
describe("UnoptimizedInMemoryRepository", () => {
let repository: UnoptimizedInMemoryRepository;
@@ -57,5 +60,84 @@ describe("UnoptimizedInMemoryRepository", () => {
});
});
describe("getStopsBySystemId", () => {
test("gets stops by system ID", async () => {
const mockStops = [
{ id: "1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } },
{ id: "2", name: "Stop B", systemId: "sys1", coordinates: { latitude: 15, longitude: 25 } },
{ id: "3", name: "Stop C", systemId: "sys2", coordinates: { latitude: 30, longitude: 40 } },
];
for (const stop of mockStops) {
await repository.addOrUpdateStop(stop);
}
const result = await repository.getStopsBySystemId("sys1");
expect(result).toEqual(mockStops.filter((stop) => stop.systemId === "sys1"));
});
test("returns an empty list if there are no stops for the given system ID", async () => {
const result = await repository.getStopsBySystemId("nonexistent-system");
expect(result).toEqual([]);
});
});
describe("getShuttleById", () => {
test("gets a shuttle by ID if it exists", async () => {
const mockShuttles = [
{ id: "1", name: "Shuttle A", routeId: "r1", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } },
{ id: "2", name: "Shuttle B", routeId: "r2", systemId: "sys1", coordinates: { latitude: 15, longitude: 25 } },
];
for (const shuttle of mockShuttles) {
await repository.addOrUpdateShuttle(shuttle);
}
const result = await repository.getShuttleById("2");
expect(result).toEqual(mockShuttles[1]);
});
test("returns null if the shuttle doesn't exist", async () => {
const result = await repository.getShuttleById("nonexistent-id");
expect(result).toBeNull();
});
});
describe("getEtasForStopId", () => {
test("gets ETAs for a specific stop ID", async () => {
const mockEtas = [
{ shuttleId: "s1", stopId: "st1", secondsRemaining: 120 },
{ shuttleId: "s2", stopId: "st1", secondsRemaining: 180 },
{ shuttleId: "s3", stopId: "st2", secondsRemaining: 240 },
];
for (const eta of mockEtas) {
await repository.addOrUpdateEta(eta);
}
const result = await repository.getEtasForStopId("st1");
expect(result).toEqual(mockEtas.filter((eta) => eta.stopId === "st1"));
});
test("returns an empty list if there are no ETAs for the stop ID", async () => {
const result = await repository.getEtasForStopId("nonexistent-stop");
expect(result).toEqual([]);
});
});
describe("getOrderedStopByRouteAndStopId", () => {
test("gets an ordered stop by route ID and stop ID", async () => {
const mockOrderedStop = {
routeId: "r1",
stopId: "st1",
position: 1,
};
await repository.addOrUpdateOrderedStop(mockOrderedStop);
const result = await repository.getOrderedStopByRouteAndStopId("r1", "st1");
expect(result).toEqual(mockOrderedStop);
});
test("returns null if no ordered stop matches the given route ID and stop ID", async () => {
const result = await repository.getOrderedStopByRouteAndStopId("nonexistent-route", "nonexistent-stop");
expect(result).toBeNull();
});
});
});