mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
use describe.each to test the multiple implementations
This commit is contained in:
@@ -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",
|
||||
@@ -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();
|
||||
})
|
||||
});
|
||||
Reference in New Issue
Block a user