From dcd70ce5e61b7027d34e1c5518a79e7ec2a00213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Thu, 26 Nov 2015 01:05:24 +0100 Subject: [PATCH] test(database): initial --- package.json | 3 ++- test/unit/database.js | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test/unit/database.js diff --git a/package.json b/package.json index 77aabf1..37a464c 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } } diff --git a/test/unit/database.js b/test/unit/database.js new file mode 100644 index 0000000..ae7ce09 --- /dev/null +++ b/test/unit/database.js @@ -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() +})