summaryrefslogtreecommitdiff
path: root/share/www/script/test/basics.js
diff options
context:
space:
mode:
authorPaul Joseph Davis <davisp@apache.org>2009-04-18 18:34:31 +0000
committerPaul Joseph Davis <davisp@apache.org>2009-04-18 18:34:31 +0000
commitdaa9d65a53dedaac5aeeb6394d4c0b6f99fa930c (patch)
tree71a35ed91de64d76b29a44776a0d6d93efc5e75a /share/www/script/test/basics.js
parent1df7a4e6a659550cde173381a0e0f9d770417d59 (diff)
Resolves COUCHDB-306 - Wacky error responses to malformed documents
Mostly adds improvements to the parsing of Json bodies for _bulk_docs and multi-get queries. Includes tests in basics.js and view_errors.js. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@766373 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script/test/basics.js')
-rw-r--r--share/www/script/test/basics.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/share/www/script/test/basics.js b/share/www/script/test/basics.js
index 8adf5a84..2eb49ebe 100644
--- a/share/www/script/test/basics.js
+++ b/share/www/script/test/basics.js
@@ -168,4 +168,32 @@ couchTests.basics = function(debug) {
// deleting a non-existent doc should be 404
xhr = CouchDB.request("DELETE", "/test_suite_db/doc-does-not-exist");
T(xhr.status == 404);
+
+ // Check some common error responses.
+ // PUT body not an object
+ xhr = CouchDB.request("PUT", "/test_suite_db/bar", {body: "[]"});
+ T(xhr.status == 400);
+ result = JSON.parse(xhr.responseText);
+ T(result.error == "bad_request");
+ T(result.reason == "Document must be a JSON object");
+
+ // Body of a _bulk_docs is not an object
+ xhr = CouchDB.request("POST", "/test_suite_db/_bulk_docs", {body: "[]"});
+ T(xhr.status == 400);
+ result = JSON.parse(xhr.responseText);
+ T(result.error == "bad_request");
+ T(result.reason == "Body must be a JSON object");
+
+ // Body of an _all_docs multi-get is not a {"key": [...]} structure.
+ xhr = CouchDB.request("POST", "/test_suite_db/_all_docs", {body: "[]"});
+ T(xhr.status == 400);
+ result = JSON.parse(xhr.responseText);
+ T(result.error == "bad_request");
+ T(result.reason == "Body must be a JSON object");
+ var data = "{\"keys\": 1}";
+ xhr = CouchDB.request("POST", "/test_suite_db/_all_docs", {body:data});
+ T(xhr.status == 400);
+ result = JSON.parse(xhr.responseText);
+ T(result.error == "bad_request");
+ T(result.reason == "`keys` member must be a array.");
};