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:26:00 UTC

[couchdb-nano] 12/15: 100% coverage

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 35ede5e80c9f13034617502b89cfc94b1fa22de1
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Mon Feb 10 10:44:06 2020 +0000

    100% coverage
---
 lib/logger.js                                      |   2 -
 lib/nano.js                                        |   1 +
 test/attachment.destroy.test.js                    |   4 +
 test/attachment.get.test.js                        |   5 +-
 test/attachment.getAsStream.test.js                |   5 +-
 test/attachment.insert.test.js                     |   5 +-
 test/attachment.insertAsStream.test.js             |   5 +-
 test/database.changes.test.js                      |  17 ++
 test/database.changesAsStream.test.js              |   4 +
 test/database.compact.test.js                      |  30 ++++
 test/database.create.test.js                       |   4 +
 test/database.destroy.test.js                      |   4 +
 test/database.follow.test.js                       |  26 +++
 test/database.get.test.js                          |   4 +
 test/database.list.test.js                         |   4 +
 test/database.listAsStream.test.js                 |   4 +
 test/database.replicate.test.js                    |  17 ++
 test/database.replication.disable.test.js          |  18 ++
 test/database.replication.enable.test.js           |  31 ++++
 test/database.replication.query.test.js            |  17 ++
 test/design.atomic.test.js                         |  14 ++
 test/design.createIndex.test.js                    |   4 +
 test/design.find.test.js                           |   4 +
 test/design.findAsStream.test.js                   |   4 +
 test/design.search.test.js                         |   4 +
 test/design.searchAsStream.test.js                 |   4 +
 test/design.show.test.js                           |   4 +
 test/design.view.test.js                           |   4 +
 test/design.viewAsStream.test.js                   |   4 +
 ...no.auth.test.js => design.viewWithList.test.js} |  19 +-
 test/document.bulk.test.js                         |   4 +
 test/document.copy.test.js                         |  50 ++++++
 test/document.destroy.test.js                      |   4 +
 test/document.fetch.test.js                        |   4 +
 test/document.fetchRevs.test.js                    |   4 +
 test/document.get.test.js                          |   4 +
 test/document.head.test.js                         |   4 +
 test/document.insert.test.js                       |   4 +
 test/document.list.test.js                         |   4 +
 test/document.listAsStream.test.js                 |   4 +
 test/multipart.get.test.js                         |   5 +-
 test/multipart.insert.test.js                      |   5 +-
 test/nano.auth.test.js                             |   6 +-
 test/nano.config.test.js                           |  39 ++++
 test/{nano.session.test.js => nano.logger.test.js} |  28 ++-
 test/nano.request.test.js                          | 200 ++++++++++++++++++++-
 test/nano.session.test.js                          |   4 +
 test/nano.timeout.test.js                          |  64 +++++++
 test/nano.updates.test.js                          |   4 +
 test/nano.uuids.test.js                            |  26 +++
 50 files changed, 711 insertions(+), 28 deletions(-)

