test: For a non-existent document.

This commit is contained in:
Hayden Young 2023-02-07 21:17:24 +00:00 committed by haad
parent 2af2f7d8fb
commit 2d425f7323
2 changed files with 49 additions and 36 deletions

View File

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

View File

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