You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by gl...@apache.org on 2020/02/12 11:25:58 UTC

[couchdb-nano] 10/15: tidy up

This is an automated email from the ASF dual-hosted git repository.

glynnbird pushed a commit to branch jest
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git

commit e033ba07f6716541fa3f71666c7e188fae016557
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Fri Feb 7 16:39:39 2020 +0000

    tidy up
---
 lib/nano.js                               | 119 ++++++++++++++++++++----------
 test/database.changes.test.js             |  18 +++--
 test/database.compact.test.js             |  18 +++--
 test/database.create.test.js              |  18 +++--
 test/database.destroy.test.js             |  18 +++--
 test/database.get.test.js                 |  18 +++--
 test/database.replicate.test.js           |  31 +++-----
 test/database.replication.disable.test.js |  31 +++-----
 test/database.replication.enable.test.js  |  32 +++-----
 test/database.replication.query.test.js   |  18 +++--
 test/design.atomic.test.js                |   8 +-
 test/design.createIndex.test.js           |   4 +-
 test/design.find.test.js                  |   4 +-
 test/design.search.test.js                |   8 +-
 test/design.show.test.js                  |   8 +-
 test/design.view.test.js                  |   8 +-
 test/document.copy.test.js                |  22 +++++-
 test/document.destroy.test.js             |  14 +++-
 test/document.fetch.test.js               |  22 ++++--
 test/document.fetchRevs.test.js           |  28 ++++---
 test/document.get.test.js                 |  12 ++-
 test/document.head.test.js                |  14 +++-
 22 files changed, 283 insertions(+), 190 deletions(-)

diff --git a/lib/nano.js b/lib/nano.js
index d396acf..eb07b2d 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -17,6 +17,7 @@ const request = require('request')
 const errs = require('errs')
 const follow = require('cloudant-follow')
 const logger = require('./logger')
