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

@@ -8,6 +8,4 @@ export interface ExternalSourceETARepository extends ETAGetterRepository {
addOrUpdateEtaFromExternalSource(eta: IEta): Promise<void>;
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 {
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 { 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<ExternalSourceETARepository> {
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();
}
}
}

View File

@@ -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<SelfUpdatingETARepository> {
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();
}
}
}