npmextra/test/test.kvstore.ts

32 lines
890 B
TypeScript
Raw Permalink Normal View History

2023-08-03 17:22:34 +00:00
import { expect, tap } from '@push.rocks/tapbundle';
2017-07-12 15:13:29 +00:00
2023-08-03 17:22:34 +00:00
import * as npmextra from '../ts/index.js';
2017-07-12 15:13:29 +00:00
2024-06-12 18:04:04 +00:00
let myKeyValueStore: npmextra.KeyValueStore<any>;
2017-07-12 15:13:29 +00:00
tap.test('should create a keyValueStore', async () => {
2024-06-12 18:04:04 +00:00
myKeyValueStore = new npmextra.KeyValueStore<any>({
typeArg: 'custom',
identityArg: 'test',
customPath: 'test/somekv.json',
});
2023-08-03 17:22:34 +00:00
expect(myKeyValueStore).toBeInstanceOf(npmextra.KeyValueStore);
});
2017-07-12 15:13:29 +00:00
2023-08-24 08:44:42 +00:00
tap.test('should reset the keyValueStore', async () => {
await myKeyValueStore.reset();
});
2017-07-12 15:13:29 +00:00
tap.test('expect result to be empty', async () => {
2023-08-03 17:22:34 +00:00
let result = await myKeyValueStore.readAll();
expect(JSON.stringify(result)).toEqual('{}');
});
2017-07-12 15:13:29 +00:00
tap.test('expect to add an object to the kv Store', async () => {
2017-08-16 16:25:45 +00:00
await myKeyValueStore.writeAll({
2021-01-27 21:00:49 +00:00
myKey: 'myValue',
});
2023-08-03 17:22:34 +00:00
await expect(await myKeyValueStore.readKey('myKey')).toEqual('myValue');
});
2017-07-12 15:13:29 +00:00
2024-06-12 18:04:04 +00:00
tap.start();