Fix tests for deleting a key-value pair

This commit is contained in:
haad 2023-03-09 09:52:06 +02:00
parent afe0ae8257
commit 611fb35330
4 changed files with 17 additions and 32 deletions

View File

@ -35,16 +35,10 @@ const KeyValuePersisted = async ({ OpLog, Database, ipfs, identity, address, nam
const get = async (key) => { const get = async (key) => {
await queue.onIdle() await queue.onIdle()
try {
const value = await index.get(key) const value = await index.get(key)
if (value) { if (value) {
return value return value
} }
} catch (e) {
// LEVEL_NOT_FOUND (ie. key not found)
}
return keyValueStore.get(key) return keyValueStore.get(key)
} }
@ -58,7 +52,6 @@ const KeyValuePersisted = async ({ OpLog, Database, ipfs, identity, address, nam
const task = async () => { const task = async () => {
await queue.add(updateIndex(index)) await queue.add(updateIndex(index))
} }
// TODO: all()
const close = async () => { const close = async () => {
events.off('update', task) events.off('update', task)
@ -82,7 +75,6 @@ const KeyValuePersisted = async ({ OpLog, Database, ipfs, identity, address, nam
...keyValueStore, ...keyValueStore,
get, get,
iterator, iterator,
// TODO: all,
close, close,
drop drop
} }

View File

@ -40,8 +40,6 @@ const KeyValue = async ({ OpLog, Database, ipfs, identity, address, name, access
} }
} }
// TODO: all()
return { return {
...database, ...database,
type: 'keyvalue', type: 'keyvalue',
@ -50,7 +48,6 @@ const KeyValue = async ({ OpLog, Database, ipfs, identity, address, name, access
del, del,
get, get,
iterator iterator
// TODO: all,
} }
} }

View File

@ -155,22 +155,20 @@ describe('KeyValuePersisted Database', function () {
it('deletes a key/value pair', async () => { it('deletes a key/value pair', async () => {
const key = 'key1' const key = 'key1'
const expected = undefined
await db.put(key, 'value1') await db.put(key, 'value1')
const hash = await db.del(key) await db.del(key)
const actual = await db.get(hash) const actual = await db.get(key)
strictEqual(actual, expected) strictEqual(actual, undefined)
}) })
it('deletes a non-existent key/value pair', async () => { 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(key)
strictEqual(actual, undefined)
const actual = await db.get(del)
strictEqual(actual, expected)
}) })
it('returns all key/value pairs', async () => { it('returns all key/value pairs', async () => {

View File

@ -147,22 +147,20 @@ describe('KeyValue Database', function () {
it('deletes a key/value pair', async () => { it('deletes a key/value pair', async () => {
const key = 'key1' const key = 'key1'
const expected = undefined
await db.put(key, 'value1') await db.put(key, 'value1')
const hash = await db.del(key) await db.del(key)
const actual = await db.get(hash) const actual = await db.get(key)
strictEqual(actual, expected) strictEqual(actual, undefined)
}) })
it('deletes a non-existent key/value pair', async () => { 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(key)
strictEqual(actual, undefined)
const actual = await db.get(del)
strictEqual(actual, expected)
}) })
it('returns all key/value pairs', async () => { it('returns all key/value pairs', async () => {