npmextra/test/test.kvstore.ts
2024-06-12 20:04:04 +02:00

32 lines
890 B
TypeScript

import { expect, tap } from '@push.rocks/tapbundle';
import * as npmextra from '../ts/index.js';
let myKeyValueStore: npmextra.KeyValueStore<any>;
tap.test('should create a keyValueStore', async () => {
myKeyValueStore = new npmextra.KeyValueStore<any>({
typeArg: 'custom',
identityArg: 'test',
customPath: 'test/somekv.json',
});
expect(myKeyValueStore).toBeInstanceOf(npmextra.KeyValueStore);
});
tap.test('should reset the keyValueStore', async () => {
await myKeyValueStore.reset();
});
tap.test('expect result to be empty', async () => {
let result = await myKeyValueStore.readAll();
expect(JSON.stringify(result)).toEqual('{}');
});
tap.test('expect to add an object to the kv Store', async () => {
await myKeyValueStore.writeAll({
myKey: 'myValue',
});
await expect(await myKeyValueStore.readKey('myKey')).toEqual('myValue');
});
tap.start();