diff --git a/test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts b/test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts new file mode 100644 index 0000000..6a7a50f --- /dev/null +++ b/test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts @@ -0,0 +1,61 @@ +import { beforeEach, describe, expect, test } from "@jest/globals"; +import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository"; + +// For repositories created in the future, reuse core testing +// logic from here and differentiate setup (e.g. creating mocks) +// Do this by creating a function which takes a GetterRepository +// or GetterSetterRepository instance + +describe("UnoptimizedInMemoryRepository", () => { + let repository: UnoptimizedInMemoryRepository; + + beforeEach(() => { + repository = new UnoptimizedInMemoryRepository(); + }); + + describe("getSystems", () => { + test("gets the systems stored in the repository", async () => { + const mockSystems = [ + { id: "1", name: "System A" }, + { id: "2", name: "System B" }, + ]; + await repository.addOrUpdateSystem(mockSystems[0]); + await repository.addOrUpdateSystem(mockSystems[1]); + + const result = await repository.getSystems(); + + expect(result).toEqual(mockSystems); + }); + + test("gets an empty list if there are no systems stored", async () => { + const result = await repository.getSystems(); + + expect(result).toEqual([]); + }); + }); + + describe("getSystemById", () => { + test("gets a system by the ID if it exists", async () => { + const mockSystems = [ + { id: "1", name: "System A" }, + { id: "2", name: "System B" }, + { id: "3", name: "System C" }, + ]; + for (const system of mockSystems) { + await repository.addOrUpdateSystem(system); + } + + const result = await repository.getSystemById("2"); + + expect(result).toEqual(mockSystems[1]); // Ensure it retrieves the correct system + }); + + test("returns null if the system doesn't exist", async () => { + const result = await repository.getSystemById("nonexistent-id"); + + expect(result).toBeNull(); + }); + }); + + +}); \ No newline at end of file