Function databaseSemaphoreAdapterTestSuite

  • The databaseSemaphoreAdapterTestSuite function simplifies the process of testing your custom implementation of IDatabaseSemaphoreAdapter with vitest.

    IMPORT_PATH: "@daiso-tech/core/semaphore/test-utilities"

    Returns void

    import { afterEach, beforeEach, describe, expect, test } from "vitest";
    import { databaseSemaphoreAdapterTestSuite } from "@daiso-tech/core/semaphore/test-utilities";
    import { kyselySemaphoreAdapter, type KyselySemaphoreTables } from "@daiso-tech/core/semaphore/kysely-semaphore-adapter";
    import { Kysely, SqliteDialect } from "kysely";
    import Sqlite, { type Database } from "better-sqlite3";

    describe("class: kyselySemaphoreAdapter", () => {
    let database: Database;
    let kysely: Kysely<KyselySemaphoreTables>;

    beforeEach(() => {
    database = new Sqlite(":memory:");
    kysely = new Kysely({
    dialect: new SqliteDialect({
    database,
    }),
    });
    });
    afterEach(() => {
    database.close();
    });
    databaseSemaphoreAdapterTestSuite({
    createAdapter: async () => {
    const semaphoreAdapter = new kyselySemaphoreAdapter({
    kysely,
    shouldRemoveExpiredKeys: false,
    });
    await semaphoreAdapter.init();
    return semaphoreAdapter;
    },
    test,
    beforeEach,
    expect,
    describe,
    });
    });