diff --git a/test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts b/test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts index 531cd00..a3f2f7e 100644 --- a/test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts +++ b/test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts @@ -429,7 +429,7 @@ describe("UnoptimizedInMemoryRepository", () => { }); }); - describe("removeSystem", () => { + describe("removeSystemIfExists", () => { test("removes system given ID", async () => { const mockSystems = generateMockSystems(); await Promise.all(mockSystems.map(async (system) => { @@ -456,7 +456,7 @@ describe("UnoptimizedInMemoryRepository", () => { }); }); - describe("removeRoute", () => { + describe("removeRouteIfExists", () => { test("removes route given ID", async () => { const systemId = "1"; const mockRoutes = generateMockRoutes(); @@ -487,27 +487,69 @@ describe("UnoptimizedInMemoryRepository", () => { }); }); - describe("removeShuttle", () => { + describe("removeShuttleIfExists", () => { test("removes shuttle given ID", async () => { + const systemId = "1"; + const mockShuttles = generateMockShuttles(); + await Promise.all(mockShuttles.map(async (shuttle) => { + shuttle.systemId = systemId; + await repository.addOrUpdateShuttle(shuttle); + })); + const shuttleToRemove = mockShuttles[0]; + await repository.removeShuttleIfExists(shuttleToRemove.id); + + const remainingShuttles = await repository.getShuttlesBySystemId(systemId); + expect(remainingShuttles).toHaveLength(mockShuttles.length - 1); }); test("does nothing if shuttle doesn't exist", async () => { + const systemId = "1"; + const mockShuttles = generateMockShuttles(); + await Promise.all(mockShuttles.map(async (shuttle) => { + shuttle.systemId = systemId; + await repository.addOrUpdateShuttle(shuttle); + })); + await repository.removeShuttleIfExists("nonexistent-id"); + + const remainingShuttles = await repository.getShuttlesBySystemId(systemId); + expect(remainingShuttles).toHaveLength(mockShuttles.length); }); }); - describe("removeStop", () => { + describe("removeStopIfExists", () => { test("removes stop given ID", async () => { + const systemId = "1"; + const mockStops = generateMockStops(); + await Promise.all(mockStops.map(async (stop) => { + stop.systemId = systemId; + await repository.addOrUpdateStop(stop); + })); + const stopToRemove = mockStops[0]; + await repository.removeStopIfExists(stopToRemove.id); + + const remainingStops = await repository.getStopsBySystemId(systemId); + expect(remainingStops).toHaveLength(mockStops.length - 1); }); test("does nothing if stop doesn't exist", async () => { + const systemId = "1"; + const mockStops = generateMockStops(); + await Promise.all(mockStops.map(async (stop) => { + stop.systemId = systemId; + await repository.addOrUpdateStop(stop); + })); + await repository.removeStopIfExists("nonexistent-id"); + + const remainingStops = await repository.getStopsBySystemId(systemId); + expect(remainingStops).toHaveLength(mockStops.length); }); }); - describe("removeOrderedStop", () => { + describe("removeOrderedStopIfExists", () => { test("removes ordered stop given stop ID and route ID", async () => { }); @@ -517,7 +559,7 @@ describe("UnoptimizedInMemoryRepository", () => { }); }); - describe("removeEta", () => { + describe("removeEtaIfExists", () => { test("removes eta given shuttle ID and stop ID", async () => { });