mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
update remove implementation and tests
This commit is contained in:
@@ -21,7 +21,7 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
repository = new UnoptimizedInMemoryShuttleRepository();
|
||||
});
|
||||
|
||||
describe("getSystems", () => {
|
||||
describe("getSystem", () => {
|
||||
test("gets the system stored in the repository", async () => {
|
||||
const mockSystems = generateMockSystems();
|
||||
await repository.updateSystem(mockSystems[0]);
|
||||
@@ -38,25 +38,6 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("getSystemById", () => {
|
||||
test("gets a system by the ID if it exists", async () => {
|
||||
const mockSystems = generateMockSystems();
|
||||
for (const system of mockSystems) {
|
||||
await repository.updateSystem(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();
|
||||
});
|
||||
});
|
||||
|
||||
describe("getStopsBySystemId", () => {
|
||||
test("gets stops by system ID", async () => {
|
||||
const mockStops = generateMockStops();
|
||||
@@ -475,27 +456,19 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
describe("removeSystemIfExists", () => {
|
||||
test("removes system given ID", async () => {
|
||||
const mockSystems = generateMockSystems();
|
||||
await Promise.all(mockSystems.map(async (system) => {
|
||||
await repository.updateSystem(system);
|
||||
}));
|
||||
await repository.updateSystem(mockSystems[0]);
|
||||
|
||||
const systemToRemove = mockSystems[0];
|
||||
await repository.removeSystemIfExists(systemToRemove.id);
|
||||
await repository.removeSystemIfExists();
|
||||
|
||||
const remainingSystems = await repository.getSystemIfExists();
|
||||
expect(remainingSystems).toHaveLength(mockSystems.length - 1);
|
||||
const expectedSystem = await repository.getSystemIfExists();
|
||||
expect(expectedSystem).toBeNull();
|
||||
});
|
||||
|
||||
test("does nothing if system doesn't exist", async () => {
|
||||
const mockSystems = generateMockSystems();
|
||||
await Promise.all(mockSystems.map(async (system) => {
|
||||
await repository.updateSystem(system);
|
||||
}));
|
||||
await repository.removeSystemIfExists();
|
||||
|
||||
await repository.removeSystemIfExists("nonexistent-id");
|
||||
|
||||
const remainingSystems = await repository.getSystemIfExists();
|
||||
expect(remainingSystems).toHaveLength(mockSystems.length);
|
||||
const expectedSystem = await repository.getSystemIfExists();
|
||||
expect(expectedSystem).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user