mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00
Fix tests for deleting a key-value pair
This commit is contained in:
parent
afe0ae8257
commit
611fb35330
@ -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
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 () => {
|
||||
|
@ -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 () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user