mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add tests for systems and routes
This commit is contained in:
@@ -431,21 +431,59 @@ describe("UnoptimizedInMemoryRepository", () => {
|
|||||||
|
|
||||||
describe("removeSystem", () => {
|
describe("removeSystem", () => {
|
||||||
test("removes system given ID", async () => {
|
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 () => {
|
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", () => {
|
describe("removeRoute", () => {
|
||||||
test("removes route given ID", async () => {
|
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 () => {
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user