2020-07-09 22:30:33 +00:00
|
|
|
import { expect, tap } from '@pushrocks/tapbundle';
|
|
|
|
import * as webstore from '../ts/index';
|
|
|
|
|
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();
|