Function databaseCacheAdapterTestSuite

  • The databaseCacheAdapterTestSuite function simplifies the process of testing your custom implementation of IDatabaseCacheAdapter with vitest.

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

    Returns void

    import { afterEach, beforeEach, describe, expect, test } from "vitest";
    import Sqlite, { type Database } from "better-sqlite3";
    import { databaseCacheAdapterTestSuite } from "@daiso-tech/core/cache/test-utilities";
    import { SqliteCacheAdapter } from "@daiso-tech/core/cache/adapters";
    import { Serde } from "@daiso-tech/core/serde";
    import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters";

    describe("class: SqliteCacheAdapter", () => {
    let database: Database;
    beforeEach(() => {
    database = new Sqlite(":memory:");
    });
    afterEach(() => {
    database.close();
    });
    databaseCacheAdapterTestSuite({
    createAdapter: async () => {
    const adapter = new SqliteCacheAdapter({
    database: database,
    tableName: "custom_table",
    shouldRemoveExpiredKeys: false,
    serde: new Serde(new SuperJsonSerdeAdapter()),
    });
    await adapter.init();
    return adapter;
    },
    test,
    beforeEach,
    expect,
    describe,
    });
    });