Function databaseLockAdapterTestSuite

  • The databaseLockAdapterTestSuite function simplifies the process of testing your custom implementation of IDatabaseLockAdapter with vitest.

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

    Returns void

    import { afterEach, beforeEach, describe, expect, test } from "vitest";
    import { databaseLockAdapterTestSuite } from "@@daiso-tech/core/lock/implementations/test-utilities";
    import { LibsqlLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
    import { type Client, createClient } from "@libsql/client";

    describe("class: LibsqlLockAdapter", () => {
    let client: Client;
    beforeEach(() => {
    client = createClient({
    url: ":memory:",
    });
    });
    afterEach(() => {
    client.close();
    });
    databaseLockAdapterTestSuite({
    createAdapter: async () => {
    const lockAdapter = new LibsqlLockAdapter({
    database: client,
    tableName: "custom_table",
    shouldRemoveExpiredKeys: false,
    rootGroup: "@a",
    });
    await lockAdapter.init();
    return lockAdapter;
    },
    test,
    beforeEach,
    expect,
    describe,
    });
    });