Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should allow a merge data transformation', async () => {
const connector = new StateDB.Connector();
const k1 = 'foo';
const v1 = 'bar';
const k2 = 'baz';
const v2 = 'qux';
expect(await connector.fetch(k1)).to.be.undefined;
expect(await connector.fetch(k2)).to.be.undefined;
await connector.save(k1, `{ "v": "${v1}"}`);
expect(JSON.parse(await connector.fetch(k1)).v).to.equal(v1);
const transform = new PromiseDelegate();
const db = new StateDB({ connector, transform: transform.promise });
const transformation: StateDB.DataTransform = {
type: 'merge',
contents: { [k2]: v2 }
};
it('should empty the items in a state database', async () => {
const connector = new StateDB.Connector();
const db = new StateDB({ connector });
expect((await connector.list()).ids).to.be.empty;
await db.save('foo', 'bar');
expect((await connector.list()).ids).not.to.be.empty;
await db.clear();
expect((await connector.list()).ids).to.be.empty;
});
});