Skip to content

Commit

Permalink
Merge pull request #236 from pouchdb/http-pouchdb
Browse files Browse the repository at this point in the history
Finish monorepo merge: http-pouchdb
  • Loading branch information
gr2m committed Jun 26, 2017
2 parents 445e42e + 5a3d029 commit 70e3156
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"serve-favicon": "~2.3.2",
"tail": "^1.2.1",
"uuid": "^3.0.1",
"wordwrap": "1.0.0"
"wordwrap": "1.0.0",
"xhr2": "^0.1.3"
},
"devDependencies": {
"assert": "^1.4.1",
Expand Down
6 changes: 6 additions & 0 deletions packages/node_modules/http-pouchdb/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions packages/node_modules/http-pouchdb/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions packages/node_modules/http-pouchdb/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions packages/node_modules/http-pouchdb/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions tests/http-pouchdb/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const {PouchDB} = require('pouchdb-plugin-helper/testutils');
const buildHTTPPouchDB = require('../../packages/node_modules/http-pouchdb');
const should = require('chai').should();

var HTTPPouchDB = buildHTTPPouchDB(PouchDB, 'http://localhost:5984/');
var XMLHttpRequest = require('xhr2');
var Promise = require('bluebird');

describe('isHTTPPouchDB', function () {
it('should be set on the HTTPPouchDB object', function () {
HTTPPouchDB.isHTTPPouchDB.should.be.ok;
});
it('should not be set on the PouchDB object', function () {
should.not.exist(PouchDB.isHTTPPouchDB);
});
});

describe('constructor', function () {
it('should create remote databases for normal db names', function () {
var users = new HTTPPouchDB('_users');

return users.info().then(function (info) {
info.should.have.property('db_name');
});
});
});

describe('destroy', function () {
it("should be possible using the 'class method'", function (done) {
new HTTPPouchDB('test');
HTTPPouchDB.destroy('test', done);
});
it('should be possible using the method', function (done) {
var db = new HTTPPouchDB('test');
db.destroy(done);
});
});

describe('replicate', function () {
it('should work', function () {
HTTPPouchDB.replicate('test-a', 'test-b').on('complete', function (resp) {
resp.status.should.equal('complete');

return dbShouldExist('test-a').then(function () {
return dbShouldExist('test-b');
}).then(function () {
return new PouchDB('http://localhost:5984/test-a').destroy();
}).then(function () {
return new PouchDB('test-b').destroy();
});
});
});
});

function dbShouldExist(name) {
return new Promise(function (resolve) {
var xhr = new XMLHttpRequest();
xhr.onload = function () {
xhr.status.should.equal(200);
resolve();
};
xhr.open('HEAD', 'http://localhost:5984/' + name);
xhr.send();
});
}

describe('allDbs', function () {
it('should return the remote db list', function (done) {
HTTPPouchDB.allDbs(function (err, dbs) {
should.not.exist(err);
dbs.should.contain('_users');
dbs.should.contain('_replicator');

done();
});
});
});

0 comments on commit 70e3156

Please sign in to comment.