npmextra/test/test.kvstore.ts

32 lines
890 B
TypeScript
Raw Normal View History

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