import { describe, expect, test, beforeEach } from "vitest";
import { MemoryLockAdapter } from "@daiso-tech/core/lock/adapters";
import { LockProvider } from "@daiso-tech/core/lock";
import { EventBus } from "@daiso-tech/core/event-bus";
import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/adapters";
import { lockProviderTestSuite } from "@daiso-tech/core/lock/test-utilities";
import { Serde } from "@daiso-tech/core/serde";
import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters";
import type { ILockData } from "@daiso-tech/core/lock/contracts";
import { KeyPrefixer } from "@daiso-tech/core/utilities";
describe("class: LockProvider", () => {
const eventBus = new EventBus({
keyPrefixer: new KeyPrefixer("event-bus"),
adapter: new MemoryEventBusAdapter(),
});
const serde = new Serde(new SuperJsonSerdeAdapter());
let map: Map<string, ILockData>;
lockProviderTestSuite({
createLockProvider: () => {
const lockProvider = new LockProvider({
serde,
adapter: new MemoryLockAdapter(),
eventBus,
keyPrefixer: new KeyPrefixer("lock"),
});
return lockProvider;
},
beforeEach,
describe,
expect,
test,
serde,
});
});
The
lockProviderTestSuite
function simplifies the process of testing your custom implementation ofILock
withvitest
.IMPORT_PATH:
"@daiso-tech/core/lock/test-utilities"