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/13 18:07:10 UTC
[couchdb-nano] branch master updated: Make sure nano works with
_local docs (#200)
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
The following commit(s) were added to refs/heads/master by this push:
new df6c040 Make sure nano works with _local docs (#200)
df6c040 is described below
commit df6c0400894929846b4b0c94e73db49a57f6019d
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Thu Feb 13 18:07:00 2020 +0000
Make sure nano works with _local docs (#200)
* added test to fetch local docs
* _local support added #167
* added local tests
Co-authored-by: Malte Legenhausen <ml...@gmail.com>
Thanks @mlegenhausen!
---
lib/nano.js | 2 +-
test/document.get.test.js | 14 ++++++++++++++
test/document.insert.test.js | 32 ++++++++++++++++++++++++++++++++
3 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/lib/nano.js b/lib/nano.js
index 79fbfb5..21b5bab 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -225,7 +225,7 @@ module.exports = exports = function dbScope (cfg) {
if (opts.path) {
req.uri += '/' + opts.path
} else if (opts.doc) {
- if (!/^_design/.test(opts.doc)) {
+ if (!/^_design|_local/.test(opts.doc)) {
// http://wiki.apache.org/couchdb/HTTP_Document_API#Naming.2FAddressing
req.uri += '/' + encodeURIComponent(opts.doc)
} else {
diff --git a/test/document.get.test.js b/test/document.get.test.js
index 6fba869..93443cb 100644
--- a/test/document.get.test.js
+++ b/test/document.get.test.js
@@ -91,3 +91,17 @@ test('should detect missing parameters (callback) - db.get', () => {
})
})
})
+
+test('check request can fetch local documents - db.get', async () => {
+ // mocks
+ const response = { _id: '_local/id', _rev: '1-123', a: 1 }
+ const scope = nock(COUCH_URL)
+ .get('/db/_local/id')
+ .reply(200, response)
+
+ // test GET /db/_local/id
+ const db = nano.db.use('db')
+ const p = await db.get('_local/id')
+ expect(p).toStrictEqual(response)
+ expect(scope.isDone()).toBe(true)
+})
diff --git a/test/document.insert.test.js b/test/document.insert.test.js
index 60f1696..c4532d7 100644
--- a/test/document.insert.test.js
+++ b/test/document.insert.test.js
@@ -130,3 +130,35 @@ test('should be able to handle missing database - POST /db - db.insert', async (
await expect(db.insert(doc)).rejects.toThrow('Database does not exist.')
expect(scope.isDone()).toBe(true)
})
+
+test('should be able to insert document with _local id - PUT /db/_local/id - db.insert', async () => {
+ // mocks
+ const doc = { a: 1, b: 2 }
+ const response = { ok: true, id: '_local/myid', rev: '1-123' }
+
+ const scope = nock(COUCH_URL)
+ .put('/db/_local/myid', doc)
+ .reply(200, response)
+
+ // test PUT /db
+ const db = nano.db.use('db')
+ const p = await db.insert(doc, '_local/myid')
+ expect(p).toStrictEqual(response)
+ expect(scope.isDone()).toBe(true)
+})
+
+test('should be able to insert document with local id in object - POST /db - db.insert', async () => {
+ // mocks
+ const doc = { _id: '_local/myid', a: 1, b: 2 }
+ const response = { ok: true, id: '_local/myid', rev: '1-123' }
+
+ const scope = nock(COUCH_URL)
+ .post('/db', doc)
+ .reply(200, response)
+
+ // test POST /db
+ const db = nano.db.use('db')
+ const p = await db.insert(doc)
+ expect(p).toStrictEqual(response)
+ expect(scope.isDone()).toBe(true)
+})