From 6d762ce62081e2166fc4b219998f2ce890b55890 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Sun, 6 Apr 2025 10:49:47 -0700 Subject: [PATCH] remove all system related data from shuttle repository --- .../UnoptimizedInMemoryShuttleRepository.ts | 25 +------- ...izedInMemoryShuttleRepositoryTests.test.ts | 62 ------------------- 2 files changed, 1 insertion(+), 86 deletions(-) diff --git a/src/repositories/UnoptimizedInMemoryShuttleRepository.ts b/src/repositories/UnoptimizedInMemoryShuttleRepository.ts index 9060662..6d613f2 100644 --- a/src/repositories/UnoptimizedInMemoryShuttleRepository.ts +++ b/src/repositories/UnoptimizedInMemoryShuttleRepository.ts @@ -1,5 +1,5 @@ import { ShuttleGetterSetterRepository } from "./ShuttleGetterSetterRepository"; -import { IEntityWithId, IEta, IOrderedStop, IRoute, IShuttle, IStop, ISystem } from "../entities/entities"; +import { IEntityWithId, IEta, IOrderedStop, IRoute, IShuttle, IStop } from "../entities/entities"; /** * An unoptimized in memory repository. @@ -7,7 +7,6 @@ import { IEntityWithId, IEta, IOrderedStop, IRoute, IShuttle, IStop, ISystem } f * switching to another data store later anyways) */ export class UnoptimizedInMemoryShuttleRepository implements ShuttleGetterSetterRepository { - private system: ISystem | null = null; private stops: IStop[] = []; private routes: IRoute[] = []; private shuttles: IShuttle[] = []; @@ -16,10 +15,6 @@ export class UnoptimizedInMemoryShuttleRepository implements ShuttleGetterSetter private subscribers: ((eta: IEta) => void)[] = []; - public async getSystemIfExists() { - return this.system; - } - public async getStopsBySystemId(systemId: string) { return this.stops.filter(stop => stop.systemId === systemId); } @@ -95,10 +90,6 @@ export class UnoptimizedInMemoryShuttleRepository implements ShuttleGetterSetter return entity; } - public async updateSystem(system: ISystem): Promise { - this.system = system; - } - public async addOrUpdateRoute(route: IRoute): Promise { const index = this.routes.findIndex((r) => r.id === route.id); if (index !== -1) { @@ -166,16 +157,6 @@ export class UnoptimizedInMemoryShuttleRepository implements ShuttleGetterSetter return await this.removeEntityByMatcherIfExists((value) => value.id === entityId, arrayToSearchIn); } - public async removeSystemIfExists(): Promise { - if (this.system !== null) { - const system = this.system; - this.system = null; - return system; - } - - return null; - } - public async removeRouteIfExists(routeId: string): Promise { return await this.removeEntityByIdIfExists(routeId, this.routes); } @@ -202,10 +183,6 @@ export class UnoptimizedInMemoryShuttleRepository implements ShuttleGetterSetter }, this.etas); } - public async clearSystemData() { - this.system = null; - } - public async clearShuttleData(): Promise { this.shuttles = []; } diff --git a/test/repositories/UnoptimizedInMemoryShuttleRepositoryTests.test.ts b/test/repositories/UnoptimizedInMemoryShuttleRepositoryTests.test.ts index 030e423..4cb2419 100644 --- a/test/repositories/UnoptimizedInMemoryShuttleRepositoryTests.test.ts +++ b/test/repositories/UnoptimizedInMemoryShuttleRepositoryTests.test.ts @@ -6,7 +6,6 @@ import { generateMockRoutes, generateMockShuttles, generateMockStops, - generateMockSystems } from "../testHelpers/mockDataGenerators"; // For repositories created in the future, reuse core testing @@ -21,23 +20,6 @@ describe("UnoptimizedInMemoryRepository", () => { repository = new UnoptimizedInMemoryShuttleRepository(); }); - describe("getSystem", () => { - test("gets the system stored in the repository", async () => { - const mockSystems = generateMockSystems(); - await repository.updateSystem(mockSystems[0]); - - const result = await repository.getSystemIfExists(); - - expect(result).toEqual(mockSystems[0]); - }); - - test("gets null if there is no data associated with the system", async () => { - const result = await repository.getSystemIfExists(); - - expect(result).toEqual(null); - }); - }); - describe("getStopsBySystemId", () => { test("gets stops by system ID", async () => { const mockStops = generateMockStops(); @@ -303,18 +285,6 @@ describe("UnoptimizedInMemoryRepository", () => { }); }); - describe("updateSystem", () => { - test("adds a new system", async () => { - const mockSystems = generateMockSystems(); - const newSystem = mockSystems[0]; - - await repository.updateSystem(newSystem); - - const result = await repository.getSystemIfExists(); - expect(result).toEqual(newSystem); - }); - }); - describe("addOrUpdateRoute", () => { test("adds a new route if nonexistent", async () => { const mockRoutes = generateMockRoutes(); @@ -440,25 +410,6 @@ describe("UnoptimizedInMemoryRepository", () => { }); }); - describe("removeSystemIfExists", () => { - test("removes system given ID", async () => { - const mockSystems = generateMockSystems(); - await repository.updateSystem(mockSystems[0]); - - await repository.removeSystemIfExists(); - - const expectedSystem = await repository.getSystemIfExists(); - expect(expectedSystem).toBeNull(); - }); - - test("does nothing if system doesn't exist", async () => { - await repository.removeSystemIfExists(); - - const expectedSystem = await repository.getSystemIfExists(); - expect(expectedSystem).toBeNull(); - }); - }); - describe("removeRouteIfExists", () => { test("removes route given ID", async () => { const systemId = "1"; @@ -620,19 +571,6 @@ describe("UnoptimizedInMemoryRepository", () => { }); }); - describe("clearSystemData", () => { - test("clears system data when the repository has data", async () => { - const mockSystems = generateMockSystems(); - const system = mockSystems[0]; - await repository.updateSystem(system); - - await repository.clearSystemData(); - - const result = await repository.getSystemIfExists(); - expect(result).toEqual(null); - }); - }); - describe("clearShuttleData", () => { test("clears all shuttles from the repository", async () => { const mockShuttles = generateMockShuttles();