Skip to content

Commit

Permalink
test(database): initial
Browse files Browse the repository at this point in the history
  • Loading branch information
boennemann committed Nov 26, 2015
1 parent ce6cd36 commit dcd70ce
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"hoodie-admin-dashboard": "^3.1.0",
"hoodie-client": "^2.2.0",
"nyc": "^3.2.2",
"proxyquire": "^1.7.3",
"rimraf": "^2.4.3",
"semantic-release": "^4.3.5",
"standard": "^5.3.1",
Expand Down Expand Up @@ -69,6 +70,6 @@
"pretest": "standard",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"start": "bin/start",
"test": "nyc tap --no-cov ./test/integration/*.js"
"test": "nyc tap --no-cov ./test/{unit,integration}/*.js"
}
}
50 changes: 50 additions & 0 deletions test/unit/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var test = require('tap').test
var proxyquire = require('proxyquire')

test('database api', function (t) {
t.test('use default adapter', function (tt) {
function PouchDB (name) {
this.name = name
}
PouchDB['@noCallThru'] = true
PouchDB.defaults = function (db) {
tt.is(db.foo, 'foo', 'correct pouch config passed')
PouchDB.foo = 'foo'
return PouchDB
}

var database = proxyquire('../../lib/database', {
pouchdb: PouchDB
})({db: {foo: 'foo'}})

tt.is(database.PouchDB, PouchDB, 'exposes pouch constructor')
tt.is(database.PouchDB.foo, 'foo', 'exposes pouch constructor with defaults')

var db = database('db-name')

tt.ok(db instanceof PouchDB, 'factory returns pouch instance')
tt.is(db.name, 'db-name', 'factory returns pouch instance with name')
tt.end()
})

t.test('use http adapter', function (tt) {
function PouchDB (name) {
this.name = name
}
PouchDB['@noCallThru'] = true
PouchDB.defaults = function (db) {
return PouchDB
}

var database = proxyquire('../../lib/database', {
pouchdb: PouchDB
})({db: {url: 'http://example.com'}})

var db = database('db-name')

tt.is(db.name, 'http://example.com/db-name', 'factory returns pouch instance with couch url')
tt.end()
})

t.end()
})

0 comments on commit dcd70ce

Please sign in to comment.