From 611fb3533082a058a72381c656d950e72bd2876c Mon Sep 17 00:00:00 2001 From: haad Date: Thu, 9 Mar 2023 09:52:06 +0200 Subject: [PATCH] Fix tests for deleting a key-value pair --- src/db/keyvalue-persisted.js | 14 +++----------- src/db/keyvalue.js | 3 --- test/db/keyvalue-persisted.js | 16 +++++++--------- test/db/keyvalue.test.js | 16 +++++++--------- 4 files changed, 17 insertions(+), 32 deletions(-) diff --git a/src/db/keyvalue-persisted.js b/src/db/keyvalue-persisted.js index 630ce24..28ca424 100644 --- a/src/db/keyvalue-persisted.js +++ b/src/db/keyvalue-persisted.js @@ -35,16 +35,10 @@ const KeyValuePersisted = async ({ OpLog, Database, ipfs, identity, address, nam const get = async (key) => { await queue.onIdle() - - try { - const value = await index.get(key) - if (value) { - return value - } - } catch (e) { - // LEVEL_NOT_FOUND (ie. key not found) + const value = await index.get(key) + if (value) { + return value } - return keyValueStore.get(key) } @@ -58,7 +52,6 @@ const KeyValuePersisted = async ({ OpLog, Database, ipfs, identity, address, nam const task = async () => { await queue.add(updateIndex(index)) } - // TODO: all() const close = async () => { events.off('update', task) @@ -82,7 +75,6 @@ const KeyValuePersisted = async ({ OpLog, Database, ipfs, identity, address, nam ...keyValueStore, get, iterator, - // TODO: all, close, drop } diff --git a/src/db/keyvalue.js b/src/db/keyvalue.js index fb76fd6..9d6c67c 100644 --- a/src/db/keyvalue.js +++ b/src/db/keyvalue.js @@ -40,8 +40,6 @@ const KeyValue = async ({ OpLog, Database, ipfs, identity, address, name, access } } - // TODO: all() - return { ...database, type: 'keyvalue', @@ -50,7 +48,6 @@ const KeyValue = async ({ OpLog, Database, ipfs, identity, address, name, access del, get, iterator - // TODO: all, } } diff --git a/test/db/keyvalue-persisted.js b/test/db/keyvalue-persisted.js index cef3917..8348f43 100644 --- a/test/db/keyvalue-persisted.js +++ b/test/db/keyvalue-persisted.js @@ -155,22 +155,20 @@ describe('KeyValuePersisted Database', function () { it('deletes a key/value pair', async () => { const key = 'key1' - const expected = undefined await db.put(key, 'value1') - const hash = await db.del(key) + await db.del(key) - const actual = await db.get(hash) - strictEqual(actual, expected) + const actual = await db.get(key) + strictEqual(actual, undefined) }) it('deletes a non-existent key/value pair', async () => { - const expected = undefined + const key = 'this key doesn\'t exist' + await db.del(key) - const del = await db.del('zdpuApFgnZNp6qQqeuHRLJhEKsmMnXEEJfSZofLc3ZZXEihWE') - - const actual = await db.get(del) - strictEqual(actual, expected) + const actual = await db.get(key) + strictEqual(actual, undefined) }) it('returns all key/value pairs', async () => { diff --git a/test/db/keyvalue.test.js b/test/db/keyvalue.test.js index 963f602..5b30338 100644 --- a/test/db/keyvalue.test.js +++ b/test/db/keyvalue.test.js @@ -147,22 +147,20 @@ describe('KeyValue Database', function () { it('deletes a key/value pair', async () => { const key = 'key1' - const expected = undefined await db.put(key, 'value1') - const hash = await db.del(key) + await db.del(key) - const actual = await db.get(hash) - strictEqual(actual, expected) + const actual = await db.get(key) + strictEqual(actual, undefined) }) it('deletes a non-existent key/value pair', async () => { - const expected = undefined + const key = 'this key doesn\'t exist' + await db.del(key) - const del = await db.del('zdpuApFgnZNp6qQqeuHRLJhEKsmMnXEEJfSZofLc3ZZXEihWE') - - const actual = await db.get(del) - strictEqual(actual, expected) + const actual = await db.get(key) + strictEqual(actual, undefined) }) it('returns all key/value pairs', async () => {