mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add test cases and implementations for system getters
This commit is contained in:
61
test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts
Normal file
61
test/repositories/UnoptimizedInMemoryRepositoryTests.test.ts
Normal 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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user