From 99999450b50aae98aa76fc79ce8e29609fb39604 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 11 Nov 2025 14:50:53 -0800 Subject: [PATCH] Remove clearAllData from BaseRedisRepository and update tests --- src/repositories/BaseRedisRepository.ts | 4 ---- .../NotificationRepositorySharedTests.test.ts | 15 ++++++++----- .../ParkingRepositorySharedTests.test.ts | 15 ++++++++----- .../shuttle/RedisShuttleRepository.ts | 3 --- .../ShuttleRepositorySharedTests.test.ts | 15 ++++++++----- .../eta/ExternalSourceETARepository.ts | 2 -- .../eta/RedisExternalSourceETARepository.ts | 3 --- ...rnalSourceETARepositorySharedTests.test.ts | 15 ++++++++----- ...lfUpdatingETARepositorySharedTests.test.ts | 21 ++++++++++--------- 9 files changed, 51 insertions(+), 42 deletions(-) diff --git a/src/repositories/BaseRedisRepository.ts b/src/repositories/BaseRedisRepository.ts index 70c2b1f..f722586 100644 --- a/src/repositories/BaseRedisRepository.ts +++ b/src/repositories/BaseRedisRepository.ts @@ -33,8 +33,4 @@ export abstract class BaseRedisRepository extends EventEmitter { public async disconnect() { await this.redisClient.disconnect(); } - - public async clearAllData() { - await this.redisClient.flushAll(); - } } diff --git a/src/repositories/notifications/__tests__/NotificationRepositorySharedTests.test.ts b/src/repositories/notifications/__tests__/NotificationRepositorySharedTests.test.ts index daf9944..86ccf07 100644 --- a/src/repositories/notifications/__tests__/NotificationRepositorySharedTests.test.ts +++ b/src/repositories/notifications/__tests__/NotificationRepositorySharedTests.test.ts @@ -1,4 +1,5 @@ import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals"; +import { createClient, RedisClientType } from "redis"; import { InMemoryNotificationRepository } from "../InMemoryNotificationRepository"; import { NotificationEvent, NotificationRepository } from "../NotificationRepository"; import { RedisNotificationRepository } from "../RedisNotificationRepository"; @@ -19,17 +20,21 @@ class InMemoryRepositoryHolder implements RepositoryHolder { class RedisNotificationRepositoryHolder implements RepositoryHolder { repo: RedisNotificationRepository | undefined; + redisClient: RedisClientType | undefined; name = 'RedisNotificationRepository'; factory = async () => { - this.repo = new RedisNotificationRepository(); - await this.repo.connect(); + this.redisClient = createClient({ + url: process.env.REDIS_URL, + }); + await this.redisClient.connect(); + this.repo = new RedisNotificationRepository(this.redisClient); return this.repo; } teardown = async () => { - if (this.repo) { - await this.repo.clearAllData(); - await this.repo.disconnect(); + if (this.redisClient) { + await this.redisClient.flushAll(); + await this.redisClient.disconnect(); } } } diff --git a/src/repositories/parking/__tests__/ParkingRepositorySharedTests.test.ts b/src/repositories/parking/__tests__/ParkingRepositorySharedTests.test.ts index 426ab9d..d9b4162 100644 --- a/src/repositories/parking/__tests__/ParkingRepositorySharedTests.test.ts +++ b/src/repositories/parking/__tests__/ParkingRepositorySharedTests.test.ts @@ -1,4 +1,5 @@ import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals"; +import { createClient, RedisClientType } from "redis"; import { InMemoryParkingRepository, } from "../InMemoryParkingRepository"; import { IParkingStructure } from "../../../entities/ParkingRepositoryEntities"; import { ParkingGetterSetterRepository } from "../ParkingGetterSetterRepository"; @@ -16,17 +17,21 @@ class InMemoryParkingRepositoryHolder implements RepositoryHolder { repo: RedisParkingRepository | undefined; + redisClient: RedisClientType | undefined; name = 'RedisParkingRepository'; factory = async () => { - this.repo = new RedisParkingRepository(); - await this.repo.connect(); + this.redisClient = createClient({ + url: process.env.REDIS_URL, + }); + await this.redisClient.connect(); + this.repo = new RedisParkingRepository(this.redisClient); return this.repo; }; teardown = async () => { - if (this.repo) { - await this.repo.clearAllData(); - await this.repo.disconnect(); + if (this.redisClient) { + await this.redisClient.flushAll(); + await this.redisClient.disconnect(); } }; } diff --git a/src/repositories/shuttle/RedisShuttleRepository.ts b/src/repositories/shuttle/RedisShuttleRepository.ts index 96c99a5..1decb11 100644 --- a/src/repositories/shuttle/RedisShuttleRepository.ts +++ b/src/repositories/shuttle/RedisShuttleRepository.ts @@ -24,9 +24,6 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt await this.redisClient.disconnect(); } - public async clearAllData() { - await this.redisClient.flushAll(); - } // EventEmitter override methods for type safety public override on( event: T, diff --git a/src/repositories/shuttle/__tests__/ShuttleRepositorySharedTests.test.ts b/src/repositories/shuttle/__tests__/ShuttleRepositorySharedTests.test.ts index bb99165..2db50fc 100644 --- a/src/repositories/shuttle/__tests__/ShuttleRepositorySharedTests.test.ts +++ b/src/repositories/shuttle/__tests__/ShuttleRepositorySharedTests.test.ts @@ -1,4 +1,5 @@ import { afterEach, beforeEach, describe, expect, jest, test } from "@jest/globals"; +import { createClient, RedisClientType } from "redis"; import { UnoptimizedInMemoryShuttleRepository } from "../UnoptimizedInMemoryShuttleRepository"; import { ShuttleGetterSetterRepository } from "../ShuttleGetterSetterRepository"; import { RedisShuttleRepository } from "../RedisShuttleRepository"; @@ -23,17 +24,21 @@ class UnoptimizedInMemoryShuttleRepositoryHolder implements RepositoryHolder { repo: RedisShuttleRepository | undefined; + redisClient: RedisClientType | undefined; name = 'RedisShuttleRepository'; factory = async () => { - this.repo = new RedisShuttleRepository(); - await this.repo.connect(); + this.redisClient = createClient({ + url: process.env.REDIS_URL, + }); + await this.redisClient.connect(); + this.repo = new RedisShuttleRepository(this.redisClient); return this.repo; }; teardown = async () => { - if (this.repo) { - await this.repo.clearAllData(); - await this.repo.disconnect(); + if (this.redisClient) { + await this.redisClient.flushAll(); + await this.redisClient.disconnect(); } }; } diff --git a/src/repositories/shuttle/eta/ExternalSourceETARepository.ts b/src/repositories/shuttle/eta/ExternalSourceETARepository.ts index 5910d62..53dfe5d 100644 --- a/src/repositories/shuttle/eta/ExternalSourceETARepository.ts +++ b/src/repositories/shuttle/eta/ExternalSourceETARepository.ts @@ -8,6 +8,4 @@ export interface ExternalSourceETARepository extends ETAGetterRepository { addOrUpdateEtaFromExternalSource(eta: IEta): Promise; removeEtaIfExists(shuttleId: string, stopId: string): Promise; - - clearAllData(): Promise; } diff --git a/src/repositories/shuttle/eta/RedisExternalSourceETARepository.ts b/src/repositories/shuttle/eta/RedisExternalSourceETARepository.ts index a551dfb..033dc2e 100644 --- a/src/repositories/shuttle/eta/RedisExternalSourceETARepository.ts +++ b/src/repositories/shuttle/eta/RedisExternalSourceETARepository.ts @@ -37,7 +37,4 @@ export class RedisExternalSourceETARepository extends BaseRedisRepository implem removeAllListeners(eventName?: string | symbol | undefined): this { throw new Error("Method not implemented."); } - clearAllData(): Promise { - throw new Error("Method not implemented."); - } } diff --git a/src/repositories/shuttle/eta/__tests__/ExternalSourceETARepositorySharedTests.test.ts b/src/repositories/shuttle/eta/__tests__/ExternalSourceETARepositorySharedTests.test.ts index 4dc4980..eb4d039 100644 --- a/src/repositories/shuttle/eta/__tests__/ExternalSourceETARepositorySharedTests.test.ts +++ b/src/repositories/shuttle/eta/__tests__/ExternalSourceETARepositorySharedTests.test.ts @@ -1,4 +1,5 @@ import { afterEach, beforeEach, describe, expect, test } from "@jest/globals"; +import { createClient, RedisClientType } from "redis"; import { RepositoryHolder } from "../../../../../testHelpers/RepositoryHolder"; import { ExternalSourceETARepository } from "../ExternalSourceETARepository"; import { RedisExternalSourceETARepository } from "../RedisExternalSourceETARepository"; @@ -6,17 +7,21 @@ import { generateMockEtas } from "../../../../../testHelpers/mockDataGenerators" class RedisExternalSourceETARepositoryHolder implements RepositoryHolder { repo: RedisExternalSourceETARepository | undefined; + redisClient: RedisClientType | undefined; name = "RedisExternalSourceETARepository" factory = async () => { - this.repo = new RedisExternalSourceETARepository(); - await this.repo.connect(); + this.redisClient = createClient({ + url: process.env.REDIS_URL, + }); + await this.redisClient.connect(); + this.repo = new RedisExternalSourceETARepository(this.redisClient); return this.repo; } teardown = async () => { - if (this.repo) { - await this.repo.clearAllData(); - await this.repo.disconnect(); + if (this.redisClient) { + await this.redisClient.flushAll(); + await this.redisClient.disconnect(); } } } diff --git a/src/repositories/shuttle/eta/__tests__/SelfUpdatingETARepositorySharedTests.test.ts b/src/repositories/shuttle/eta/__tests__/SelfUpdatingETARepositorySharedTests.test.ts index ac61cf1..c04ba37 100644 --- a/src/repositories/shuttle/eta/__tests__/SelfUpdatingETARepositorySharedTests.test.ts +++ b/src/repositories/shuttle/eta/__tests__/SelfUpdatingETARepositorySharedTests.test.ts @@ -1,4 +1,5 @@ import { afterEach, beforeEach, describe, expect, test } from "@jest/globals"; +import { createClient, RedisClientType } from "redis"; import { RepositoryHolder } from "../../../../../testHelpers/RepositoryHolder"; import { SelfUpdatingETARepository } from "../SelfUpdatingETARepository"; import { RedisSelfUpdatingETARepository } from "../RedisSelfUpdatingETARepository"; @@ -8,25 +9,25 @@ import { setupRouteAndOrderedStopsForShuttleRepository } from "../../../../../te class RedisSelfUpdatingETARepositoryHolder implements RepositoryHolder { repo: RedisSelfUpdatingETARepository | undefined; shuttleRepo: RedisShuttleRepository | undefined; + redisClient: RedisClientType | undefined; name = "RedisSelfUpdatingETARepository" factory = async () => { - this.shuttleRepo = new RedisShuttleRepository(); - await this.shuttleRepo.connect(); + this.redisClient = createClient({ + url: process.env.REDIS_URL, + }); + await this.redisClient.connect(); + this.shuttleRepo = new RedisShuttleRepository(this.redisClient); this.repo = new RedisSelfUpdatingETARepository( this.shuttleRepo, + this.redisClient, ); - await this.repo.connect(); return this.repo; } teardown = async () => { - if (this.shuttleRepo) { - await this.shuttleRepo.clearAllData(); - await this.shuttleRepo.disconnect(); - } - if (this.repo) { - await this.repo.clearAllData(); - await this.repo.disconnect(); + if (this.redisClient) { + await this.redisClient.flushAll(); + await this.redisClient.disconnect(); } } }