• The cacheTestSuite function simplifies the process of testing your custom implementation of ICache with vitest.

    Parameters

    Returns void

    import Redis from "ioredis";
    import { afterEach, beforeEach, describe, expect, test } from "vitest";
    import { RedisContainer, type StartedRedisContainer } from "@testcontainers/redis";
    import { SuperJsonSerde, TimeSpan, RedisCacheAdapter, cacheTestSuite, MemoryEventBusAdapter } from "@daiso-tech/core";

    const timeout = TimeSpan.fromMinutes(2);
    describe("class: Cache", () => {
    let client: Redis;
    let startedContainer: StartedRedisContainer;
    const eventBus = new EventBus(new MemoryEventBusAdapter()):
    const serde = new SuperJsonSerde();
    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());
    cacheTestSuite({
    createCacheA: () =>
    new Cache(
    new RedisCacheAdapter(client, {
    serde,
    }),
    {
    rootGroup: "@a",
    eventBus,
    }
    ),
    createCacheB: () =>
    new Cache(
    new RedisCacheAdapter(client, {
    serde,
    }),
    {
    rootGroup: "@b",
    eventBus,
    }
    ),
    test,
    beforeEach,
    expect,
    describe,
    });
    });