Remove clearAllData from BaseRedisRepository and update tests

This commit is contained in:
2025-11-11 14:50:53 -08:00
parent 01c55d52ec
commit 99999450b5
9 changed files with 51 additions and 42 deletions

View File

@@ -33,8 +33,4 @@ export abstract class BaseRedisRepository extends EventEmitter {
public async disconnect() { public async disconnect() {
await this.redisClient.disconnect(); await this.redisClient.disconnect();
} }
public async clearAllData() {
await this.redisClient.flushAll();
}
} }

View File

@@ -1,4 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals"; import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals";
import { createClient, RedisClientType } from "redis";
import { InMemoryNotificationRepository } from "../InMemoryNotificationRepository"; import { InMemoryNotificationRepository } from "../InMemoryNotificationRepository";
import { NotificationEvent, NotificationRepository } from "../NotificationRepository"; import { NotificationEvent, NotificationRepository } from "../NotificationRepository";
import { RedisNotificationRepository } from "../RedisNotificationRepository"; import { RedisNotificationRepository } from "../RedisNotificationRepository";
@@ -19,17 +20,21 @@ class InMemoryRepositoryHolder implements RepositoryHolder {
class RedisNotificationRepositoryHolder implements RepositoryHolder { class RedisNotificationRepositoryHolder implements RepositoryHolder {
repo: RedisNotificationRepository | undefined; repo: RedisNotificationRepository | undefined;
redisClient: RedisClientType | undefined;
name = 'RedisNotificationRepository'; name = 'RedisNotificationRepository';
factory = async () => { factory = async () => {
this.repo = new RedisNotificationRepository(); this.redisClient = createClient({
await this.repo.connect(); url: process.env.REDIS_URL,
});
await this.redisClient.connect();
this.repo = new RedisNotificationRepository(this.redisClient);
return this.repo; return this.repo;
} }
teardown = async () => { teardown = async () => {
if (this.repo) { if (this.redisClient) {
await this.repo.clearAllData(); await this.redisClient.flushAll();
await this.repo.disconnect(); await this.redisClient.disconnect();
} }
} }
} }

View File

@@ -1,4 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals"; import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals";
import { createClient, RedisClientType } from "redis";
import { InMemoryParkingRepository, } from "../InMemoryParkingRepository"; import { InMemoryParkingRepository, } from "../InMemoryParkingRepository";
import { IParkingStructure } from "../../../entities/ParkingRepositoryEntities"; import { IParkingStructure } from "../../../entities/ParkingRepositoryEntities";
import { ParkingGetterSetterRepository } from "../ParkingGetterSetterRepository"; import { ParkingGetterSetterRepository } from "../ParkingGetterSetterRepository";
@@ -16,17 +17,21 @@ class InMemoryParkingRepositoryHolder implements RepositoryHolder<ParkingGetterS
class RedisParkingRepositoryHolder implements RepositoryHolder<ParkingGetterSetterRepository> { class RedisParkingRepositoryHolder implements RepositoryHolder<ParkingGetterSetterRepository> {
repo: RedisParkingRepository | undefined; repo: RedisParkingRepository | undefined;
redisClient: RedisClientType | undefined;
name = 'RedisParkingRepository'; name = 'RedisParkingRepository';
factory = async () => { factory = async () => {
this.repo = new RedisParkingRepository(); this.redisClient = createClient({
await this.repo.connect(); url: process.env.REDIS_URL,
});
await this.redisClient.connect();
this.repo = new RedisParkingRepository(this.redisClient);
return this.repo; return this.repo;
}; };
teardown = async () => { teardown = async () => {
if (this.repo) { if (this.redisClient) {
await this.repo.clearAllData(); await this.redisClient.flushAll();
await this.repo.disconnect(); await this.redisClient.disconnect();
} }
}; };
} }

View File

@@ -24,9 +24,6 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
await this.redisClient.disconnect(); await this.redisClient.disconnect();
} }
public async clearAllData() {
await this.redisClient.flushAll();
}
// EventEmitter override methods for type safety // EventEmitter override methods for type safety
public override on<T extends ShuttleRepositoryEventName>( public override on<T extends ShuttleRepositoryEventName>(
event: T, event: T,

View File

@@ -1,4 +1,5 @@
import { afterEach, beforeEach, describe, expect, jest, test } from "@jest/globals"; import { afterEach, beforeEach, describe, expect, jest, test } from "@jest/globals";
import { createClient, RedisClientType } from "redis";
import { UnoptimizedInMemoryShuttleRepository } from "../UnoptimizedInMemoryShuttleRepository"; import { UnoptimizedInMemoryShuttleRepository } from "../UnoptimizedInMemoryShuttleRepository";
import { ShuttleGetterSetterRepository } from "../ShuttleGetterSetterRepository"; import { ShuttleGetterSetterRepository } from "../ShuttleGetterSetterRepository";
import { RedisShuttleRepository } from "../RedisShuttleRepository"; import { RedisShuttleRepository } from "../RedisShuttleRepository";
@@ -23,17 +24,21 @@ class UnoptimizedInMemoryShuttleRepositoryHolder implements RepositoryHolder<Shu
class RedisShuttleRepositoryHolder implements RepositoryHolder<ShuttleGetterSetterRepository> { class RedisShuttleRepositoryHolder implements RepositoryHolder<ShuttleGetterSetterRepository> {
repo: RedisShuttleRepository | undefined; repo: RedisShuttleRepository | undefined;
redisClient: RedisClientType | undefined;
name = 'RedisShuttleRepository'; name = 'RedisShuttleRepository';
factory = async () => { factory = async () => {
this.repo = new RedisShuttleRepository(); this.redisClient = createClient({
await this.repo.connect(); url: process.env.REDIS_URL,
});
await this.redisClient.connect();
this.repo = new RedisShuttleRepository(this.redisClient);
return this.repo; return this.repo;
}; };
teardown = async () => { teardown = async () => {
if (this.repo) { if (this.redisClient) {
await this.repo.clearAllData(); await this.redisClient.flushAll();
await this.repo.disconnect(); await this.redisClient.disconnect();
} }
}; };
} }

View File

@@ -8,6 +8,4 @@ export interface ExternalSourceETARepository extends ETAGetterRepository {
addOrUpdateEtaFromExternalSource(eta: IEta): Promise<void>; addOrUpdateEtaFromExternalSource(eta: IEta): Promise<void>;
removeEtaIfExists(shuttleId: string, stopId: string): Promise<IEta | null>; removeEtaIfExists(shuttleId: string, stopId: string): Promise<IEta | null>;
clearAllData(): Promise<void>;
} }

View File

@@ -37,7 +37,4 @@ export class RedisExternalSourceETARepository extends BaseRedisRepository implem
removeAllListeners(eventName?: string | symbol | undefined): this { removeAllListeners(eventName?: string | symbol | undefined): this {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
clearAllData(): Promise<void> {
throw new Error("Method not implemented.");
}
} }

View File

@@ -1,4 +1,5 @@
import { afterEach, beforeEach, describe, expect, test } from "@jest/globals"; import { afterEach, beforeEach, describe, expect, test } from "@jest/globals";
import { createClient, RedisClientType } from "redis";
import { RepositoryHolder } from "../../../../../testHelpers/RepositoryHolder"; import { RepositoryHolder } from "../../../../../testHelpers/RepositoryHolder";
import { ExternalSourceETARepository } from "../ExternalSourceETARepository"; import { ExternalSourceETARepository } from "../ExternalSourceETARepository";
import { RedisExternalSourceETARepository } from "../RedisExternalSourceETARepository"; import { RedisExternalSourceETARepository } from "../RedisExternalSourceETARepository";
@@ -6,17 +7,21 @@ import { generateMockEtas } from "../../../../../testHelpers/mockDataGenerators"
class RedisExternalSourceETARepositoryHolder implements RepositoryHolder<ExternalSourceETARepository> { class RedisExternalSourceETARepositoryHolder implements RepositoryHolder<ExternalSourceETARepository> {
repo: RedisExternalSourceETARepository | undefined; repo: RedisExternalSourceETARepository | undefined;
redisClient: RedisClientType | undefined;
name = "RedisExternalSourceETARepository" name = "RedisExternalSourceETARepository"
factory = async () => { factory = async () => {
this.repo = new RedisExternalSourceETARepository(); this.redisClient = createClient({
await this.repo.connect(); url: process.env.REDIS_URL,
});
await this.redisClient.connect();
this.repo = new RedisExternalSourceETARepository(this.redisClient);
return this.repo; return this.repo;
} }
teardown = async () => { teardown = async () => {
if (this.repo) { if (this.redisClient) {
await this.repo.clearAllData(); await this.redisClient.flushAll();
await this.repo.disconnect(); await this.redisClient.disconnect();
} }
} }
} }

View File

@@ -1,4 +1,5 @@
import { afterEach, beforeEach, describe, expect, test } from "@jest/globals"; import { afterEach, beforeEach, describe, expect, test } from "@jest/globals";
import { createClient, RedisClientType } from "redis";
import { RepositoryHolder } from "../../../../../testHelpers/RepositoryHolder"; import { RepositoryHolder } from "../../../../../testHelpers/RepositoryHolder";
import { SelfUpdatingETARepository } from "../SelfUpdatingETARepository"; import { SelfUpdatingETARepository } from "../SelfUpdatingETARepository";
import { RedisSelfUpdatingETARepository } from "../RedisSelfUpdatingETARepository"; import { RedisSelfUpdatingETARepository } from "../RedisSelfUpdatingETARepository";
@@ -8,25 +9,25 @@ import { setupRouteAndOrderedStopsForShuttleRepository } from "../../../../../te
class RedisSelfUpdatingETARepositoryHolder implements RepositoryHolder<SelfUpdatingETARepository> { class RedisSelfUpdatingETARepositoryHolder implements RepositoryHolder<SelfUpdatingETARepository> {
repo: RedisSelfUpdatingETARepository | undefined; repo: RedisSelfUpdatingETARepository | undefined;
shuttleRepo: RedisShuttleRepository | undefined; shuttleRepo: RedisShuttleRepository | undefined;
redisClient: RedisClientType | undefined;
name = "RedisSelfUpdatingETARepository" name = "RedisSelfUpdatingETARepository"
factory = async () => { factory = async () => {
this.shuttleRepo = new RedisShuttleRepository(); this.redisClient = createClient({
await this.shuttleRepo.connect(); url: process.env.REDIS_URL,
});
await this.redisClient.connect();
this.shuttleRepo = new RedisShuttleRepository(this.redisClient);
this.repo = new RedisSelfUpdatingETARepository( this.repo = new RedisSelfUpdatingETARepository(
this.shuttleRepo, this.shuttleRepo,
this.redisClient,
); );
await this.repo.connect();
return this.repo; return this.repo;
} }
teardown = async () => { teardown = async () => {
if (this.shuttleRepo) { if (this.redisClient) {
await this.shuttleRepo.clearAllData(); await this.redisClient.flushAll();
await this.shuttleRepo.disconnect(); await this.redisClient.disconnect();
}
if (this.repo) {
await this.repo.clearAllData();
await this.repo.disconnect();
} }
} }
} }