Function databaseSharedLockAdapterTestSuite

  • The databaseSharedLockAdapterTestSuite function simplifies the process of testing your custom implementation of IDatabaseSharedLockAdapter with vitest.

    IMPORT_PATH: "@daiso-tech/core/shared-lock/test-utilities"

    Returns void

    import { afterEach, beforeEach, describe, expect, test } from "vitest";
    import { databaseSharedLockAdapterTestSuite } from "@daiso-tech/core/shared-lock/test-utilities";
    import { KyselySharedLockAdapter, type KyselySharedLockTables } from "@daiso-tech/core/shared-lock/kysely-shared-lock-adapter";
    import { Kysely, SqliteDialect } from "kysely";
    import Sqlite, { type Database } from "better-sqlite3";

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

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