diff options
author | Jan Lehnardt <jan@apache.org> | 2015-06-25 22:32:02 +0200 |
---|---|---|
committer | Jan Lehnardt <jan@apache.org> | 2015-06-25 22:32:02 +0200 |
commit | f6c87e41afe6063145be0a5b5a907367020def44 (patch) | |
tree | 7307a6de89d1711b8b011394e4c98a2ec6c36220 | |
parent | df1be4f40093aa55cd6b6b80bc3090476bdebe1c (diff) | |
download | couchdb-port-js-tests-to-2.0.tar.gz |
js tests: make all_docs.js cluster-capableport-js-tests-to-2.0
-rw-r--r-- | test/javascript/couch.js | 7 | ||||
-rw-r--r-- | test/javascript/couchdb.uri | 1 | ||||
-rw-r--r-- | test/javascript/tests/all_docs.js | 93 |
3 files changed, 62 insertions, 39 deletions
diff --git a/test/javascript/couch.js b/test/javascript/couch.js index 7e4eeed73..02722a2d6 100644 --- a/test/javascript/couch.js +++ b/test/javascript/couch.js @@ -71,9 +71,10 @@ function CouchDB(name, httpHeaders) { }; // Deletes a document from the database - this.deleteDoc = function(doc) { + this.deleteDoc = function(doc, request_options) { + request_options = request_options || ""; this.last_req = this.request("DELETE", this.uri + encodeURIComponent(doc._id) - + "?rev=" + doc._rev); + + "?rev=" + doc._rev + request_options); CouchDB.maybeThrowError(this.last_req); var result = JSON.parse(this.last_req.responseText); doc._rev = result.rev; //record rev in input document @@ -357,6 +358,8 @@ CouchDB.getVersion = function() { }; CouchDB.reloadConfig = function() { + // diabled until cluser port gets /_config + return {}; CouchDB.last_req = CouchDB.request("POST", "/_config/_reload"); CouchDB.maybeThrowError(CouchDB.last_req); return JSON.parse(CouchDB.last_req.responseText); diff --git a/test/javascript/couchdb.uri b/test/javascript/couchdb.uri new file mode 100644 index 000000000..99c8819c8 --- /dev/null +++ b/test/javascript/couchdb.uri @@ -0,0 +1 @@ +http://127.0.0.1:15984/ diff --git a/test/javascript/tests/all_docs.js b/test/javascript/tests/all_docs.js index 66ad880f5..bc6639bac 100644 --- a/test/javascript/tests/all_docs.js +++ b/test/javascript/tests/all_docs.js @@ -18,10 +18,22 @@ couchTests.all_docs = function(debug) { // Create some more documents. // Notice the use of the ok member on the return result. - T(db.save({_id:"0",a:1,b:1}).ok); - T(db.save({_id:"3",a:4,b:16}).ok); - T(db.save({_id:"1",a:2,b:4}).ok); - T(db.save({_id:"2",a:3,b:9}).ok); + + var doc1 = db.save({_id:"0",a:1,b:1}); + var doc2 = db.save({_id:"3",a:4,b:16}); + var doc3 = db.save({_id:"1",a:2,b:4}); + var doc4 = db.save({_id:"2",a:3,b:9}); + + T(doc1.ok); + T(doc2.ok); + T(doc3.ok); + T(doc4.ok); + + var revs = []; + revs.push(doc1.rev); + revs.push(doc2.rev); + revs.push(doc3.rev); + revs.push(doc4.rev); // Check the all docs var results = db.allDocs(); @@ -47,50 +59,52 @@ couchTests.all_docs = function(debug) { }); TEquals(0, raw.rows.length); - // check that the docs show up in the seq view in the order they were created - var changes = db.changes(); - var ids = ["0","3","1","2"]; - for (var i=0; i < changes.results.length; i++) { - var row = changes.results[i]; - T(row.id == ids[i], "seq order"); - }; - // it should work in reverse as well - changes = db.changes({descending:true}); - ids = ["2","1","3","0"]; - for (var i=0; i < changes.results.length; i++) { - var row = changes.results[i]; - T(row.id == ids[i], "descending=true"); - }; + // check that all docs show up in the changes feed + // the order can vary + var changes = db.changes(); + changes.results.forEach(function(row, idx) { + var rev = row.changes[0].rev; + TEquals(true, revs.indexOf(rev) !== -1, "doc " + i + " should be in changes"); + }); // check that deletions also show up right var doc1 = db.open("1"); - var deleted = db.deleteDoc(doc1); + var deleted = db.deleteDoc(doc1, "&w=3"); T(deleted.ok); changes = db.changes(); - // the deletion should make doc id 1 have the last seq num T(changes.results.length == 4); - T(changes.results[3].id == "1"); - T(changes.results[3].deleted); + var deleted_doc = changes.results.filter(function(row) { + return row.deleted == true; + })[0]; + TEquals("1", deleted_doc.id, "deletes"); // do an update - var doc2 = db.open("3"); - doc2.updated = "totally"; - db.save(doc2); + var doc3 = db.open("3"); + doc3.updated = "totally"; + doc3 = db.save(doc3); changes = db.changes(); // the update should make doc id 3 have the last seq num T(changes.results.length == 4); - T(changes.results[3].id == "3"); + var updated_doc = changes.results.filter(function(row) { + return row.id == doc3.id + })[0]; + TEquals("3", updated_doc.id, "doc id should be 3"); // ok now lets see what happens with include docs changes = db.changes({include_docs: true}); T(changes.results.length == 4); - T(changes.results[3].id == "3"); - T(changes.results[3].doc.updated == "totally"); - T(changes.results[2].doc); - T(changes.results[2].doc._deleted); + var updated_doc = changes.results.filter(function(row) { + return row.id == doc3.id + })[0]; + T(updated_doc.doc.updated == "totally"); + + var deleted_doc = changes.results.filter(function(row) { + return row.deleted == true; + })[0]; + TEquals(true, deleted_doc.doc._deleted, "deletes"); rows = db.allDocs({include_docs: true}, ["1"]).rows; TEquals(1, rows.length); @@ -112,13 +126,18 @@ couchTests.all_docs = function(debug) { var winRev = db.open("3"); changes = db.changes({include_docs: true, conflicts: true, style: "all_docs"}); - TEquals("3", changes.results[3].id); - TEquals(3, changes.results[3].changes.length); - TEquals(winRev._rev, changes.results[3].changes[0].rev); - TEquals("3", changes.results[3].doc._id); - TEquals(winRev._rev, changes.results[3].doc._rev); - TEquals(true, changes.results[3].doc._conflicts instanceof Array); - TEquals(2, changes.results[3].doc._conflicts.length); + + var doc3 = changes.results.filter(function(row) { + return row.id == "3"; + })[0]; + + TEquals("3", doc3.id); + TEquals(3, doc3.changes.length); + TEquals(winRev._rev, doc3.changes[0].rev); + TEquals("3", doc3.doc._id); + TEquals(winRev._rev, doc3.doc._rev); + TEquals(true, doc3.doc._conflicts instanceof Array); + TEquals(2, doc3.doc._conflicts.length); rows = db.allDocs({include_docs: true, conflicts: true}).rows; TEquals(3, rows.length); |