mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
restructure implementation holders into classes with teardown
This commit is contained in:
@@ -1,30 +1,54 @@
|
|||||||
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals";
|
||||||
import { InMemoryNotificationRepository } from "../../src/repositories/InMemoryNotificationRepository";
|
import { InMemoryNotificationRepository } from "../../src/repositories/InMemoryNotificationRepository";
|
||||||
import { NotificationEvent, NotificationRepository } from "../../src/repositories/NotificationRepository";
|
import { NotificationEvent, NotificationRepository } from "../../src/repositories/NotificationRepository";
|
||||||
import { RedisNotificationRepository } from "../../src/repositories/RedisNotificationRepository";
|
import { RedisNotificationRepository } from "../../src/repositories/RedisNotificationRepository";
|
||||||
|
|
||||||
|
interface RepositoryHolder {
|
||||||
|
name: string;
|
||||||
|
factory(): Promise<NotificationRepository>,
|
||||||
|
teardown(): Promise<void>,
|
||||||
|
}
|
||||||
|
|
||||||
|
class InMemoryRepositoryHolder implements RepositoryHolder {
|
||||||
|
name = 'InMemoryNotificationRepository';
|
||||||
|
factory = async () => {
|
||||||
|
return new InMemoryNotificationRepository();
|
||||||
|
}
|
||||||
|
teardown = async () => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RedisNotificationRepositoryHolder implements RepositoryHolder {
|
||||||
|
repo: RedisNotificationRepository | undefined;
|
||||||
|
|
||||||
|
name = 'RedisNotificationRepository';
|
||||||
|
factory = async () => {
|
||||||
|
this.repo = new RedisNotificationRepository();
|
||||||
|
await this.repo.connect();
|
||||||
|
return this.repo;
|
||||||
|
}
|
||||||
|
teardown = async () => {
|
||||||
|
if (this.repo) {
|
||||||
|
await this.repo.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const repositoryImplementations = [
|
const repositoryImplementations = [
|
||||||
{
|
new InMemoryRepositoryHolder(),
|
||||||
name: 'InMemoryNotificationRepository',
|
new RedisNotificationRepositoryHolder(),
|
||||||
factory: async () => new InMemoryNotificationRepository(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'RedisNotificationRepository',
|
|
||||||
factory: async () => {
|
|
||||||
const repo = new RedisNotificationRepository();
|
|
||||||
await repo.connect();
|
|
||||||
return repo;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
|
|
||||||
describe.each(repositoryImplementations)('$name', ({ factory }) => {
|
describe.each(repositoryImplementations)('$name', (holder) => {
|
||||||
let repo: NotificationRepository;
|
let repo: NotificationRepository;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
repo = await factory();
|
repo = await holder.factory();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await holder.teardown();
|
||||||
|
})
|
||||||
|
|
||||||
const notification = {
|
const notification = {
|
||||||
deviceId: "device1",
|
deviceId: "device1",
|
||||||
shuttleId: "shuttle1",
|
shuttleId: "shuttle1",
|
||||||
|
|||||||
Reference in New Issue
Block a user