webstore/test/test.webstore.both.ts

41 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-07-27 11:51:40 +00:00
import { expect, tap } from '@push.rocks/tapbundle';
2022-05-28 10:33:10 +00:00
import * as webstore from '../ts/index.js';
2020-07-09 22:30:33 +00:00
2020-07-09 23:03:01 +00:00
let testWebstore: webstore.WebStore;
2020-07-09 22:30:33 +00:00
tap.test('first test', async () => {
2020-07-09 23:03:01 +00:00
testWebstore = new webstore.WebStore({
2020-07-11 17:15:24 +00:00
dbName: 'mytest-db',
2020-09-18 10:12:02 +00:00
storeName: 'mytest-store',
2020-07-09 23:03:01 +00:00
});
2022-01-24 03:39:12 +00:00
expect(testWebstore).toBeInstanceOf(webstore.WebStore);
2020-07-09 22:30:33 +00:00
});
2020-07-11 17:19:29 +00:00
tap.test('should allow storing a string', async () => {
await testWebstore.set('mystring', 'heythere');
2022-01-24 03:39:12 +00:00
expect(await testWebstore.get('mystring')).toEqual('heythere');
2020-07-11 17:19:29 +00:00
});
tap.test('should allow storing an object', async () => {
2020-07-09 23:03:01 +00:00
await testWebstore.set('testProp1', {
2020-09-18 10:12:02 +00:00
wow: 'wowVal',
2020-07-09 23:03:01 +00:00
});
console.log(JSON.stringify(await testWebstore.get('testProp1')));
});
2020-07-11 17:15:24 +00:00
tap.test('should overwrite a value', async () => {
await testWebstore.set('testProp1', {
2020-09-18 10:12:02 +00:00
wow: 'wowVal2',
2020-07-11 17:15:24 +00:00
});
console.log(JSON.stringify(await testWebstore.get('testProp1')));
});
tap.test('should correctly check the existence of keys', async () => {
2020-09-18 10:12:02 +00:00
const resultNotThere = await testWebstore.check('notThere');
2020-07-11 17:15:24 +00:00
const resultThere = await testWebstore.check('testProp1');
2022-01-24 03:39:12 +00:00
expect(resultNotThere).toBeFalse();
expect(resultThere).toBeTrue();
2020-07-11 17:15:24 +00:00
});
2020-07-09 22:30:33 +00:00
tap.start();