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 2018/07/02 14:03:47 UTC
[couchdb-nano] branch master updated: Fix JSON.stringify of
start_key & end_key alias parameters (#93)
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 4ef1cff Fix JSON.stringify of start_key & end_key alias parameters (#93)
4ef1cff is described below
commit 4ef1cff9afd86e441ff389a7692c3693c5272c0f
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Mon Jul 2 15:03:45 2018 +0100
Fix JSON.stringify of start_key & end_key alias parameters (#93)
* 6.4.4
* ensure start_key & end_key parameters are JSON.stringified - fixes issue #92
* fix mocked tests
---
lib/nano.js | 2 +-
tests/fixtures/document/create_index.json | 7 +++++-
tests/fixtures/document/list.json | 9 ++++++++
tests/integration/document/create_index.js | 2 +-
tests/integration/document/list.js | 35 +++++++++++++++++++++++++++++-
tests/integration/util/uuid.js | 6 ++---
6 files changed, 53 insertions(+), 8 deletions(-)
diff --git a/lib/nano.js b/lib/nano.js
index 84d2a32..fd4bf92 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -159,7 +159,7 @@ module.exports = exports = nano = function dbScope(cfg) {
// http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options
if (typeof opts.qs === 'object' && !isEmpty(opts.qs)) {
- ['startkey', 'endkey', 'key', 'keys'].forEach(function(key) {
+ ['startkey', 'endkey', 'key', 'keys', 'start_key', 'end_key'].forEach(function(key) {
if (key in opts.qs) {
qs[key] = JSON.stringify(opts.qs[key]);
}
diff --git a/tests/fixtures/document/create_index.json b/tests/fixtures/document/create_index.json
index a419823..720fe56 100644
--- a/tests/fixtures/document/create_index.json
+++ b/tests/fixtures/document/create_index.json
@@ -16,4 +16,9 @@
, "body" : "{\"name\":\"fooindex\",\"index\":{\"fields\":[\"foo\"]}}"
, "response" : "{\"result\":\"created\",\"id\":\"_design/a7ee061f1a2c0c6882258b2f1e148b714e79ccea\",\"name\": \"fooindex\"}"
}
-]
+, { "method" : "delete"
+ , "path" : "/document_create_index"
+ , "status" : 201
+ , "response" : "{ \"ok\": true }"
+ }
+]
\ No newline at end of file
diff --git a/tests/fixtures/document/list.json b/tests/fixtures/document/list.json
index 006f6fc..58bd178 100644
--- a/tests/fixtures/document/list.json
+++ b/tests/fixtures/document/list.json
@@ -31,6 +31,15 @@
, { "path" : "/document_list/_all_docs?startkey=%22c%22"
, "response" : "{\"total_rows\":3,\"offset\": 1,\"rows\":[\r\n{\"id\":\"foobar\",\"key\":\"foobar\",\"value\":{\"_id\":\"foobar\",\"_rev\":\"1-4c6114c65e295552ab1019e2b046b10e\",\"foo\":\"bar\"},\"doc\":{\"_id\":\"foobar\",\"_rev\":\"1-4c6114c65e295552ab1019e2b046b10e\",\"foo\":\"bar\"}},\r\n{\"id\":\"barfoo\",\"key\":\"barfoo\",\"value\":{\"_id\":\"barfoo\",\"_rev\":\"1-41412c293dade3fe73279cba8b4cece4\",\"bar\":\"foo\"},\"doc\":{\"_id\":\"barfoo\",\"_rev\":\"1-41412c293dade3fe73279cb [...]
}
+, { "path" : "/document_list/_all_docs?start_key=%22c%22"
+ , "response" : "{\"total_rows\":3,\"offset\": 1,\"rows\":[\r\n{\"id\":\"foobar\",\"key\":\"foobar\",\"value\":{\"_id\":\"foobar\",\"_rev\":\"1-4c6114c65e295552ab1019e2b046b10e\",\"foo\":\"bar\"},\"doc\":{\"_id\":\"foobar\",\"_rev\":\"1-4c6114c65e295552ab1019e2b046b10e\",\"foo\":\"bar\"}},\r\n{\"id\":\"barfoo\",\"key\":\"barfoo\",\"value\":{\"_id\":\"barfoo\",\"_rev\":\"1-41412c293dade3fe73279cba8b4cece4\",\"bar\":\"foo\"},\"doc\":{\"_id\":\"barfoo\",\"_rev\":\"1-41412c293dade3fe73279cb [...]
+ }
+, { "path" : "/document_list/_all_docs?endkey=%22s%22"
+ , "response" : "{\"total_rows\":3,\"offset\": 1,\"rows\":[\r\n{\"id\":\"foobar\",\"key\":\"foobar\",\"value\":{\"_id\":\"foobar\",\"_rev\":\"1-4c6114c65e295552ab1019e2b046b10e\",\"foo\":\"bar\"},\"doc\":{\"_id\":\"foobar\",\"_rev\":\"1-4c6114c65e295552ab1019e2b046b10e\",\"foo\":\"bar\"}},\r\n{\"id\":\"barfoo\",\"key\":\"barfoo\",\"value\":{\"_id\":\"barfoo\",\"_rev\":\"1-41412c293dade3fe73279cba8b4cece4\",\"bar\":\"foo\"},\"doc\":{\"_id\":\"barfoo\",\"_rev\":\"1-41412c293dade3fe73279cb [...]
+ }
+, { "path" : "/document_list/_all_docs?end_key=%22s%22"
+ , "response" : "{\"total_rows\":3,\"offset\": 1,\"rows\":[\r\n{\"id\":\"foobar\",\"key\":\"foobar\",\"value\":{\"_id\":\"foobar\",\"_rev\":\"1-4c6114c65e295552ab1019e2b046b10e\",\"foo\":\"bar\"},\"doc\":{\"_id\":\"foobar\",\"_rev\":\"1-4c6114c65e295552ab1019e2b046b10e\",\"foo\":\"bar\"}},\r\n{\"id\":\"barfoo\",\"key\":\"barfoo\",\"value\":{\"_id\":\"barfoo\",\"_rev\":\"1-41412c293dade3fe73279cba8b4cece4\",\"bar\":\"foo\"},\"doc\":{\"_id\":\"barfoo\",\"_rev\":\"1-41412c293dade3fe73279cb [...]
+ }
, { "method" : "delete"
, "path" : "/document_list"
, "status" : 200
diff --git a/tests/integration/document/create_index.js b/tests/integration/document/create_index.js
index dab3cee..7181f1b 100644
--- a/tests/integration/document/create_index.js
+++ b/tests/integration/document/create_index.js
@@ -26,7 +26,7 @@ it ('Should create one simple index', function(assert) {
}, function(error, foo) {
assert.equal(error, null, 'should have indexed fields');
assert.equal(foo.result, 'created', 'index should be created');
- assert.equal(foo.name, 'foobaz', 'index should have correct name');
+ assert.equal(foo.name, 'fooindex', 'index should have correct name');
assert.end();
});
diff --git a/tests/integration/document/list.js b/tests/integration/document/list.js
index 80af2e6..60fc15c 100644
--- a/tests/integration/document/list.js
+++ b/tests/integration/document/list.js
@@ -44,13 +44,46 @@ it('should be able to list using the `relax` function', function(assert) {
});
});
+it('should be able to list with a start_key', function(assert) {
+ db.list({start_key: 'c'}, function(error, docs) {
+ assert.equal(error, null, 'should work');
+ assert.ok(docs.rows, 'get the rows');
+ assert.equal(docs.rows.length, 2, 'starts in row two');
+ assert.equal(docs['total_rows'], 3, 'out of three rows');
+ assert.equal(docs.offset, 1, 'offset is 1');
+ assert.end();
+ });
+});
+
it('should be able to list with a startkey', function(assert) {
db.list({startkey: 'c'}, function(error, docs) {
assert.equal(error, null, 'should work');
- assert.ok(docs.rows, 'get teh rows');
+ assert.ok(docs.rows, 'get the rows');
assert.equal(docs.rows.length, 2, 'starts in row two');
assert.equal(docs['total_rows'], 3, 'out of three rows');
assert.equal(docs.offset, 1, 'offset is 1');
assert.end();
});
});
+
+it('should be able to list with a endkey', function(assert) {
+ db.list({endkey: 's'}, function(error, docs) {
+ assert.equal(error, null, 'should work');
+ assert.ok(docs.rows, 'get the rows');
+ assert.equal(docs.rows.length, 2, 'starts in row two');
+ assert.equal(docs['total_rows'], 3, 'out of three rows');
+ assert.equal(docs.offset, 1, 'offset is 1');
+ assert.end();
+ });
+});
+
+it('should be able to list with a end_key', function(assert) {
+ db.list({end_key: 's'}, function(error, docs) {
+ assert.equal(error, null, 'should work');
+ assert.ok(docs.rows, 'get the rows');
+ assert.equal(docs.rows.length, 2, 'starts in row two');
+ assert.equal(docs['total_rows'], 3, 'out of three rows');
+ assert.equal(docs.offset, 1, 'offset is 1');
+ assert.end();
+ });
+});
\ No newline at end of file
diff --git a/tests/integration/util/uuid.js b/tests/integration/util/uuid.js
index 0cb4360..c97ec7b 100644
--- a/tests/integration/util/uuid.js
+++ b/tests/integration/util/uuid.js
@@ -18,14 +18,12 @@ var db = harness.locals.db;
var nano = helpers.nano;
var it = harness.it;
-it('should insert a one item', helpers.insertOne);
-
it('should generate three uuids', function(assert) {
nano.uuids(3, function(error, data) {
assert.equal(error, null, 'should generate uuids');
assert.ok(data, 'got response');
assert.ok(data.uuids, 'got uuids');
- assert.equal(data.uuids.count, 3, 'got 3');
+ assert.equal(data.uuids.length, 3, 'got 3');
assert.end();
});
});
@@ -35,7 +33,7 @@ it('should generate one uuid', function(assert) {
assert.equal(error, null, 'should generate uuids');
assert.ok(data, 'got response');
assert.ok(data.uuids, 'got uuid');
- assert.equal(data.uuids.count, 1, 'got 1');
+ assert.equal(data.uuids.length, 1, 'got 1');
assert.end();
});
});