diff --git a/lib/logger.js b/lib/logger.js
index 9f73271..87aa782 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -10,8 +10,6 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-'use strict'
-
 const debug = require('debug')('nano/logger')
 
 module.exports = function logging (cfg) {
diff --git a/lib/nano.js b/lib/nano.js
index 0ca315f..c1bcc23 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -469,6 +469,7 @@ module.exports = exports = function dbScope (cfg) {
   function uuids (count, callback) {
     if (typeof count === 'function') {
       callback = count
+      count = 1
     }
     count = count || 1
     return relax({ method: 'GET', path: '_uuids', qs: { count: count } }, callback)
diff --git a/test/attachment.destroy.test.js b/test/attachment.destroy.test.js
index d7b6450..0a225ff 100644
--- a/test/attachment.destroy.test.js
+++ b/test/attachment.destroy.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to destroy a document - DELETE /db/id/attname - db.attachment.destroy', async () => {
   // mocks
   const response = { ok: true, id: 'id', rev: '2-456' }
diff --git a/test/attachment.get.test.js b/test/attachment.get.test.js
index 61285d5..53638b1 100644
--- a/test/attachment.get.test.js
+++ b/test/attachment.get.test.js
@@ -14,9 +14,12 @@ const Nano = require('..')
 const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
-
 const image = Buffer.from('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to get an attachment - GET /db/id/attname - db.attachment.get', async () => {
   // mocks
   const scope = nock(COUCH_URL)
diff --git a/test/attachment.getAsStream.test.js b/test/attachment.getAsStream.test.js
index c5ad8eb..4598417 100644
--- a/test/attachment.getAsStream.test.js
+++ b/test/attachment.getAsStream.test.js
@@ -14,9 +14,12 @@ const Nano = require('..')
 const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
-
 const image = Buffer.from('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to get an attachment as a stream - GET /db/id/attname - db.attachment.get', async () => {
   // mocks
   const scope = nock(COUCH_URL)
diff --git a/test/attachment.insert.test.js b/test/attachment.insert.test.js
index 4f0809f..78ccad9 100644
--- a/test/attachment.insert.test.js
+++ b/test/attachment.insert.test.js
@@ -14,9 +14,12 @@ const Nano = require('..')
 const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
-
 const image = Buffer.from('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to insert document attachment - PUT /db/docname/attachment - db.attachment.insert', async () => {
   // mocks
   const response = { ok: true, id: 'docname', rev: '2-456' }
diff --git a/test/attachment.insertAsStream.test.js b/test/attachment.insertAsStream.test.js
index b805028..cc6a620 100644
--- a/test/attachment.insertAsStream.test.js
+++ b/test/attachment.insertAsStream.test.js
@@ -15,7 +15,6 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 const fs = require('fs')
-
 const image = Buffer.from(''.concat(
   'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAsV',
   'BMVEUAAAD////////////////////////5ur3rEBn////////////////wDBL/',
@@ -27,6 +26,10 @@ const image = Buffer.from(''.concat(
   'vaND1c8OG4vrdOqD8YwgpDYDxRgkSm5rwu0nQVBJuMg++pLXZyr5jnc1BaH4GT',
   'LvEliY253nA3pVhQqdPt0f/erJkMGMB8xucAAAAASUVORK5CYII='), 'base64')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to insert document attachment as stream - PUT /db/docname/attachment - db.attachment.insertAsStream', async () => {
   // mocks
   const response = { ok: true, id: 'docname', rev: '2-456' }
diff --git a/test/database.changes.test.js b/test/database.changes.test.js
index d176bef..e4a7216 100644
--- a/test/database.changes.test.js
+++ b/test/database.changes.test.js
@@ -34,6 +34,10 @@ const errResponse = {
   reason: 'Database does not exist.'
 }
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to fetch the changes - GET /db/_changes - nano.db.changes', async () => {
   // mocks
   const scope = nock(COUCH_URL)
@@ -84,3 +88,16 @@ test('should detect missing parameters (callback) - nano.db.changes', async () =
     })
   })
 })
+
+test('should be able to fetch the changes from db.changes - GET /db/_changes - db.changes', async () => {
+  // mocks
+  const scope = nock(COUCH_URL)
+    .get('/db/_changes')
+    .reply(200, response)
+
+  // test GET /db/_changes
+  const db = nano.db.use('db')
+  const p = await db.changes()
+  expect(p).toStrictEqual(response)
+  expect(scope.isDone()).toBe(true)
+})
diff --git a/test/database.changesAsStream.test.js b/test/database.changesAsStream.test.js
index adedbe8..adaf9f4 100644
--- a/test/database.changesAsStream.test.js
+++ b/test/database.changesAsStream.test.js
@@ -30,6 +30,10 @@ const response = {
   pending: 0
 }
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should get a streamed list of changes - GET /_changes - nano.db.changesAsStream', async () => {
   // mocks
   const scope = nock(COUCH_URL)
diff --git a/test/database.compact.test.js b/test/database.compact.test.js
index 7fb3006..420a5ac 100644
--- a/test/database.compact.test.js
+++ b/test/database.compact.test.js
@@ -16,6 +16,10 @@ const nano = Nano(COUCH_URL)
 const nock = require('nock')
 const response = { ok: true }
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to send compaction request - POST /db/_compact - nano.db.compact', async () => {
   // mocks
   const scope = nock(COUCH_URL)
@@ -53,3 +57,29 @@ test('should detect missing parameters (callback) - nano.db.compact', async () =
     })
   })
 })
+
+test('should be able to send compaction request from db.compact - POST /db/_compact - db.compact', async () => {
+  // mocks
+  const scope = nock(COUCH_URL)
+    .post('/db/_compact')
+    .reply(200, response)
+
+  // test POST /db/_compact
+  const db = nano.db.use('db')
+  const p = await db.compact()
+  expect(p).toEqual(response)
+  expect(scope.isDone()).toBe(true)
+})
+
+test('should be able to send compaction request with design doc from db.view.compact - POST /db/_compact - db.view.compact', async () => {
+  // mocks
+  const scope = nock(COUCH_URL)
+    .post('/db/_compact/ddoc')
+    .reply(200, response)
+
+  // test POST /db/_compact/ddoc
+  const db = nano.db.use('db')
+  const p = await db.view.compact('ddoc')
+  expect(p).toEqual(response)
+  expect(scope.isDone()).toBe(true)
+})
diff --git a/test/database.create.test.js b/test/database.create.test.js
index ae461df..099d415 100644
--- a/test/database.create.test.js
+++ b/test/database.create.test.js
@@ -16,6 +16,10 @@ const nano = Nano(COUCH_URL)
 const nock = require('nock')
 const response = { ok: true }
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should create a database - PUT /db - nano.db.create', async () => {
   // mocks
   const scope = nock(COUCH_URL)
diff --git a/test/database.destroy.test.js b/test/database.destroy.test.js
index 659de5b..8174c7a 100644
--- a/test/database.destroy.test.js
+++ b/test/database.destroy.test.js
@@ -16,6 +16,10 @@ const nano = Nano(COUCH_URL)
 const nock = require('nock')
 const response = { ok: true }
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should destroy a database - DELETE /db - nano.db.destroy', async () => {
   // mocks
   const scope = nock(COUCH_URL)
diff --git a/test/database.follow.test.js b/test/database.follow.test.js
index 870a7bf..7218a89 100644
--- a/test/database.follow.test.js
+++ b/test/database.follow.test.js
@@ -13,6 +13,11 @@
 const Nano = require('..')
 const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
+const nock = require('nock')
+
+afterEach(() => {
+  nock.cleanAll()
+})
 
 test('should be able to follow changes feed - nano.db.follow', () => {
   const db = nano.db.use('db')
@@ -20,3 +25,24 @@ test('should be able to follow changes feed - nano.db.follow', () => {
   expect(feed.constructor.name).toBe('Feed')
   // no need to test the changes feed follower - it has its own tests
 })
+
+test('should be able to follow changes feed (callback) - nano.db.follow', async () => {
+  // mocks
+  const scope = nock(COUCH_URL)
+    .get('/db')
+    .reply(404, {
+      error: 'not_found',
+      reason: 'Database does not exist.'
+    })
+
+  return new Promise((resolve, reject) => {
+    const db = nano.db.use('db')
+    const feed = db.follow({ since: 'now' }, (err, data) => {
+      expect(err).not.toBeNull()
+      expect(scope.isDone()).toBe(true)
+      resolve()
+    })
+    expect(feed.constructor.name).toBe('Feed')
+  })
+  // no need to test the changes feed follower - it has its own tests
+})
diff --git a/test/database.get.test.js b/test/database.get.test.js
index ae9e421..454940d 100644
--- a/test/database.get.test.js
+++ b/test/database.get.test.js
@@ -41,6 +41,10 @@ const response = {
   instance_start_time: '0'
 }
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to fetch the database info - GET /db - nano.db.get', async () => {
   // mocks
   const scope = nock(COUCH_URL)
diff --git a/test/database.list.test.js b/test/database.list.test.js
index f83dc74..e07c4ea 100644
--- a/test/database.list.test.js
+++ b/test/database.list.test.js
@@ -16,6 +16,10 @@ const nano = Nano(COUCH_URL)
 const nock = require('nock')
 const response = ['rita', 'sue', 'bob']
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be to get list of databases - GET /_all_dbs - nano.db.list', async () => {
   // mocks
   const scope = nock(COUCH_URL)
diff --git a/test/database.listAsStream.test.js b/test/database.listAsStream.test.js
index 25b6ed2..f887dd6 100644
--- a/test/database.listAsStream.test.js
+++ b/test/database.listAsStream.test.js
@@ -16,6 +16,10 @@ const nano = Nano(COUCH_URL)
 const nock = require('nock')
 const response = ['rita', 'sue', 'bob']
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should get a streamed list of databases - GET /_all_dbs - nano.db.listAsStream', async () => {
   // mocks
   const scope = nock(COUCH_URL)
diff --git a/test/database.replicate.test.js b/test/database.replicate.test.js
index 19290d7..a133cf8 100644
--- a/test/database.replicate.test.js
+++ b/test/database.replicate.test.js
@@ -22,6 +22,10 @@ const response = {
   source_last_seq: 28
 }
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to send replication request with local database names- POST /_replicate - nano.db.replicate', async () => {
   // mocks
   const scope = nock(COUCH_URL)
@@ -77,3 +81,16 @@ test('should detect missing parameters (callback) - nano.db.replicate', async ()
     })
   })
 })
