mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
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();
|
|
});
|
|
});
|
|
|
|
|
|
}); |