import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { Redis } from "ioredis";
import {
RedisContainer,
type StartedRedisContainer,
} from "@testcontainers/redis";
import { cacheAdapterTestSuite } from "@daiso-tech/core/cache/test-utilities";
import { RedisCacheAdapter } from "@daiso-tech/core/cache/adapters";
import { TimeSpan } from "@daiso-tech/core/utilities";
import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters";
import { Serde } from "@daiso-tech/core/serde";
const timeout = TimeSpan.fromMinutes(2);
describe("class: RedisCacheAdapter", () => {
let client: Redis;
let startedContainer: StartedRedisContainer;
beforeEach(async () => {
startedContainer = await new RedisContainer("redis:7.4.2").start();
client = new Redis(startedContainer.getConnectionUrl());
}, timeout.toMilliseconds());
afterEach(async () => {
await client.quit();
await startedContainer.stop();
}, timeout.toMilliseconds());
cacheAdapterTestSuite({
createAdapter: () =>
new RedisCacheAdapter({
database: client,
serde: new Serde(new SuperJsonSerdeAdapter()),
}),
test,
beforeEach,
expect,
describe,
});
});
The
cacheAdapterTestSuite
function simplifies the process of testing your custom implementation ofICacheAdapter
withvitest
.IMPORT_PATH:
"@daiso-tech/core/cache/test-utilities"