mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00
test: For a non-existent document.
This commit is contained in:
parent
2af2f7d8fb
commit
2d425f7323
@ -24,7 +24,7 @@ const DocumentStore = async ({ OpLog, Database, ipfs, identity, databaseId, acce
|
|||||||
* @returns {string} The hash of the new oplog entry.
|
* @returns {string} The hash of the new oplog entry.
|
||||||
*/
|
*/
|
||||||
const del = async (key) => {
|
const del = async (key) => {
|
||||||
if (!get(key)) { throw new Error(`No entry with key '${key}' in the database`) }
|
if (!await get(key)) { throw new Error(`No document with key '${key}' in the database`) }
|
||||||
|
|
||||||
return addOperation({ op: 'DEL', key, value: null })
|
return addOperation({ op: 'DEL', key, value: null })
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,20 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
|||||||
strictEqual(doc, undefined)
|
strictEqual(doc, undefined)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('queries a document', async () => {
|
it('throws an error when deleting a non-existent document', async () => {
|
||||||
|
const key = 'i do not exist'
|
||||||
|
let err
|
||||||
|
|
||||||
|
try {
|
||||||
|
await db1.del(key)
|
||||||
|
} catch (e) {
|
||||||
|
err = e
|
||||||
|
}
|
||||||
|
|
||||||
|
strictEqual(err.message, `No document with key \'${key}\' in the database`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('queries for a document', async () => {
|
||||||
const expected = { _id: 'hello world 1', msg: 'writing new 1 to db1', views: 10 }
|
const expected = { _id: 'hello world 1', msg: 'writing new 1 to db1', views: 10 }
|
||||||
|
|
||||||
await db1.put({ _id: 'hello world 1', msg: 'writing 1 to db1', views: 10 })
|
await db1.put({ _id: 'hello world 1', msg: 'writing 1 to db1', views: 10 })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user