Function eventBusAdapterTestSuite

  • The eventBusAdapterTestSuite function simplifies the process of testing your custom implementation of IEventBusAdapter with vitest.

    Returns void

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

    const timeout = TimeSpan.fromMinutes(2);
    describe("class: RedisPubSubEventBusAdapter", () => {
    let dispatcherClient: Redis;
    let listenerClient: Redis;
    let startedContainer: StartedRedisContainer;
    const serde = new SuperJsonSerde();
    beforeEach(async () => {
    startedContainer = await new RedisContainer().start();
    dispatcherClient = new Redis(startedContainer.getConnectionUrl());
    listenerClient = new Redis(startedContainer.getConnectionUrl());
    }, timeout.toMilliseconds());
    afterEach(async () => {
    await dispatcherClient.quit();
    await listenerClient.quit();
    await startedContainer.stop();
    }, timeout.toMilliseconds());
    eventBusAdapterTestSuite({
    createAdapterA: () =>
    new RedisPubSubEventBusAdapter({
    dispatcherClient,
    listenerClient,
    serde,
    rootGroup: "@global"
    }),
    createAdapterB: () =>
    new RedisPubSubEventBusAdapter({
    dispatcherClient,
    listenerClient,
    serde,
    rootGroup: "@global"
    }),
    serde,
    test,
    beforeEach,
    expect,
    describe,
    });
    });