+
+test('should be replicate from db.replicate - POST /_replicate - db.replicate', async () => {
+  // mocks
+  const scope = nock(COUCH_URL)
+    .post('/_replicate', { source: COUCH_URL + '/source', target: COUCH_URL + '/target' })
+    .reply(200, response)
+
+  // test POST /_replicate
+  const db = nano.db.use('source')
+  const p = await db.replicate('target')
+  expect(p).toEqual(response)
+  expect(scope.isDone()).toBe(true)
+})
diff --git a/test/database.replication.disable.test.js b/test/database.replication.disable.test.js
index 51fff73..da76cfc 100644
--- a/test/database.replication.disable.test.js
+++ b/test/database.replication.disable.test.js
@@ -20,6 +20,10 @@ const errResponse = {
   reason: 'missing'
 }
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to delete a replication - DELETE /_replicator - nano.db.replication.disable', async () => {
   // mocks
   const scope = nock(COUCH_URL)
@@ -59,3 +63,17 @@ test('should detect missing parameters (callback) - nano.db.replication.disable'
     })
   })
 })
+
+test('should be able to delete a replication from db.replication.disable - DELETE /_replicator - db.replication.disable', async () => {
+  // mocks
+  const scope = nock(COUCH_URL)
+    .delete('/_replicator/rep1')
+    .query({ rev: '1-456' })
+    .reply(200, response)
+
+  // test DELETE /_replicator/id
+  const db = nano.db.use('db')
+  const p = await db.replication.disable('rep1', '1-456')
+  expect(p).toEqual(response)
+  expect(scope.isDone()).toBe(true)
+})
diff --git a/test/database.replication.enable.test.js b/test/database.replication.enable.test.js
index bb74f9a..7fda367 100644
--- a/test/database.replication.enable.test.js
+++ b/test/database.replication.enable.test.js
@@ -16,6 +16,10 @@ const nano = Nano(COUCH_URL)
 const nock = require('nock')
 const response = { ok: true, id: 'abc', rev: '1-123' }
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to send replication request with local database names - POST /_replicator - nano.db.replication.enable', async () => {
   // mocks
   const scope = nock(COUCH_URL)
@@ -42,6 +46,20 @@ test('should be able to send replication request with URLs - POST /_replicator -
   expect(scope.isDone()).toBe(true)
 })
 
+test('should be able to send replication request with objects - POST /_replicator - nano.db.replication.enable', async () => {
+  // mocks
+  const source = { config: { url: 'http://mydomain1.com', db: 'source' } }
+  const target = { config: { url: 'https://mydomain2.com', db: 'target' } }
+  const scope = nock(COUCH_URL)
+    .post('/_replicator', { source: 'http://mydomain1.com/source', target: 'https://mydomain2.com/target' })
+    .reply(200, response)
+
+  // test POST /_replicator
+  const p = await nano.db.replication.enable(source, target)
+  expect(p).toEqual(response)
+  expect(scope.isDone()).toBe(true)
+})
+
 test('should be able to supply additional parameters - POST /_replicator - nano.db.replication.enable', async () => {
   // mocks
   const source = 'http://mydomain1.com/source'
@@ -72,3 +90,16 @@ test('should detect missing parameters (callback) - nano.db.replication.enable',
     })
   })
 })