+const INVALID_PARAMETERS_ERROR = new Error('Invalid parameters')
 
 function isEmpty (val) {
   return val == null || !(Object.keys(val) || val).length
@@ -330,17 +331,27 @@ module.exports = exports = function dbScope (cfg) {
 
   // http://docs.couchdb.org/en/latest/api/database/common.html#put--db
   function createDb (dbName, qs0, callback0) {
+    const { opts, callback } = getCallback(qs0, callback0)
     if (!dbName) {
-      throw new Error('missing dbName')
+      const e = INVALID_PARAMETERS_ERROR
+      if (callback) {
+        return callback(e, null)
+      } else {
+        return Promise.reject(e)
+      }
     }
-    const { opts, callback } = getCallback(qs0, callback0)
     return relax({ db: dbName, method: 'PUT', qs: opts }, callback)
   }
 
   // http://docs.couchdb.org/en/latest/api/database/common.html#delete--db
   function destroyDb (dbName, callback) {
     if (!dbName) {
-      throw new Error('missing dbName')
+      const e = INVALID_PARAMETERS_ERROR
+      if (callback) {
+        return callback(e, null)
+      } else {
+        return Promise.reject(e)
+      }
     }
     return relax({ db: dbName, method: 'DELETE' }, callback)
   }
@@ -348,7 +359,12 @@ module.exports = exports = function dbScope (cfg) {
   // http://docs.couchdb.org/en/latest/api/database/common.html#get--db
   function getDb (dbName, callback) {
     if (!dbName) {
-      throw new Error('missing dbName')
+      const e = INVALID_PARAMETERS_ERROR
+      if (callback) {
+        return callback(e, null)
+      } else {
+        return Promise.reject(e)
+      }
     }
     return relax({ db: dbName }, callback)
   }
@@ -365,13 +381,18 @@ module.exports = exports = function dbScope (cfg) {
 
   // http://docs.couchdb.org/en/latest/api/database/compact.html#post--db-_compact
   function compactDb (dbName, ddoc, callback) {
-    if (!dbName) {
-      throw new Error('missing dbName')
-    }
     if (typeof ddoc === 'function') {
       callback = ddoc
       ddoc = null
     }
+    if (!dbName) {
+      const e = INVALID_PARAMETERS_ERROR
+      if (callback) {
+        return callback(e, null)
+      } else {
+        return Promise.reject(e)
+      }
+    }
     return relax({
       db: dbName,
       doc: '_compact',
@@ -384,7 +405,12 @@ module.exports = exports = function dbScope (cfg) {
   function changesDb (dbName, qs0, callback0) {
     const { opts, callback } = getCallback(qs0, callback0)
     if (!dbName) {
-      throw new Error('missing dbName')
+      const e = INVALID_PARAMETERS_ERROR
+      if (callback) {
+        return callback(e, null)
+      } else {
+        return Promise.reject(e)
+      }
     }
     return relax({ db: dbName, path: '_changes', qs: opts }, callback)
   }
@@ -422,11 +448,14 @@ module.exports = exports = function dbScope (cfg) {
   // http://docs.couchdb.org/en/latest/api/server/common.html#post--_replicate
   function replicateDb (source, target, opts0, callback0) {
     const { opts, callback } = getCallback(opts0, callback0)
-    if (!source) {
-      throw new Error('missing source')
-    }
-    if (!target) {
-      throw new Error('missing target')
+
+    if (!source || !target) {
+      const e = INVALID_PARAMETERS_ERROR
+      if (callback) {
+        return callback(e, null)
+      } else {
+        return Promise.reject(e)
+      }
     }
 
     // _replicate
@@ -448,11 +477,14 @@ module.exports = exports = function dbScope (cfg) {
   // http://guide.couchdb.org/draft/replication.html
   function enableReplication (source, target, opts0, callback0) {
     const { opts, callback } = getCallback(opts0, callback0)
-    if (!source) {
-      throw new Error('missing source')
-    }
-    if (!target) {
-      throw new Error('missing target')
+
+    if (!source || !target) {
+      const e = INVALID_PARAMETERS_ERROR
+      if (callback) {
+        return callback(e, null)
+      } else {
+        return Promise.reject(e)
+      }
     }
 
     // _replicator
@@ -466,7 +498,12 @@ module.exports = exports = function dbScope (cfg) {
   function queryReplication (id, opts0, callback0) {
     const { opts, callback } = getCallback(opts0, callback0)
     if (!id) {
-      throw new Error('missing id')
+      const e = INVALID_PARAMETERS_ERROR
+      if (callback) {
+        return callback(e, null)
+      } else {
+        return Promise.reject(e)
+      }
     }
     return relax({ db: '_replicator', method: 'GET', path: id, qs: opts }, callback)
   }
@@ -474,11 +511,13 @@ module.exports = exports = function dbScope (cfg) {
   // http://guide.couchdb.org/draft/replication.html
   function disableReplication (id, rev, opts0, callback0) {
     const { opts, callback } = getCallback(opts0, callback0)
-    if (!id) {
-      throw new Error('missing id')
-    }
-    if (!rev) {
-      throw new Error('missing rev')
+    if (!id || !rev) {
+      const e = INVALID_PARAMETERS_ERROR
+      if (callback) {
+        return callback(e, null)
+      } else {
+        return Promise.reject(e)
+      }
     }
     const req = {
       db: '_replicator',
@@ -519,7 +558,7 @@ module.exports = exports = function dbScope (cfg) {
     // http://docs.couchdb.org/en/latest/api/document/common.html#delete--db-docid
     function destroyDoc (docName, rev, callback) {
       if (!docName) {
-        const e = new Error('Invalid doc id')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
@@ -540,7 +579,7 @@ module.exports = exports = function dbScope (cfg) {
       const { opts, callback } = getCallback(qs0, callback0)
 
       if (!docName) {
-        const e = new Error('Invalid doc id')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
@@ -554,7 +593,7 @@ module.exports = exports = function dbScope (cfg) {
     // http://docs.couchdb.org/en/latest/api/document/common.html#head--db-docid
     function headDoc (docName, callback) {
       if (!docName) {
-        const e = new Error('Invalid doc id')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
@@ -593,7 +632,7 @@ module.exports = exports = function dbScope (cfg) {
       const { opts, callback } = getCallback(opts0, callback0)
 
       if (!docSrc || !docDest) {
-        const e = new Error('Invalid doc id')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
@@ -656,7 +695,7 @@ module.exports = exports = function dbScope (cfg) {
       if (!docNames || typeof docNames !== 'object' ||
           !docNames.keys || !Array.isArray(docNames.keys) ||
           docNames.keys.length === 0) {
-        const e = new Error('Invalid keys')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
@@ -679,7 +718,7 @@ module.exports = exports = function dbScope (cfg) {
       if (!docNames || typeof docNames !== 'object' ||
           !docNames.keys || !Array.isArray(docNames.keys) ||
           docNames.keys.length === 0) {
-        const e = new Error('Invalid keys')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
@@ -699,7 +738,7 @@ module.exports = exports = function dbScope (cfg) {
       const { opts, callback } = getCallback(qs0, callback0)
 
       if (!ddoc || !viewName) {
-        const e = new Error('Invalid view')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
@@ -786,7 +825,7 @@ module.exports = exports = function dbScope (cfg) {
     // http://docs.couchdb.org/en/latest/api/ddoc/render.html#get--db-_design-ddoc-_show-func
     function showDoc (ddoc, viewName, docName, qs, callback) {
       if (!ddoc || !viewName || !docName) {
-        const e = new Error('Invalid show')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
@@ -803,7 +842,7 @@ module.exports = exports = function dbScope (cfg) {
         body = undefined
       }
       if (!ddoc || !viewName || !docName) {
-        const e = new Error('Invalid update')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
@@ -846,7 +885,7 @@ module.exports = exports = function dbScope (cfg) {
       delete qs.docName
 
       if (!doc || !attachments || !docName) {
-        const e = new Error('Invalid parameters')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
@@ -889,7 +928,7 @@ module.exports = exports = function dbScope (cfg) {
       opts.attachments = true
 
       if (!docName) {
-        const e = new Error('Invalid parameters')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
@@ -909,7 +948,7 @@ module.exports = exports = function dbScope (cfg) {
     function insertAtt (docName, attName, att, contentType, qs0, callback0) {
       const { opts, callback } = getCallback(qs0, callback0)
       if (!docName || !attName || !att || !contentType) {
-        const e = new Error('Invalid parameters')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
@@ -945,7 +984,7 @@ module.exports = exports = function dbScope (cfg) {
     function getAtt (docName, attName, qs0, callback0) {
       const { opts, callback } = getCallback(qs0, callback0)
       if (!docName || !attName) {
-        const e = new Error('Invalid parameters')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
@@ -976,7 +1015,7 @@ module.exports = exports = function dbScope (cfg) {
 
     function destroyAtt (docName, attName, qs, callback) {
       if (!docName || !attName) {
-        const e = new Error('Invalid parameters')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
@@ -994,7 +1033,7 @@ module.exports = exports = function dbScope (cfg) {
 
     function find (query, callback) {
       if (!query || typeof query !== 'object') {
-        const e = new Error('Invalid query')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
@@ -1021,7 +1060,7 @@ module.exports = exports = function dbScope (cfg) {
 
     function createIndex (indexDef, callback) {
       if (!indexDef || typeof indexDef !== 'object') {
-        const e = new Error('Invalid index definition')
+        const e = INVALID_PARAMETERS_ERROR
         if (callback) {
           return callback(e, null)
         } else {
diff --git a/test/database.changes.test.js b/test/database.changes.test.js
index 4fb1e48..d176bef 100644
--- a/test/database.changes.test.js
+++ b/test/database.changes.test.js
@@ -71,14 +71,16 @@ test('should be able to handle a missing database - GET /db/_changes - nano.db.c
   expect(scope.isDone()).toBe(true)
 })
 
-test('should not attempt with empty dbName - nano.db.changes', async () => {
-  expect(() => {
-    nano.db.changes('')
-  }).toThrowError('missing dbName')
+test('should not attempt invalid parameters - nano.db.changes', async () => {
+  await expect(nano.db.changes()).rejects.toThrowError('Invalid parameters')
+  await expect(nano.db.changes('')).rejects.toThrowError('Invalid parameters')
 })
 
-test('should not attempt with missing dbName - nano.db.changes', async () => {
-  expect(() => {
-    nano.db.changes()
-  }).toThrowError('missing dbName')
+test('should detect missing parameters (callback) - nano.db.changes', async () => {
+  return new Promise((resolve, reject) => {
+    nano.db.changes(undefined, undefined, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
 })
diff --git a/test/database.compact.test.js b/test/database.compact.test.js
index 331e359..7fb3006 100644
--- a/test/database.compact.test.js
+++ b/test/database.compact.test.js
@@ -40,14 +40,16 @@ test('should be able to send compaction request with design doc - POST /db/_comp
   expect(scope.isDone()).toBe(true)
 })
 
-test('should not attempt compact with empty dbName - nano.db.compact', async () => {
-  expect(() => {
-    nano.db.compact('')
-  }).toThrowError('missing dbName')
+test('should not attempt compact with invalid parameters - nano.db.compact', async () => {
+  await expect(nano.db.compact('')).rejects.toThrowError('Invalid parameters')
+  await expect(nano.db.compact()).rejects.toThrowError('Invalid parameters')
 })
 
-test('should not attempt compact with missing dbName - nano.db.compact', async () => {
-  expect(() => {
-    nano.db.compact()
-  }).toThrowError('missing dbName')
+test('should detect missing parameters (callback) - nano.db.compact', async () => {
+  return new Promise((resolve, reject) => {
+    nano.db.compact(undefined, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
 })
diff --git a/test/database.create.test.js b/test/database.create.test.js
index 9feae75..ae461df 100644
--- a/test/database.create.test.js
+++ b/test/database.create.test.js
@@ -57,14 +57,16 @@ test('should handle pre-existing database - PUT /db - nano.db.create', async ()
   expect(scope.isDone()).toBe(true)
 })
 
-test('should not attempt to create database with empty database name - nano.db.create', async () => {
-  expect(() => {
-    nano.db.create('')
-  }).toThrowError('missing dbName')
+test('should not attempt to create database with invalid parameters - nano.db.create', async () => {
+  await expect(nano.db.create()).rejects.toThrowError('Invalid parameters')
+  await expect(nano.db.create('')).rejects.toThrowError('Invalid parameters')
 })
 
-test('should not attempt to create database with missing database name - nano.db.create', async () => {
-  expect(() => {
-    nano.db.create()
-  }).toThrowError('missing dbName')
+test('should detect missing parameters (callback) - nano.db.create', async () => {
+  return new Promise((resolve, reject) => {
+    nano.db.create(undefined, undefined, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
 })
diff --git a/test/database.destroy.test.js b/test/database.destroy.test.js
index 17f8189..659de5b 100644
--- a/test/database.destroy.test.js
+++ b/test/database.destroy.test.js
@@ -29,7 +29,7 @@ test('should destroy a database - DELETE /db - nano.db.destroy', async () => {
   expect(scope.isDone()).toBe(true)
 })
 
-test('should handle non-existant database - DELETE /db - nano.db.create', async () => {
+test('should handle non-existant database - DELETE /db - nano.db.destroy', async () => {
   // mocks
   const scope = nock(COUCH_URL)
     .delete('/db')
@@ -44,13 +44,15 @@ test('should handle non-existant database - DELETE /db - nano.db.create', async
 })
 
 test('should not attempt to destroy database with empty database name - nano.db.destroy', async () => {
-  expect(() => {
-    nano.db.destroy('')
-  }).toThrowError('missing dbName')
+  await expect(nano.db.destroy()).rejects.toThrowError('Invalid parameters')
+  await expect(nano.db.destroy('')).rejects.toThrowError('Invalid parameters')
 })
 
-test('should not attempt to destroy database with missing database name - nano.db.destroy', async () => {
-  expect(() => {
-    nano.db.destroy()
-  }).toThrowError('missing dbName')
+test('should detect missing parameters (callback) - nano.db.destroy', async () => {
+  return new Promise((resolve, reject) => {
+    nano.db.destroy(undefined, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
 })
diff --git a/test/database.get.test.js b/test/database.get.test.js
index 1098abc..ae9e421 100644
--- a/test/database.get.test.js
+++ b/test/database.get.test.js
@@ -84,14 +84,16 @@ test('should handle missing database - PUT /db - nano.db.create', async () => {
   expect(scope.isDone()).toBe(true)
 })
 
-test('should not attempt info fetch with empty dbName - nano.db.get', async () => {
-  expect(() => {
-    nano.db.get('')
-  }).toThrowError('missing dbName')
+test('should not attempt info fetch with missing parameters - nano.db.get', async () => {
+  await expect(nano.db.get()).rejects.toThrowError('Invalid parameters')
+  await expect(nano.db.get('')).rejects.toThrowError('Invalid parameters')
 })
 
-test('should not attempt info fetch with missing dbName - nano.db.get', async () => {
-  expect(() => {
-    nano.db.get()
-  }).toThrowError('missing dbName')
+test('should detect missing parameters (callback) - nano.db.get', async () => {
+  return new Promise((resolve, reject) => {
+    nano.db.get(undefined, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
 })
diff --git a/test/database.replicate.test.js b/test/database.replicate.test.js
index e2e86b2..19290d7 100644
--- a/test/database.replicate.test.js
+++ b/test/database.replicate.test.js
@@ -63,26 +63,17 @@ test('should be able to supply additional parameters - POST /_replicate - nano.d
   expect(scope.isDone()).toBe(true)
 })
 
-test('should not attempt compact with empty source - nano.db.replicate', async () => {
-  expect(() => {
-    nano.db.replicate('')
-  }).toThrowError('missing source')
+test('should not attempt compact invalid parameters - nano.db.replicate', async () => {
+  await expect(nano.db.replicate('')).rejects.toThrowError('Invalid parameters')
+  await expect(nano.db.replicate(undefined, 'target')).rejects.toThrowError('Invalid parameters')
+  await expect(nano.db.replicate('', 'target')).rejects.toThrowError('Invalid parameters')
 })
 
-test('should not attempt compact with missing source - nano.db.replicate', async () => {
-  expect(() => {
-    nano.db.replicate(undefined, 'target')
-  }).toThrowError('missing source')
-})
-
-test('should not attempt compact with empty target - nano.db.replicate', async () => {
-  expect(() => {
-    nano.db.replicate('', 'target')
-  }).toThrowError('missing source')
-})
-
-test('should not attempt compact with missing target - nano.db.replicate', async () => {
-  expect(() => {
-    nano.db.replicate(undefined, 'target')
-  }).toThrowError('missing source')
+test('should detect missing parameters (callback) - nano.db.replicate', async () => {
+  return new Promise((resolve, reject) => {
+    nano.db.replicate(undefined, undefined, undefined, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
 })
diff --git a/test/database.replication.disable.test.js b/test/database.replication.disable.test.js
index d01eec3..51fff73 100644
--- a/test/database.replication.disable.test.js
+++ b/test/database.replication.disable.test.js
@@ -45,26 +45,17 @@ test('should be able to handle a 404 - DELETE /_replicator - nano.db.replication
   expect(scope.isDone()).toBe(true)
 })
 
-test('should not to try to disable with missing id - nano.db.replication.disable', async () => {
-  expect(() => {
-    nano.db.replication.disable(undefined, '1-456')
-  }).toThrowError('missing id')
+test('should not to try to disable with invalid parameters - nano.db.replication.disable', async () => {
+  await expect(nano.db.replication.disable(undefined, '1-456')).rejects.toThrowError('Invalid parameters')
+  await expect(nano.db.replication.disable('', '1-456')).rejects.toThrowError('Invalid parameters')
+  await expect(nano.db.replication.disable('rep1')).rejects.toThrowError('Invalid parameters')
 })
 
-test('should not to try to disable with empty id - nano.db.replication.disable', async () => {
-  expect(() => {
-    nano.db.replication.disable('', '1-456')
-  }).toThrowError('missing id')
-})
-
-test('should not to try to disable with missing rev - nano.db.replication.disable', async () => {
-  expect(() => {
-    nano.db.replication.disable('rep1')
-  }).toThrowError('missing rev')
-})
-
-test('should not to try to disable with empty rev - nano.db.replication.disable', async () => {
-  expect(() => {
-    nano.db.replication.disable('rep1', '')
-  }).toThrowError('missing rev')
+test('should detect missing parameters (callback) - nano.db.replication.disable', async () => {
+  return new Promise((resolve, reject) => {
+    nano.db.replication.disable(undefined, undefined, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
 })
diff --git a/test/database.replication.enable.test.js b/test/database.replication.enable.test.js
index 4c7aebd..bb74f9a 100644
--- a/test/database.replication.enable.test.js
+++ b/test/database.replication.enable.test.js
@@ -57,26 +57,18 @@ test('should be able to supply additional parameters - POST /_replicator - nano.
   expect(scope.isDone()).toBe(true)
 })
 
-test('should not attempt compact with empty source - nano.db.replication.enable', async () => {
-  expect(() => {
-    nano.db.replication.enable('')
-  }).toThrowError('missing source')
+test('should not attempt compact with invalid parameters - nano.db.replication.enable', async () => {
+  await expect(nano.db.replication.enable(undefined, 'target')).rejects.toThrowError('Invalid parameters')
+  await expect(nano.db.replication.enable()).rejects.toThrowError('Invalid parameters')
+  await expect(nano.db.replication.enable('source')).rejects.toThrowError('Invalid parameters')
+  await expect(nano.db.replication.enable('source', '')).rejects.toThrowError('Invalid parameters')
 })
 
-test('should not attempt compact with missing source - nano.db.replication.enable', async () => {
-  expect(() => {
-    nano.db.replication.enable(undefined, 'target')
-  }).toThrowError('missing source')
-})
-
-test('should not attempt compact with empty target - nano.db.replication.enable', async () => {
-  expect(() => {
-    nano.db.replication.enable('', 'target')
-  }).toThrowError('missing source')
-})
-
-test('should not attempt compact with missing target - nano.db.replication.enable', async () => {
-  expect(() => {
-    nano.db.replication.enable(undefined, 'target')
-  }).toThrowError('missing source')
+test('should detect missing parameters (callback) - nano.db.replication.enable', async () => {
+  return new Promise((resolve, reject) => {
+    nano.db.replication.enable(undefined, undefined, undefined, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
 })
diff --git a/test/database.replication.query.test.js b/test/database.replication.query.test.js
index 0e36bb9..deff494 100644
--- a/test/database.replication.query.test.js
+++ b/test/database.replication.query.test.js
@@ -77,14 +77,16 @@ test('should be able to query a replication and handle 404 - GET /_replicator/id
   expect(scope.isDone()).toBe(true)
 })
 
-test('should not attempt info fetch with empty id - nano.db.replication.query', async () => {
-  expect(() => {
-    nano.db.replication.query('')
-  }).toThrowError('missing id')
+test('should not attempt info fetch with invalid parameters - nano.db.replication.query', async () => {
+  await expect(nano.db.replication.query('')).rejects.toThrowError('Invalid parameters')
+  await expect(nano.db.replication.query()).rejects.toThrowError('Invalid parameters')
 })
 
-test('should not attempt info fetch with missing id - nano.db.replication.query', async () => {
-  expect(() => {
-    nano.db.replication.query()
-  }).toThrowError('missing id')
+test('should detect missing parameters (callback) - nano.db.replication.query', async () => {
+  return new Promise((resolve, reject) => {
+    nano.db.replication.query(undefined, undefined, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
 })
diff --git a/test/design.atomic.test.js b/test/design.atomic.test.js
index 95c37fa..b0904aa 100644
--- a/test/design.atomic.test.js
+++ b/test/design.atomic.test.js
@@ -77,10 +77,10 @@ test('should be able to handle 404 - db.atomic', async () => {
 
 test('should detect missing parameters - db.update', async () => {
   const db = nano.db.use('db')
-  await expect(db.atomic()).rejects.toThrow('Invalid update')
-  await expect(db.atomic('ddoc')).rejects.toThrow('Invalid update')
-  await expect(db.atomic('ddoc', 'updatename')).rejects.toThrow('Invalid update')
-  await expect(db.atomic('', 'updatename', 'docid')).rejects.toThrow('Invalid update')
+  await expect(db.atomic()).rejects.toThrow('Invalid parameters')
+  await expect(db.atomic('ddoc')).rejects.toThrow('Invalid parameters')
+  await expect(db.atomic('ddoc', 'updatename')).rejects.toThrow('Invalid parameters')
+  await expect(db.atomic('', 'updatename', 'docid')).rejects.toThrow('Invalid parameters')
 })
 
 test('should detect missing parameters (callback) - db.update', async () => {
diff --git a/test/design.createIndex.test.js b/test/design.createIndex.test.js
index 1c7e7a5..88e0224 100644
--- a/test/design.createIndex.test.js
+++ b/test/design.createIndex.test.js
@@ -67,8 +67,8 @@ test('should handle 404 - POST /db/_index - db.index', async () => {
 
 test('should detect missing index - db.createIndex', async () => {
   const db = nano.db.use('db')
-  await expect(db.createIndex()).rejects.toThrow('Invalid index definition')
-  await expect(db.createIndex('myindex')).rejects.toThrow('Invalid index definition')
+  await expect(db.createIndex()).rejects.toThrow('Invalid parameters')
+  await expect(db.createIndex('myindex')).rejects.toThrow('Invalid parameters')
 })
 
 test('should detect missing index (callback) - db.createIndex', async () => {
diff --git a/test/design.find.test.js b/test/design.find.test.js
index 39bf9d3..b4aaba4 100644
--- a/test/design.find.test.js
+++ b/test/design.find.test.js
@@ -68,8 +68,8 @@ test('should handle 404 - POST /db/_find - db.find', async () => {
 
 test('should detect missing query - db.find', async () => {
   const db = nano.db.use('db')
-  await expect(db.find()).rejects.toThrow('Invalid query')
-  await expect(db.find('susan')).rejects.toThrow('Invalid query')
+  await expect(db.find()).rejects.toThrow('Invalid parameters')
+  await expect(db.find('susan')).rejects.toThrow('Invalid parameters')
 })
 
 test('should detect missing query (callback) - db.find', async () => {
diff --git a/test/design.search.test.js b/test/design.search.test.js
index 7be860c..8a5c37c 100644
--- a/test/design.search.test.js
+++ b/test/design.search.test.js
@@ -55,10 +55,10 @@ test('should be able to handle 404 - db.search', async () => {
 
 test('should detect missing parameters - db.search', async () => {
   const db = nano.db.use('db')
-  await expect(db.search()).rejects.toThrow('Invalid view')
-  await expect(db.search('susan')).rejects.toThrow('Invalid view')
-  await expect(db.search('susan', '')).rejects.toThrow('Invalid view')
-  await expect(db.search('', 'susan')).rejects.toThrow('Invalid view')
+  await expect(db.search()).rejects.toThrow('Invalid parameters')
+  await expect(db.search('susan')).rejects.toThrow('Invalid parameters')
+  await expect(db.search('susan', '')).rejects.toThrow('Invalid parameters')
+  await expect(db.search('', 'susan')).rejects.toThrow('Invalid parameters')
 })
 
 test('should detect missing parameters (callback) - db.search', async () => {
diff --git a/test/design.show.test.js b/test/design.show.test.js
index 258f1bb..4fc6278 100644
--- a/test/design.show.test.js
+++ b/test/design.show.test.js
@@ -49,10 +49,10 @@ test('should be able to handle 404 - db.show', async () => {
 
 test('should detect missing parameters - db.show', async () => {
   const db = nano.db.use('db')
-  await expect(db.show()).rejects.toThrow('Invalid show')
-  await expect(db.show('ddoc')).rejects.toThrow('Invalid show')
-  await expect(db.show('ddoc', 'showname')).rejects.toThrow('Invalid show')
-  await expect(db.show('', 'showname', 'docid')).rejects.toThrow('Invalid show')
+  await expect(db.show()).rejects.toThrow('Invalid parameters')
+  await expect(db.show('ddoc')).rejects.toThrow('Invalid parameters')
+  await expect(db.show('ddoc', 'showname')).rejects.toThrow('Invalid parameters')
+  await expect(db.show('', 'showname', 'docid')).rejects.toThrow('Invalid parameters')
 })
 
 test('should detect missing parameters (callback) - db.show', async () => {
diff --git a/test/design.view.test.js b/test/design.view.test.js
index 767b4f9..b53074d 100644
--- a/test/design.view.test.js
+++ b/test/design.view.test.js
@@ -147,10 +147,10 @@ test('should be able to handle 404 - db.view', async () => {
 
 test('should detect missing parameters - db.view', async () => {
   const db = nano.db.use('db')
-  await expect(db.view()).rejects.toThrow('Invalid view')
-  await expect(db.view('susan')).rejects.toThrow('Invalid view')
-  await expect(db.view('susan', '')).rejects.toThrow('Invalid view')
-  await expect(db.view('', 'susan')).rejects.toThrow('Invalid view')
+  await expect(db.view()).rejects.toThrow('Invalid parameters')
+  await expect(db.view('susan')).rejects.toThrow('Invalid parameters')
+  await expect(db.view('susan', '')).rejects.toThrow('Invalid parameters')
+  await expect(db.view('', 'susan')).rejects.toThrow('Invalid parameters')
 })
 
 test('should detect missing parameters (callback) - db.view', async () => {
diff --git a/test/document.copy.test.js b/test/document.copy.test.js
index 29d2d6a..9904313 100644
--- a/test/document.copy.test.js
+++ b/test/document.copy.test.js
@@ -31,12 +31,12 @@ test('should be able to copy a document - db.copy', async () => {
 
 test('should detect missing source doc id - db.copy', async () => {
   const db = nano.db.use('db')
-  await expect(db.copy(undefined, 'rabbbit2')).rejects.toThrow('Invalid doc id')
+  await expect(db.copy(undefined, 'rabbbit2')).rejects.toThrow('Invalid parameters')
 })
 
 test('should detect missing target doc id - db.copy', async () => {
   const db = nano.db.use('db')
-  await expect(db.copy('rabbit1')).rejects.toThrow('Invalid doc id')
+  await expect(db.copy('rabbit1')).rejects.toThrow('Invalid parameters')
 })
 
 test('should be able to copy a document in overwrite mode - db.copy', async () => {
@@ -74,3 +74,21 @@ test('should be able to copy a document in overwrite mode missing target - db.co
   expect(p).toStrictEqual(response)
   expect(scope.isDone()).toBe(true)
 })
+
+test('should detect invalid parameters - db.copy', async () => {
+  const db = nano.db.use('db')
+  await expect(db.copy()).rejects.toThrowError('Invalid parameters')
+  await expect(db.copy('')).rejects.toThrowError('Invalid parameters')
+  await expect(db.copy('', 'rabbit2')).rejects.toThrowError('Invalid parameters')
+  await expect(db.copy('rabbit1', '')).rejects.toThrowError('Invalid parameters')
+})
+
+test('should detect missing parameters (callback) - db.copy', async () => {
+  return new Promise((resolve, reject) => {
+    const db = nano.db.use('db')
+    db.copy(undefined, undefined, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
+})
diff --git a/test/document.destroy.test.js b/test/document.destroy.test.js
index 2177992..8c50f12 100644
--- a/test/document.destroy.test.js
+++ b/test/document.destroy.test.js
@@ -45,7 +45,17 @@ test('should be able to handle 409 conflicts - DELETE /db/id - db.destroy', asyn
   expect(scope.isDone()).toBe(true)
 })
 
-test('should detect missing doc id - db.destroy', async () => {
+test('should detect missing parameters - db.destroy', async () => {
   const db = nano.db.use('db')
-  await expect(db.destroy(undefined, '1-123')).rejects.toThrow('Invalid doc id')
+  await expect(db.destroy(undefined, '1-123')).rejects.toThrow('Invalid parameters')
+})
+
+test('should detect missing parameters (callback) - db.destroy', async () => {
+  return new Promise((resolve, reject) => {
+    const db = nano.db.use('db')
+    db.destroy(undefined, undefined, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
 })
diff --git a/test/document.fetch.test.js b/test/document.fetch.test.js
index 55281fc..c2056f9 100644
--- a/test/document.fetch.test.js
+++ b/test/document.fetch.test.js
@@ -150,11 +150,21 @@ test('should be able to handle 404 - POST /db/_all_docs - db.fetch', async () =>
   expect(scope.isDone()).toBe(true)
 })
 
-test('should detect missing keys - db.fetch', async () => {
+test('should detect invalid parameters - db.fetch', async () => {
   const db = nano.db.use('db')
-  await expect(db.fetch()).rejects.toThrow('Invalid keys')
-  await expect(db.fetch({})).rejects.toThrow('Invalid keys')
-  await expect(db.fetch({ keys: {} })).rejects.toThrow('Invalid keys')
-  await expect(db.fetch({ keys: '123' })).rejects.toThrow('Invalid keys')
-  await expect(db.fetch({ keys: [] })).rejects.toThrow('Invalid keys')
+  await expect(db.fetch()).rejects.toThrow('Invalid parameters')
+  await expect(db.fetch({})).rejects.toThrow('Invalid parameters')
+  await expect(db.fetch({ keys: {} })).rejects.toThrow('Invalid parameters')
+  await expect(db.fetch({ keys: '123' })).rejects.toThrow('Invalid parameters')
+  await expect(db.fetch({ keys: [] })).rejects.toThrow('Invalid parameters')
+})
+
+test('should detect missing parameters (callback) - db.fetch', async () => {
+  return new Promise((resolve, reject) => {
+    const db = nano.db.use('db')
+    db.fetch(undefined, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
 })
diff --git a/test/document.fetchRevs.test.js b/test/document.fetchRevs.test.js
index 80eda1c..4cf610d 100644
--- a/test/document.fetchRevs.test.js
+++ b/test/document.fetchRevs.test.js
@@ -15,7 +15,7 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
-test('should be able to fetch a list of document revisions - POST /db/_all_docs - db.fetch', async () => {
+test('should be able to fetch a list of document revisions - POST /db/_all_docs - db.fetchRevs', async () => {
   // mocks
   const keys = ['1000501', '1000543', '100077']
   const response = {
@@ -56,7 +56,7 @@ test('should be able to fetch a list of document revisions - POST /db/_all_docs
   expect(scope.isDone()).toBe(true)
 })
 
-test('should be able to fetch a list of document revisions  with opts - GET /db/_all_docs - db.fetch', async () => {
+test('should be able to fetch a list of document revisions  with opts - GET /db/_all_docs - db.fetchRevs', async () => {
   // mocks
   const keys = ['1000501', '1000543', '100077']
   const response = {
@@ -97,7 +97,7 @@ test('should be able to fetch a list of document revisions  with opts - GET /db/
   expect(scope.isDone()).toBe(true)
 })
 
-test('should be able to handle 404 - POST /db/_all_docs - db.fetch', async () => {
+test('should be able to handle 404 - POST /db/_all_docs - db.fetchRevs', async () => {
   // mocks
   const keys = ['1000501', '1000543', '100077']
   const response = {
@@ -114,11 +114,21 @@ test('should be able to handle 404 - POST /db/_all_docs - db.fetch', async () =>
   expect(scope.isDone()).toBe(true)
 })
 
-test('should detect missing keys - db.fetch', async () => {
+test('should detect missing parameters - db.fetchRevs', async () => {
   const db = nano.db.use('db')
-  await expect(db.fetchRevs()).rejects.toThrow('Invalid keys')
-  await expect(db.fetchRevs({})).rejects.toThrow('Invalid keys')
-  await expect(db.fetchRevs({ keys: {} })).rejects.toThrow('Invalid keys')
-  await expect(db.fetchRevs({ keys: '123' })).rejects.toThrow('Invalid keys')
-  await expect(db.fetchRevs({ keys: [] })).rejects.toThrow('Invalid keys')
+  await expect(db.fetchRevs()).rejects.toThrow('Invalid parameters')
+  await expect(db.fetchRevs({})).rejects.toThrow('Invalid parameters')
+  await expect(db.fetchRevs({ keys: {} })).rejects.toThrow('Invalid parameters')
+  await expect(db.fetchRevs({ keys: '123' })).rejects.toThrow('Invalid parameters')
+  await expect(db.fetchRevs({ keys: [] })).rejects.toThrow('Invalid parameters')
+})
+
+test('should detect missing parameters (callback) - db.fetchRevs', async () => {
+  return new Promise((resolve, reject) => {
+    const db = nano.db.use('db')
+    db.fetchRevs(undefined, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
 })
diff --git a/test/document.get.test.js b/test/document.get.test.js
index a2cfcca..001fd77 100644
--- a/test/document.get.test.js
+++ b/test/document.get.test.js
@@ -61,5 +61,15 @@ test('should be able to handle 404 - GET /db/id - db.get', async () => {
 
 test('should detect missing doc id - db.get', async () => {
   const db = nano.db.use('db')
-  await expect(db.get()).rejects.toThrow('Invalid doc id')
+  await expect(db.get()).rejects.toThrow('Invalid parameters')
+})
+
+test('should detect missing parameters (callback) - db.get', async () => {
+  return new Promise((resolve, reject) => {
+    const db = nano.db.use('db')
+    db.get(undefined, undefined, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
 })
diff --git a/test/document.head.test.js b/test/document.head.test.js
index dc2cb99..094b41a 100644
--- a/test/document.head.test.js
+++ b/test/document.head.test.js
@@ -60,7 +60,17 @@ test('should be able to head a missing document - HEAD /db/id - db.head', async
   expect(scope.isDone()).toBe(true)
 })
 
-test('should detect missing doc id - db.head', async () => {
+test('should detect missing parameters - db.head', async () => {
   const db = nano.db.use('db')
-  await expect(db.head()).rejects.toThrow('Invalid doc id')
+  await expect(db.head()).rejects.toThrow('Invalid parameters')
+})
+
+test('should detect missing parameters (callback) - db.head', async () => {
+  return new Promise((resolve, reject) => {
+    const db = nano.db.use('db')
+    db.head(undefined, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
 })