add test cases and implementations for system getters

This commit is contained in:
2025-01-21 14:25:05 -08:00
parent 52d1ae2b86
commit 70717d6476

View File

@@ -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();
});
});
});