add remaining test cases

This commit is contained in:
2025-01-22 20:02:53 -08:00
parent 3a5116ae0c
commit fbb57cbf8e

View File

@@ -551,21 +551,63 @@ describe("UnoptimizedInMemoryRepository", () => {
describe("removeOrderedStopIfExists", () => { describe("removeOrderedStopIfExists", () => {
test("removes ordered stop given stop ID and route ID", async () => { test("removes ordered stop given stop ID and route ID", async () => {
const routeId = "1";
const mockOrderedStops = generateMockOrderedStops();
await Promise.all(mockOrderedStops.map(async (stop) => {
stop.routeId = routeId;
await repository.addOrUpdateOrderedStop(stop);
}));
const orderedStopToRemove = mockOrderedStops[0];
await repository.removeOrderedStopIfExists(orderedStopToRemove.stopId, orderedStopToRemove.routeId);
const remainingOrderedStops = await repository.getOrderedStopsByRouteId(routeId);
expect(remainingOrderedStops).toHaveLength(mockOrderedStops.length - 1);
}); });
test("does nothing if ordered stop doesn't exist", async () => { test("does nothing if ordered stop doesn't exist", async () => {
const routeId = "1";
const mockOrderedStops = generateMockOrderedStops();
await Promise.all(mockOrderedStops.map(async (stop) => {
stop.routeId = routeId;
await repository.addOrUpdateOrderedStop(stop);
}));
await repository.removeOrderedStopIfExists("nonexistent-stop-id", "nonexistent-route-id");
const remainingOrderedStops = await repository.getOrderedStopsByRouteId(routeId);
expect(remainingOrderedStops).toHaveLength(mockOrderedStops.length);
}); });
}); });
describe("removeEtaIfExists", () => { describe("removeEtaIfExists", () => {
test("removes eta given shuttle ID and stop ID", async () => { test("removes eta given shuttle ID and stop ID", async () => {
const stopId = "1";
const mockEtas = generateMockEtas();
await Promise.all(mockEtas.map(async (eta) => {
eta.stopId = stopId;
await repository.addOrUpdateEta(eta);
}));
const etaToRemove = mockEtas[0];
await repository.removeEtaIfExists(etaToRemove.shuttleId, etaToRemove.stopId);
const remainingEtas = await repository.getEtasForStopId(stopId);
expect(remainingEtas).toHaveLength(mockEtas.length - 1);
}); });
test("does nothing if eta doesn't exist", async () => { test("does nothing if eta doesn't exist", async () => {
const stopId = "1";
const mockEtas = generateMockEtas();
await Promise.all(mockEtas.map(async (eta) => {
eta.stopId = stopId;
await repository.addOrUpdateEta(eta);
}));
await repository.removeEtaIfExists("nonexistent-shuttle-id", "nonexistent-stop-id");
const remainingEtas = await repository.getEtasForStopId(stopId);
expect(remainingEtas).toHaveLength(mockEtas.length);
}); });
}); });