use describe.each to test the multiple implementations

This commit is contained in:
2025-03-31 19:50:37 -07:00
parent a7ac9888f6
commit 7a5e1b8561
2 changed files with 17 additions and 27 deletions

View File

@@ -1,13 +1,25 @@
import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import { beforeEach, describe, expect, it, jest } from "@jest/globals";
import { InMemoryNotificationRepository } from "../../src/repositories/InMemoryNotificationRepository"; 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", () => { const repositoryImplementations = [
let repo: InMemoryNotificationRepository; {
name: 'InMemoryNotificationRepository',
factory: () => new InMemoryNotificationRepository(),
},
{
name: 'RedisNotificationRepository',
factory: () => new RedisNotificationRepository(),
},
]
describe.each(repositoryImplementations)('$name', ({ factory }) => {
let repo: NotificationRepository;
beforeEach(() => { beforeEach(() => {
repo = new InMemoryNotificationRepository(); repo = factory();
}) });
const notification = { const notification = {
deviceId: "device1", deviceId: "device1",

View File

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