+
+test('should be able to send replication request db.replication.enable - POST /_replicator - db.replication.enable', async () => {
+  // mocks
+  const scope = nock(COUCH_URL)
+    .post('/_replicator', { source: COUCH_URL + '/source', target: COUCH_URL + '/target' })
+    .reply(200, response)
+
+  // test POST /_replicator
+  const db = nano.db.use('source')
+  const p = await db.replication.enable('target')
+  expect(p).toEqual(response)
+  expect(scope.isDone()).toBe(true)
+})
diff --git a/test/database.replication.query.test.js b/test/database.replication.query.test.js
index deff494..368511a 100644
--- a/test/database.replication.query.test.js
+++ b/test/database.replication.query.test.js
@@ -40,6 +40,10 @@ const errResponse = {
   reason: 'missing'
 }
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to query a replication - GET /_replicator/id - nano.db.replication.query', async () => {
   // mocks
   const scope = nock(COUCH_URL)
@@ -90,3 +94,16 @@ test('should detect missing parameters (callback) - nano.db.replication.query',
     })
   })
 })
+
+test('should be able to query a replication from db.replication.quey - GET /_replicator/id - db.replication.query', async () => {
+  // mocks
+  const scope = nock(COUCH_URL)
+    .get('/_replicator/rep1')
+    .reply(200, response)
+
+  // test GET /_replicator/id
+  const db = nano.db.use('db')
+  const p = await db.replication.query('rep1')
+  expect(p).toEqual(response)
+  expect(scope.isDone()).toBe(true)
+})
diff --git a/test/design.atomic.test.js b/test/design.atomic.test.js
index b0904aa..0382943 100644
--- a/test/design.atomic.test.js
+++ b/test/design.atomic.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to use an update function - PUT /db/_design/ddoc/_update/updatename/docid - db.atomic', async () => {
   const updateFunction = function (doc, req) {
     if (doc) {
@@ -92,3 +96,13 @@ test('should detect missing parameters (callback) - db.update', async () => {
     })
   })
 })
