From 7a5e1b8561b5ddcb6c0208f8814905615998489e Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Mon, 31 Mar 2025 19:50:37 -0700 Subject: [PATCH] use describe.each to test the multiple implementations --- ...test.ts => NotificationRepositoryTests.ts} | 22 ++++++++++++++----- .../RedisNotificationRepositoryTests.test.ts | 22 ------------------- 2 files changed, 17 insertions(+), 27 deletions(-) rename test/repositories/{InMemoryNotificationRepositoryTests.test.ts => NotificationRepositoryTests.ts} (88%) delete mode 100644 test/repositories/RedisNotificationRepositoryTests.test.ts diff --git a/test/repositories/InMemoryNotificationRepositoryTests.test.ts b/test/repositories/NotificationRepositoryTests.ts similarity index 88% rename from test/repositories/InMemoryNotificationRepositoryTests.test.ts rename to test/repositories/NotificationRepositoryTests.ts index 3419d96..5216224 100644 --- a/test/repositories/InMemoryNotificationRepositoryTests.test.ts +++ b/test/repositories/NotificationRepositoryTests.ts @@ -1,13 +1,25 @@ import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import { InMemoryNotificationRepository } from "../../src/repositories/InMemoryNotificationRepository"; -import { NotificationEvent } from "../../src/repositories/NotificationRepository"; +import { NotificationEvent, NotificationRepository } from "../../src/repositories/NotificationRepository"; +import { RedisNotificationRepository } from "../../src/repositories/RedisNotificationRepository"; -describe("InMemoryNotificationRepository", () => { - let repo: InMemoryNotificationRepository; +const repositoryImplementations = [ + { + name: 'InMemoryNotificationRepository', + factory: () => new InMemoryNotificationRepository(), + }, + { + name: 'RedisNotificationRepository', + factory: () => new RedisNotificationRepository(), + }, +] + +describe.each(repositoryImplementations)('$name', ({ factory }) => { + let repo: NotificationRepository; beforeEach(() => { - repo = new InMemoryNotificationRepository(); - }) + repo = factory(); + }); const notification = { deviceId: "device1", diff --git a/test/repositories/RedisNotificationRepositoryTests.test.ts b/test/repositories/RedisNotificationRepositoryTests.test.ts deleted file mode 100644 index 0eb4a92..0000000 --- a/test/repositories/RedisNotificationRepositoryTests.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { afterEach, beforeEach, describe } from "@jest/globals"; -import { createClient, RedisClientType } from "redis"; -import { RedisNotificationRepository } from "../../src/repositories/RedisNotificationRepository"; - -describe("RedisNotificationRepository", () => { - let redisClient: RedisClientType; - let repository: RedisNotificationRepository; - - beforeEach(async () => { - redisClient = createClient({ - url: process.env.REDIS_URL, - }); - repository = new RedisNotificationRepository( - redisClient - ); - await repository.connect(); - }); - - afterEach(async () => { - await repository.disconnect(); - }) -});