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/06/26 06:55:54 UTC

[couchdb-nano] branch master updated: (#70) Return error if db.get() called with no docName (#78)

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 723e148  (#70) Return error if db.get() called with no docName (#78)
723e148 is described below

commit 723e148f1633c5a75c78c62fd5ff4914ea01d560
Author: Adam Saeid <20...@users.noreply.github.com>
AuthorDate: Tue Jun 26 07:55:52 2018 +0100

    (#70) Return error if db.get() called with no docName (#78)
---
 lib/nano.js                |  8 +++++++-
 tests/unit/document/get.js | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/lib/nano.js b/lib/nano.js
index 3b7f822..0ea96de 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -460,7 +460,13 @@ module.exports = exports = nano = function dbScope(cfg) {
         qs = {};
       }
 
-      return relax({db: dbName, doc: docName, qs: qs}, callback);
+      if(!docName) {
+        if(callback)
+          callback("Invalid doc id", null);
+      }
+      else {
+        return relax({db: dbName, doc: docName, qs: qs}, callback);
+      }
     }
 
     // http://docs.couchdb.org/en/latest/api/document/common.html#head--db-docid
diff --git a/tests/unit/document/get.js b/tests/unit/document/get.js
new file mode 100644
index 0000000..bbe18b7
--- /dev/null
+++ b/tests/unit/document/get.js
@@ -0,0 +1,41 @@
+// 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.
+
+'use strict';
+
+var helpers = require('../../helpers/unit');
+var test  = require('tape');
+var debug = require('debug')('nano/tests/unit/shared/error');
+
+var cli = helpers.mockClientDb(debug)
+var db = cli.use('foo')
+
+test('it should not return db info if docName undefined', function(assert) {
+  db.get(undefined, function(err) {
+    assert.equal(err, 'Invalid doc id');
+    assert.end();
+  });
+});
+
+test('it should not return db info if docName null', function(assert) {
+  db.get(null, function(err) {
+    assert.equal(err, 'Invalid doc id');
+    assert.end();
+  });
+});
+
+test('it should not return db info if docName empty string', function(assert) {
+  db.get('', function(err) {
+    assert.equal(err, 'Invalid doc id');
+    assert.end();
+  });
+});
\ No newline at end of file