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) => {
await queue.onIdle()
try {
const value = await index.get(key)
if (value) {
return value
}
} catch (e) {
// LEVEL_NOT_FOUND (ie. key not found)
}
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
}

View File

@ -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,
}
}

View File

@ -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 () => {

View File

@ -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 () => {