+
+test('should detect missing parameters (callback no body) - db.update', async () => {
+  const db = nano.db.use('db')
+  return new Promise((resolve, reject) => {
+    db.atomic('', '', '', (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
+})
diff --git a/test/design.createIndex.test.js b/test/design.createIndex.test.js
index 88e0224..bd7bdcc 100644
--- a/test/design.createIndex.test.js
+++ b/test/design.createIndex.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to create an index - POST /db/_index - db.index', async () => {
   // mocks
   const indexDef = {
diff --git a/test/design.find.test.js b/test/design.find.test.js
index b4aaba4..b0990f3 100644
--- a/test/design.find.test.js
+++ b/test/design.find.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to query an index - POST /db/_find - db.find', async () => {
   // mocks
   const query = {
diff --git a/test/design.findAsStream.test.js b/test/design.findAsStream.test.js
index b330779..cb7f298 100644
--- a/test/design.findAsStream.test.js
+++ b/test/design.findAsStream.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to query an index as a stream- POST /db/_find - db.findAsStream', async () => {
   // mocks
   const query = {
diff --git a/test/design.search.test.js b/test/design.search.test.js
index 8a5c37c..e7e8e42 100644
--- a/test/design.search.test.js
+++ b/test/design.search.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to access a search index - POST /db/_design/ddoc/_search/searchname - db.search', async () => {
   // mocks
   const response = {
diff --git a/test/design.searchAsStream.test.js b/test/design.searchAsStream.test.js
index d86f35d..565d604 100644
--- a/test/design.searchAsStream.test.js
+++ b/test/design.searchAsStream.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to access a search index as a stream - POST /db/_design/ddoc/_search/searchname - db.searchAsStream', async () => {
   // mocks
   const response = {
diff --git a/test/design.show.test.js b/test/design.show.test.js
index 4fc6278..1097e89 100644
--- a/test/design.show.test.js
+++ b/test/design.show.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to use a show function - GET /db/_design/ddoc/_show/showname/docid - db.show', async () => {
   const showFunction = function (doc, req) {
     return 'Hello, world!'
diff --git a/test/design.view.test.js b/test/design.view.test.js
index b53074d..7a62626 100644
--- a/test/design.view.test.js
+++ b/test/design.view.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to access a MapReduce view - GET /db/_design/ddoc/_view/viewname - db.view', async () => {
   // mocks
   const response = {
diff --git a/test/design.viewAsStream.test.js b/test/design.viewAsStream.test.js
index e332897..2ec4b0a 100644
--- a/test/design.viewAsStream.test.js
+++ b/test/design.viewAsStream.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to access a MapReduce view as a stream - GET /db/_design/ddoc/_view/viewname - db.viewAsStream', async () => {
   // mocks
   const response = {
diff --git a/test/nano.auth.test.js b/test/design.viewWithList.test.js
similarity index 64%
copy from test/nano.auth.test.js
copy to test/design.viewWithList.test.js
index f952887..92bb7f6 100644
--- a/test/nano.auth.test.js
+++ b/test/design.viewWithList.test.js
@@ -15,17 +15,20 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
-test('should be able to authenticate - POST /_session - nano.auth', async () => {
+afterEach(() => {
+  nock.cleanAll()
+})
+
+test('should be able to access a MapReduce view with a list - GET /db/_design/ddoc/_list/listname/viewname - db.viewWithList', async () => {
   // mocks
-  const username = 'u'
-  const password = 'p'
-  const response = { ok: true, name: 'admin', roles: ['_admin', 'admin'] }
+  const response = '1,2,3\n4,5,6\n7,8,9\n'
   const scope = nock(COUCH_URL)
-    .post('/_session', 'name=u&password=p', { 'content-type': 'application/x-www-form-urlencoded; charset=utf-8' })
-    .reply(200, response)
+    .get('/db/_design/ddoc/_list/listname/viewname')
+    .reply(200, response, { 'Content-type': 'text/csv' })
 
-  // test GET /_uuids
-  const p = await nano.auth(username, password)
+  // test GET /db
+  const db = nano.db.use('db')
+  const p = await db.viewWithList('ddoc', 'viewname', 'listname')
   expect(p).toStrictEqual(response)
   expect(scope.isDone()).toBe(true)
 })
diff --git a/test/document.bulk.test.js b/test/document.bulk.test.js
index 672df9d..a3cd304 100644
--- a/test/document.bulk.test.js
+++ b/test/document.bulk.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to insert documents in bulk - POST /db/_bulk_docs - db.bulk', async () => {
   // mocks
   const docs = [{ a: 1, b: 2 }, { a: 2, b: 3 }, { a: 3, b: 4 }]
diff --git a/test/document.copy.test.js b/test/document.copy.test.js
index 9904313..e5eb7d7 100644
--- a/test/document.copy.test.js
+++ b/test/document.copy.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to copy a document - db.copy', async () => {
   // mocks
   const response = { ok: true, id: 'rabbit2', rev: '1-123' }
@@ -55,6 +59,52 @@ test('should be able to copy a document in overwrite mode - db.copy', async () =
   expect(scope.isDone()).toBe(true)
 })
 
+test('should be able to handle an error  in overwrite mode # 1 - db.copy', async () => {
+  // mocks
+  const response = 'Internal server error'
+  const scope = nock(COUCH_URL)
+    .head('/db/rabbit2')
+    .reply(200, '', { ETag: '1-123' })
+    .intercept('/db/rabbit1', 'COPY')
+    .reply(500, response)
+
+  // test GET /db
+  const db = nano.db.use('db')
+  await expect(db.copy('rabbit1', 'rabbit2', { overwrite: true })).rejects.toThrow(response)
+  expect(scope.isDone()).toBe(true)
+})
+
+test('should be able to handle an error  in overwrite mode # 2 - db.copy', async () => {
+  // mocks
+  const response = 'Internal server error'
+  const scope = nock(COUCH_URL)
+    .head('/db/rabbit2')
+    .reply(500, response)
+
+  // test GET /db
+  const db = nano.db.use('db')
+  await expect(db.copy('rabbit1', 'rabbit2', { overwrite: true })).rejects.toThrow(response)
+  expect(scope.isDone()).toBe(true)
+})
+
+test('should be able to handle an error  in overwrite mode # 3 - db.copy', async () => {
+  // mocks
+  const response = 'Internal server error'
+  const scope = nock(COUCH_URL)
+    .head('/db/rabbit2')
+    .reply(500, response)
+
+  // test GET /db
+  return new Promise((resolve, reject) => {
+    const db = nano.db.use('db')
+    db.copy('rabbit1', 'rabbit2', { overwrite: true }, (err, data) => {
+      expect(err).not.toBeNull()
+      expect(scope.isDone()).toBe(true)
+      resolve()
+    })
+  })
+})
+
 test('should be able to copy a document in overwrite mode missing target - db.copy', async () => {
   // mocks
   const response = { ok: true, id: 'rabbit2', rev: '1-123' }
diff --git a/test/document.destroy.test.js b/test/document.destroy.test.js
index 8c50f12..2958d27 100644
--- a/test/document.destroy.test.js
+++ b/test/document.destroy.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to destroy a document - DELETE /db/id - db.destroy', async () => {
   // mocks
   const response = { ok: true, id: 'id', rev: '2-456' }
diff --git a/test/document.fetch.test.js b/test/document.fetch.test.js
index c2056f9..bde243b 100644
--- a/test/document.fetch.test.js
+++ b/test/document.fetch.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to fetch a list of documents - POST /db/_all_docs - db.fetch', async () => {
   // mocks
   const keys = ['1000501', '1000543', '100077']
diff --git a/test/document.fetchRevs.test.js b/test/document.fetchRevs.test.js
index 4cf610d..aa6f3fa 100644
--- a/test/document.fetchRevs.test.js
+++ b/test/document.fetchRevs.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to fetch a list of document revisions - POST /db/_all_docs - db.fetchRevs', async () => {
   // mocks
   const keys = ['1000501', '1000543', '100077']
diff --git a/test/document.get.test.js b/test/document.get.test.js
index 001fd77..109b7cb 100644
--- a/test/document.get.test.js
+++ b/test/document.get.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to get a document - GET /db/id - db.get', async () => {
   // mocks
   const response = { _id: 'id', rev: '1-123', a: 1, b: 'two', c: true }
diff --git a/test/document.head.test.js b/test/document.head.test.js
index 094b41a..0dfd9f1 100644
--- a/test/document.head.test.js
+++ b/test/document.head.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to head a document - HEAD /db/id - db.head', async () => {
   // mocks
   const scope = nock(COUCH_URL)
diff --git a/test/document.insert.test.js b/test/document.insert.test.js
index 812775b..60f1696 100644
--- a/test/document.insert.test.js
+++ b/test/document.insert.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to insert document - POST /db - db.insert', async () => {
   // mocks
   const doc = { a: 1, b: 2 }
diff --git a/test/document.list.test.js b/test/document.list.test.js
index 3e0705f..53fc245 100644
--- a/test/document.list.test.js
+++ b/test/document.list.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to get a list of documents - GET /db/_all_docs - db.list', async () => {
   // mocks
   const response = {
diff --git a/test/document.listAsStream.test.js b/test/document.listAsStream.test.js
index 45cdf49..c4a6c03 100644
--- a/test/document.listAsStream.test.js
+++ b/test/document.listAsStream.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should get a streamed list of documents - GET /db/_all_docs - db.listAsStream', async () => {
   // mocks
   const response = {
diff --git a/test/multipart.get.test.js b/test/multipart.get.test.js
index 6383367..2db92eb 100644
--- a/test/multipart.get.test.js
+++ b/test/multipart.get.test.js
@@ -14,7 +14,6 @@ const Nano = require('..')
 const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
-
 const multipartResponse = ''.concat(
   '--e89b3e29388aef23453450d10e5aaed0',
   'Content-Type: application/json',
@@ -33,6 +32,10 @@ const multipartResponse = ''.concat(
   '',
   '--e89b3e29388aef23453450d10e5aaed0--')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to fetch a document with attachments - multipart GET /db - db.multipart.get', async () => {
   // mocks
   const scope = nock(COUCH_URL, { reqheaders: { accept: 'multipart/related' } })
diff --git a/test/multipart.insert.test.js b/test/multipart.insert.test.js
index 2982bc5..43f46b1 100644
--- a/test/multipart.insert.test.js
+++ b/test/multipart.insert.test.js
@@ -14,7 +14,6 @@ const Nano = require('..')
 const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
-
 const image1 = Buffer.from(''.concat(
   'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAsV',
   'BMVEUAAAD////////////////////////5ur3rEBn////////////////wDBL/',
@@ -47,6 +46,10 @@ const doc = {
   }
 }
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to insert a document with attachments #1 - multipart POST /db - db.multipart.insert', async () => {
   // mocks
   const response = { ok: true, id: '8s8g8h8h9', rev: '1-123' }
diff --git a/test/nano.auth.test.js b/test/nano.auth.test.js
index f952887..fe6af9b 100644
--- a/test/nano.auth.test.js
+++ b/test/nano.auth.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to authenticate - POST /_session - nano.auth', async () => {
   // mocks
   const username = 'u'
@@ -22,7 +26,7 @@ test('should be able to authenticate - POST /_session - nano.auth', async () =>
   const response = { ok: true, name: 'admin', roles: ['_admin', 'admin'] }
   const scope = nock(COUCH_URL)
     .post('/_session', 'name=u&password=p', { 'content-type': 'application/x-www-form-urlencoded; charset=utf-8' })
-    .reply(200, response)
+    .reply(200, response, { 'Set-Cookie': 'AuthSession=YWRtaW46NUU0MTFBMDE6stHsxYnlDy4mYxwZEcnXHn4fm5w; Version=1; Expires=Mon, 10-Feb-2050 09:03:21 GMT; Max-Age=600; Path=/; HttpOnly' })
 
   // test GET /_uuids
   const p = await nano.auth(username, password)
diff --git a/test/nano.config.test.js b/test/nano.config.test.js
index 72de445..16c02b5 100644
--- a/test/nano.config.test.js
+++ b/test/nano.config.test.js
@@ -11,6 +11,7 @@
 // the License.
 
 const Nano = require('..')
+const assert = require('assert')
 
 test('should be able to supply HTTP url - nano.config', () => {
   const HTTP_URL = 'http://localhost:5984'
@@ -61,3 +62,41 @@ test('should be able to supply logging function - nano.config', () => {
   expect(nano.config.url).toBe(HTTPS_URL)
   expect(typeof nano.config.log).toBe('function')
 })
+
+test('should be able to handle missing URL - nano.config', () => {
+  try {
+    Nano()
+  } catch (e) {
+    expect(e instanceof assert.AssertionError)
+    expect(e.message).toBe('You must specify the endpoint url when invoking this module')
+  }
+})
+
+test('should be able to handle invalid URL #1 - nano.config', () => {
+  const INVALID_URL = 'badurl.com'
+  try {
+    Nano(INVALID_URL)
+  } catch (e) {
+    expect(e instanceof assert.AssertionError)
+    expect(e.message).toBe('url is not valid')
+  }
+})
+
+test('should be able to handle invalid URL #2 - nano.config', () => {
+  const INVALID_URL = 'badurl.com'
+  try {
+    Nano({ url: INVALID_URL })
+  } catch (e) {
+    expect(e instanceof assert.AssertionError)
+    expect(e.message).toBe('url is not valid')
+  }
+})
+
+test('exercise the parseUrl feature for proxies etc - nano.config', () => {
+  const HTTP_URL = 'http://localhost:5984/prefix'
+  const nano = Nano({
+    url: HTTP_URL,
+    parseUrl: false
+  })
+  expect(nano.config.url).toBe(HTTP_URL)
+})
diff --git a/test/nano.session.test.js b/test/nano.logger.test.js
similarity index 62%
copy from test/nano.session.test.js
copy to test/nano.logger.test.js
index ca2eb97..a6ae009 100644
--- a/test/nano.session.test.js
+++ b/test/nano.logger.test.js
@@ -10,20 +10,34 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
+const nock = require('nock')
 const Nano = require('..')
 const COUCH_URL = 'http://localhost:5984'
-const nano = Nano(COUCH_URL)
-const nock = require('nock')
 
-test('should be able to check your session - GET /_session - nano.auth', async () => {
+afterEach(() => {
+  nock.cleanAll()
+})
+
+test('should be able to log output with user-defined function', async () => {
+  // setup Nano with custom logger
+  const logs = []
+  const nano = Nano({
+    url: COUCH_URL,
+    log: (data) => {
+      logs.push(data)
+    }
+  })
+
   // mocks
-  const response = { ok: true, userCtx: { name: null, roles: [] }, info: { authentication_db: '_users', authentication_handlers: ['cookie', 'default'] } }
+  const response = { _id: 'id', rev: '1-123', a: 1, b: 'two', c: true }
   const scope = nock(COUCH_URL)
-    .get('/_session')
+    .get('/db/id')
     .reply(200, response)
 
-  // test GET /_uuids
-  const p = await nano.session()
+  // test GET /db
+  const db = nano.db.use('db')
+  const p = await db.get('id')
   expect(p).toStrictEqual(response)
+  expect(logs.length).toBe(2)
   expect(scope.isDone()).toBe(true)
 })
diff --git a/test/nano.request.test.js b/test/nano.request.test.js
index 045071d..40b0e86 100644
--- a/test/nano.request.test.js
+++ b/test/nano.request.test.js
@@ -11,10 +11,14 @@
 // the License.
 
 const Nano = require('..')
-const COUCH_URL = 'http://localhost:5984'
-const nano = Nano(COUCH_URL)
+const COUCH_URL = 'http://localhost:59804'
+const nano = Nano({ url: COUCH_URL, cookie: true })
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('check request can do GET requests - nano.request', async () => {
   // mocks
   const response = { ok: true }
@@ -36,15 +40,16 @@ test('check request can do GET requests - nano.request', async () => {
 test('check request can do POST requests - nano.request', async () => {
   // mocks
   const response = { ok: true }
+  const doc = { _id: '_design/myddoc', a: true }
   const scope = nock(COUCH_URL)
-    .post('/db', { _id: '1', a: true })
+    .post('/db', doc)
     .reply(200, response)
 
   // test POST /db
   const req = {
     method: 'post',
     db: 'db',
-    body: { _id: '1', a: true }
+    body: doc
   }
   const p = await nano.request(req)
   expect(p).toStrictEqual(response)
@@ -282,3 +287,190 @@ test('check request formats key properly - nano.request', async () => {
   expect(p).toStrictEqual(response)
   expect(scope.isDone()).toBe(true)
 })
+
+test('check request can do 500s - nano.request', async () => {
+  // mocks
+  const errorMessage = 'Internal server error'
+  const scope = nock(COUCH_URL)
+    .get('/db?a=1&b=2')
+    .reply(500, errorMessage)
+
+  // test GET /db?a=1&b=2
+  const req = {
+    method: 'get',
+    db: 'db',
+    qs: { a: 1, b: 2 }
+  }
+  await expect(nano.request(req)).rejects.toThrow(errorMessage)
+  expect(scope.isDone()).toBe(true)
+})
+
+test('check request can do 500s with callback - nano.request', async () => {
+  // mocks
+  const errorMessage = 'Internal server error'
+  const scope = nock(COUCH_URL)
+    .get('/db?a=1&b=2')
+    .reply(500, errorMessage)
+
+  // test GET /db?a=1&b=2
+  const req = {
+    method: 'get',
+    db: 'db',
+    qs: { a: 1, b: 2 }
+  }
+
+  return new Promise((resolve, reject) => {
+    nano.request(req, (err, data) => {
+      expect(err).not.toBe(null)
+      expect(scope.isDone()).toBe(true)
+      resolve()
+    })
+  })
+})
+
+test('check request handle empty parameter list - nano.request', async () => {
+  // mocks
+  const response = {
+    couchdb: 'Welcome',
+    version: '2.3.1',
+    git_sha: 'c298091a4',
+    uuid: '865f5b0c258c5749012ce7807b4b0622',
+    features: [
+      'pluggable-storage-engines',
+      'scheduler'
+    ],
+    vendor: {
+      name: 'The Apache Software Foundation'
+    }
+  }
+  const scope = nock(COUCH_URL)
+    .get('/')
+    .reply(200, response)
+
+  // test GET /
+  const p = await nano.request()
+  expect(p).toStrictEqual(response)
+  expect(scope.isDone()).toBe(true)
+})
+
+test('check request handle empty parameter list (callback) - nano.request', async () => {
+  // mocks
+  const response = {
+    couchdb: 'Welcome',
+    version: '2.3.1',
+    git_sha: 'c298091a4',
+    uuid: '865f5b0c258c5749012ce7807b4b0622',
+    features: [
+      'pluggable-storage-engines',
+      'scheduler'
+    ],
+    vendor: {
+      name: 'The Apache Software Foundation'
+    }
+  }
+  const scope = nock(COUCH_URL)
+    .get('/')
+    .reply(200, response)
+
+  // test GET /
+  return new Promise((resolve, reject) => {
+    nano.request((err, data) => {
+      expect(err).toBeNull()
+      expect(data).toStrictEqual(response)
+      expect(scope.isDone()).toBe(true)
+      resolve()
+    })
+  })
+})
+
+test('check request handles single string parameter - nano.request', async () => {
+  // mocks
+  const response = {
+    db_name: 'db',
+    purge_seq: '0-8KhNZEiqhyjKAgBm5Rxs',
+    update_seq: '23523-gUFPHo-6PQIAJ_EdrA',
+    sizes: {
+      file: 18215344,
+      external: 5099714,
+      active: 6727596
+    }
+  }
+  const scope = nock(COUCH_URL)
+    .get('/db')
+    .reply(200, response)
+
+  // test GET /
+  const p = await nano.request('db')
+  expect(p).toStrictEqual(response)
+  expect(scope.isDone()).toBe(true)
+})
+
+test('check request handles cookies - nano.request', async () => {
+  // mocks
+  const username = 'u'
+  const password = 'p'
+  const response = { ok: true, name: 'admin', roles: ['_admin', 'admin'] }
+  const scope = nock(COUCH_URL)
+    .post('/_session', 'name=u&password=p', { 'content-type': 'application/x-www-form-urlencoded; charset=utf-8' })
+    .reply(200, response, { 'Set-Cookie': 'AuthSession=YWRtaW46NUU0MTFBMDE6stHsxYnlDy4mYxwZEcnXHn4fm5w; Version=1; Expires=Mon, 10-Feb-2050 09:03:21 GMT; Max-Age=600; Path=/; HttpOnly' })
+
+  // test GET /_uuids
+  const req = {
+    method: 'post',
+    path: '_session',
+    form: {
+      name: username,
+      password: password
+    },
+    jar: true
+  }
+  const p = await nano.request(req)
+  expect(p).toStrictEqual(response)
+  expect(scope.isDone()).toBe(true)
+})
+
+test('check request can do GET a doc - nano.request', async () => {
+  // mocks
+  const response = { _id: 'docname/design', _rev: '1-123', ok: true }
+  const scope = nock(COUCH_URL)
+    .get('/db/_design/docname?a=1&b=2')
+    .reply(200, response)
+
+  // test GET /db?a=1&b=2
+  const req = {
+    method: 'get',
+    db: 'db',
+    doc: '_design/docname',
+    qs: { a: 1, b: 2 }
+  }
+  const p = await nano.request(req)
+  expect(p).toStrictEqual(response)
+  expect(scope.isDone()).toBe(true)
+})
+
+test('check request doesn\'t mangle bodies containing functions - nano.request', async () => {
+  // mocks
+  const emit = () => { }
+  const doc = {
+    a: 1,
+    views: {
+      bytime: {
+        map: function () { emit(doc.ts, true) }
+      }
+    }
+  }
+  const response = { id: 'jfjfjf', rev: '1-123', ok: true }
+  const scope = nock(COUCH_URL)
+    .post('/db', { a: 1, views: { bytime: { map: 'function () {\n          emit(doc.ts, true);\n        }' } } })
+    .reply(200, response)
+
+  // test GET /db?a=1&b=2
+  const req = {
+    method: 'post',
+    db: 'db',
+    body: doc
+  }
+  const p = await nano.request(req)
+  expect(p).toStrictEqual(response)
+  expect(scope.isDone()).toBe(true)
+})
diff --git a/test/nano.session.test.js b/test/nano.session.test.js
index ca2eb97..2c0179a 100644
--- a/test/nano.session.test.js
+++ b/test/nano.session.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to check your session - GET /_session - nano.auth', async () => {
   // mocks
   const response = { ok: true, userCtx: { name: null, roles: [] }, info: { authentication_db: '_users', authentication_handlers: ['cookie', 'default'] } }
diff --git a/test/nano.timeout.test.js b/test/nano.timeout.test.js
new file mode 100644
index 0000000..2e7d2b8
--- /dev/null
+++ b/test/nano.timeout.test.js
@@ -0,0 +1,64 @@
+// Licensed under the Apache License, Version 2.0 (the 'License'); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+const Nano = require('..')
+const COUCH_URL = 'http://localhost:59804'
+const nano = Nano({
+  url: COUCH_URL,
+  requestDefaults: {
+    timeout: 500
+  }
+})
+const nock = require('nock')
+
+afterEach(() => {
+  nock.cleanAll()
+})
+
+test('check requests timeout - nano.request', async () => {
+  // mocks
+  const response = { ok: true }
+  nock(COUCH_URL)
+    .get('/db?a=1&b=2')
+    .delay(1000)
+    .reply(200, response)
+
+  // test GET /db?a=1&b=2
+  const req = {
+    method: 'get',
+    db: 'db',
+    qs: { a: 1, b: 2 }
+  }
+  await expect(nano.request(req)).rejects.toThrow('error happened in your connection')
+})
+
+test('check request timeout (callback) - nano.request', async () => {
+  // mocks
+  const response = { ok: true }
+  nock(COUCH_URL)
+    .get('/db?a=1&b=2')
+    .delay(1000)
+    .reply(200, response)
+
+  // test GET /db?a=1&b=2
+  const req = {
+    method: 'get',
+    db: 'db',
+    qs: { a: 1, b: 2 }
+  }
+  return new Promise((resolve, reject) => {
+    nano.request(req, (err, data) => {
+      expect(err).not.toBeNull()
+      resolve()
+    })
+  })
+})
diff --git a/test/nano.updates.test.js b/test/nano.updates.test.js
index 127041e..23c9245 100644
--- a/test/nano.updates.test.js
+++ b/test/nano.updates.test.js
@@ -39,6 +39,10 @@ const errResponse = {
   reason: 'Database does not exist.'
 }
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to fetch db updates - GET /_db_updates - nano.updates', async () => {
   // mocks
   const scope = nock(COUCH_URL)
diff --git a/test/nano.uuids.test.js b/test/nano.uuids.test.js
index ea004f1..315aed9 100644
--- a/test/nano.uuids.test.js
+++ b/test/nano.uuids.test.js
@@ -15,6 +15,10 @@ const COUCH_URL = 'http://localhost:5984'
 const nano = Nano(COUCH_URL)
 const nock = require('nock')
 
+afterEach(() => {
+  nock.cleanAll()
+})
+
 test('should be able to fetch uuids - GET /_uuids - nano.uuids', async () => {
   // mocks
   const response = {
@@ -50,3 +54,25 @@ test('should be able to fetch more uuids - GET /_uuids?count=3 - nano.uuids', as
   expect(p).toStrictEqual(response)
   expect(scope.isDone()).toBe(true)
 })
+
+test('should be able to fetch uuids callback - GET /_uuids - nano.uuids', async () => {
+  // mocks
+  const response = {
+    uuids: [
+      'c42ddf1272c7d05b2dc45b696200145f'
+    ]
+  }
+  const scope = nock(COUCH_URL)
+    .get('/_uuids?count=1')
+    .reply(200, response)
+
+  // test GET /_uuids
+  return new Promise((resolve, reject) => {
+    nano.uuids((err, data) => {
+      expect(err).toBe(null)
+      expect(data).toStrictEqual(response)
+      expect(scope.isDone()).toBe(true)
+      resolve()
+    })
+  })
+})