From 8d81ab1449c35ef31e8aefdf2bddc2381e287fd9 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 22 Jan 2025 19:50:04 -0800 Subject: [PATCH] add tests for systems and routes --- ...UnoptimizedInMemoryRepositoryTests.test.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts b/test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts index 8d5dcb7..531cd00 100644 --- a/test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts +++ b/test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts @@ -431,21 +431,59 @@ describe("UnoptimizedInMemoryRepository", () => { describe("removeSystem", () => { test("removes system given ID", async () => { + const mockSystems = generateMockSystems(); + await Promise.all(mockSystems.map(async (system) => { + await repository.addOrUpdateSystem(system); + })); + const systemToRemove = mockSystems[0]; + await repository.removeSystemIfExists(systemToRemove.id); + + const remainingSystems = await repository.getSystems(); + expect(remainingSystems).toHaveLength(mockSystems.length - 1); }); test("does nothing if system doesn't exist", async () => { + const mockSystems = generateMockSystems(); + await Promise.all(mockSystems.map(async (system) => { + await repository.addOrUpdateSystem(system); + })); + await repository.removeSystemIfExists("nonexistent-id"); + + const remainingSystems = await repository.getSystems(); + expect(remainingSystems).toHaveLength(mockSystems.length); }); }); describe("removeRoute", () => { test("removes route given ID", async () => { + const systemId = "1"; + const mockRoutes = generateMockRoutes(); + await Promise.all(mockRoutes.map(async (route) => { + route.systemId = systemId; + await repository.addOrUpdateRoute(route); + })); + const routeToRemove = mockRoutes[0]; + await repository.removeRouteIfExists(routeToRemove.id); + + const remainingRoutes = await repository.getRoutesBySystemId(systemId); + expect(remainingRoutes).toHaveLength(mockRoutes.length - 1); }); test("does nothing if route doesn't exist", async () => { + const systemId = "1"; + const mockRoutes = generateMockRoutes(); + await Promise.all(mockRoutes.map(async (route) => { + route.systemId = systemId; + await repository.addOrUpdateRoute(route); + })); + await repository.removeRouteIfExists("nonexistent-id"); + + const remainingRoutes = await repository.getRoutesBySystemId(systemId); + expect(remainingRoutes).toHaveLength(mockRoutes.length); }); });