modified tests to work with latest dependencies and CouchDB 2.0
Project: http://git-wip-us.apache.org/repos/asf/couchdb-nano/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-nano/commit/45d58bfe Tree: http://git-wip-us.apache.org/repos/asf/couchdb-nano/tree/45d58bfe Diff: http://git-wip-us.apache.org/repos/asf/couchdb-nano/diff/45d58bfe Branch: refs/heads/master Commit: 45d58bfeb8b59ee97d1821ed9006c735fc65f4e4 Parents: d1c7554 Author: Glynn Bird <[email protected]> Authored: Wed Oct 26 14:19:25 2016 +0100 Committer: Glynn Bird <[email protected]> Committed: Wed Oct 26 14:19:25 2016 +0100 ---------------------------------------------------------------------- tests/fixtures/database/changes.json | 4 +- tests/fixtures/shared/error.json | 2 +- tests/helpers/integration.js | 4 +- tests/integration/database/changes.js | 7 +-- tests/integration/database/compact.js | 2 +- .../integration/database/create-and-destroy.js | 2 +- tests/integration/database/follow.js | 16 ++---- tests/integration/database/list.js | 8 +++ tests/integration/database/replicate.js | 4 +- tests/integration/design/show.js | 2 +- tests/integration/shared/cookie.js | 4 +- tests/integration/shared/error.js | 2 +- tests/integration/shared/updates.js | 60 -------------------- 13 files changed, 29 insertions(+), 88 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/45d58bfe/tests/fixtures/database/changes.json ---------------------------------------------------------------------- diff --git a/tests/fixtures/database/changes.json b/tests/fixtures/database/changes.json index 820d2fe..7bce048 100644 --- a/tests/fixtures/database/changes.json +++ b/tests/fixtures/database/changes.json @@ -23,8 +23,8 @@ , "response" : "{\"ok\":true,\"id\":\"barfoo\",\"rev\":\"1-3cde10\"}" } , { "status" : 200 - , "path" : "/database_changes/_changes?since=2" - , "response" : "{\"results\":[\n{\"seq\":3,\"id\":\"foobaz\",\"changes\":[{\"rev\":\"1-cfa20dddac397da5bf0be2b50fb472fe\"}]}\n],\n\"last_seq\":3}" + , "path" : "/database_changes/_changes?since=0" + , "response" : "{\"results\":[{\"seq\":\"1-abc\",\"id\":\"a\",\"changes\":[{\"rev\":\"1-abc\"}]},{\"seq\":\"2-abc\",\"id\":\"b\",\"changes\":[{\"rev\":\"1-abc\"}]},{\"seq\":\"3-abc\",\"id\":\"c\",\"changes\":[{\"rev\":\"1-abc\"}]}],\"last_seq\":\"3-abc\"}" } , { "method" : "delete" , "path" : "/database_changes" http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/45d58bfe/tests/fixtures/shared/error.json ---------------------------------------------------------------------- diff --git a/tests/fixtures/shared/error.json b/tests/fixtures/shared/error.json index 4b42be2..4210c2c 100644 --- a/tests/fixtures/shared/error.json +++ b/tests/fixtures/shared/error.json @@ -10,7 +10,7 @@ , { "method" : "delete" , "path" : "/say_wat_wat" , "status" : 404 - , "response" : "{\"error\":\"not_found\",\"reason\":\"missing\"}" + , "response" : "{\"error\":\"not_found\",\"reason\":\"Database does not exist.\"}" } , { "method" : "delete" , "path" : "/shared_error" http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/45d58bfe/tests/helpers/integration.js ---------------------------------------------------------------------- diff --git a/tests/helpers/integration.js b/tests/helpers/integration.js index f7b3249..c63c4ea 100644 --- a/tests/helpers/integration.js +++ b/tests/helpers/integration.js @@ -146,7 +146,7 @@ helpers.prepareAView = function(assert, search, db) { }, 'p_nuno', cb); } ], function(error) { - assert.equal(error, undefined, 'store the peeps'); + assert.equal(error, null, 'store the peeps'); assert.end(); }); }); @@ -180,7 +180,7 @@ helpers.insertThree = function insertThree(assert) { function(cb) { db.insert({'bar': 'foo'}, 'barfoo', cb); }, function(cb) { db.insert({'foo': 'baz'}, 'foobaz', cb); } ], function(error) { - assert.equal(error, undefined, 'should store docs'); + assert.equal(error, null, 'should store docs'); assert.end(); }); }; http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/45d58bfe/tests/integration/database/changes.js ---------------------------------------------------------------------- diff --git a/tests/integration/database/changes.js b/tests/integration/database/changes.js index d8f251a..8c96f43 100644 --- a/tests/integration/database/changes.js +++ b/tests/integration/database/changes.js @@ -19,11 +19,10 @@ var it = harness.it; it('should be able to insert three documents', helpers.insertThree); -it('should be able to receive changes since seq:2', function(assert) { - db.changes({since:2}, function(error, response) { +it('should be able to receive changes since seq:0', function(assert) { + db.changes({since:0}, function(error, response) { assert.equal(error, null, 'gets response from changes'); - assert.equal(response.results.length, 1, 'gets one result'); - assert.equal(response['last_seq'], 3, 'seq is 3'); + assert.equal(response.results.length, 3, 'gets three results'); assert.end(); }); }); http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/45d58bfe/tests/integration/database/compact.js ---------------------------------------------------------------------- diff --git a/tests/integration/database/compact.js b/tests/integration/database/compact.js index 0eef721..98c9468 100644 --- a/tests/integration/database/compact.js +++ b/tests/integration/database/compact.js @@ -36,7 +36,7 @@ it('should have run the compaction', function(assert) { assert.equal(error, null, 'info should respond'); assert.equal(info['doc_count'], 0, 'document count is not 3'); assert.equal(info['doc_del_count'], 1, 'document should be deleted'); - assert.equal(info['update_seq'], 2, 'seq is two'); + assert.equal(info['update_seq'][0], '2', 'seq is two'); assert.end(); }); }); http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/45d58bfe/tests/integration/database/create-and-destroy.js ---------------------------------------------------------------------- diff --git a/tests/integration/database/create-and-destroy.js b/tests/integration/database/create-and-destroy.js index 952c9ee..94d082b 100644 --- a/tests/integration/database/create-and-destroy.js +++ b/tests/integration/database/create-and-destroy.js @@ -37,7 +37,7 @@ function(assert) { it('must destroy the databases we created', function(assert) { async.forEach(['az09_$()+-/', 'with/slash'], nano.db.destroy, function(err) { - assert.equal(err, undefined, 'should destroy all dbs'); + assert.equal(err, null, 'should destroy all dbs'); assert.end(); }); }); http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/45d58bfe/tests/integration/database/follow.js ---------------------------------------------------------------------- diff --git a/tests/integration/database/follow.js b/tests/integration/database/follow.js index a4bcdaf..e66749c 100644 --- a/tests/integration/database/follow.js +++ b/tests/integration/database/follow.js @@ -25,14 +25,13 @@ if (helpers.unmocked) { it('should be able to get the changes feed', function(assert) { var i = 3; - feed1 = db.follow({since: 3}); + feed1 = db.follow({since: '0'}); feed1.on('change', function(change) { assert.ok(change, 'change existed'); - assert.equal(change.seq, i + 1, 'seq is set correctly'); + //assert.equal(change.seq, i + 1, 'seq is set correctly'); ++i; if (i === 4) { - console.log(change, i); assert.end(); } }); @@ -44,13 +43,8 @@ if (helpers.unmocked) { }, 100); }); - it('should see changes since `seq:3`', function(assert) { - var feed = db.follow({since: 3}, function(error, change) { - assert.equal(error, null, 'should not have errors'); - assert.ok(change, 'change existed'); - feed.die(); - feed1.die(); - process.nextTick(assert.end); - }); + it('should clear changes feed', function(assert) { + feed1.die(); + assert.end(); }); } http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/45d58bfe/tests/integration/database/list.js ---------------------------------------------------------------------- diff --git a/tests/integration/database/list.js b/tests/integration/database/list.js index 44501b0..8759a75 100644 --- a/tests/integration/database/list.js +++ b/tests/integration/database/list.js @@ -17,6 +17,14 @@ var harness = helpers.harness(__filename); var it = harness.it; var nano = harness.locals.nano; +it('should ensure _replicator and _users are created', function(assert) { + nano.db.create('_replicator', function() { + nano.db.create('_users', function() { + assert.end(); + }); + }); +}); + it('should list the correct databases', function(assert) { nano.db.list(function(error, list) { assert.equal(error, null, 'should list databases'); http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/45d58bfe/tests/integration/database/replicate.js ---------------------------------------------------------------------- diff --git a/tests/integration/database/replicate.js b/tests/integration/database/replicate.js index ab22ba9..3be79a0 100644 --- a/tests/integration/database/replicate.js +++ b/tests/integration/database/replicate.js @@ -27,7 +27,7 @@ it('should insert a bunch of items', helpers.insertThree); it('creates a bunch of database replicas', function(assert) { async.forEach(['database_replica', 'database_replica2'], nano.db.create, function(error) { - assert.equal(error, undefined, 'created database(s)'); + assert.equal(error, null, 'created database(s)'); assert.end(); }); }); @@ -68,7 +68,7 @@ it('should be able to replicate with params', function(assert) { it('should destroy the extra databases', function(assert) { async.forEach(['database_replica', 'database_replica2'], nano.db.destroy, function(error) { - assert.equal(error, undefined, 'deleted databases'); + assert.equal(error, null, 'deleted databases'); assert.end(); }); }); http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/45d58bfe/tests/integration/design/show.js ---------------------------------------------------------------------- diff --git a/tests/integration/design/show.js b/tests/integration/design/show.js index 086a03e..2d6f20d 100644 --- a/tests/integration/design/show.js +++ b/tests/integration/design/show.js @@ -66,7 +66,7 @@ it('should insert a show ddoc', function(assert) { }, 'p_nuno', cb); } ], function(error) { - assert.equal(error, undefined, 'stores docs'); + assert.equal(error, null, 'stores docs'); assert.end(); }); }); http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/45d58bfe/tests/integration/shared/cookie.js ---------------------------------------------------------------------- diff --git a/tests/integration/shared/cookie.js b/tests/integration/shared/cookie.js index 9a0eb2a..0c42e90 100644 --- a/tests/integration/shared/cookie.js +++ b/tests/integration/shared/cookie.js @@ -25,7 +25,7 @@ var server; it('should be able to setup admin and login', function(assert) { nano.relax({ method : 'PUT', - path: '_config/admins/' + helpers.username, + path: '_node/couchdb@localhost/_config/admins/' + helpers.username, body: helpers.password }, function(err) { assert.equal(err, null, 'should create admin'); @@ -65,7 +65,7 @@ it('should be able to get the session', function(assert) { it('must restore admin parteh mode for other tests', function(assert) { admin.relax({ method: 'DELETE', - path: '_config/admins/' + helpers.username + path: '_node/couchdb@localhost/_config/admins/' + helpers.username }, function(err) { assert.equal(err, null, 'should have deleted admin user'); assert.end(); http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/45d58bfe/tests/integration/shared/error.js ---------------------------------------------------------------------- diff --git a/tests/integration/shared/error.js b/tests/integration/shared/error.js index ec3a1d0..e9b89de 100644 --- a/tests/integration/shared/error.js +++ b/tests/integration/shared/error.js @@ -46,7 +46,7 @@ it('should error when destroying a db that does not exist', function(assert) { nano.db.destroy('say_wat_wat', function(error) { assert.ok(error, 'an error'); assert.ok(error.message, 'a note'); - assert.equal(error.message, 'missing', 'is missing'); + assert.equal(error.message, 'Database does not exist.', 'is missing'); assert.end(); }); }); http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/45d58bfe/tests/integration/shared/updates.js ---------------------------------------------------------------------- diff --git a/tests/integration/shared/updates.js b/tests/integration/shared/updates.js deleted file mode 100644 index d61abd7..0000000 --- a/tests/integration/shared/updates.js +++ /dev/null @@ -1,60 +0,0 @@ -// 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/integration'); -var harness = helpers.harness(__filename, helpers.noopTest, helpers.noopTest); -var it = harness.it; -var nano = harness.locals.nano; - -it('should be able to track updates in couch', function(assert) { - var called = false; - - function getUpdates() { - nano.updates(function(err, updates) { - if (called) { - return; - } - called = true; - - if (err && updates.error && updates.error === 'illegal_database_name') { - // - // older couches - // - assert.expect(1); - assert.ok(updates.ok, 'db updates are not supported'); - assert.end(); - } else { - // - // new couches - // - assert.equal(err, null, 'got root'); - assert.ok(updates.ok, 'updates are ok'); - assert.equal(updates.type, 'created', 'update was a create'); - assert.equal(updates['db_name'], 'mydb', 'mydb was updated'); - assert.end(); - } - }); - - setTimeout(function() { nano.db.create('mydb'); }, 50); - } - - nano.db.destroy('mydb', getUpdates); -}); - -it('should destroy mydb', function(assert) { - nano.db.destroy('mydb', function(err) { - assert.equal(err, null, 'no errors'); - assert.end(); - }); -});
