slouch/test/utils.js
Geoff Cox 54a60e7a21 feat(auth): cookie authentication in node (#27)
* feat(cookie): request-wrapper

* test(request-wrapper): 100% coverage

* test(browser): 100% coverage

* refactor(request-class): rename to enhanced-request

* feat(get-session)

* feat(enhanced-request): full response

* refactor(enhanced-request): enhanced opts

* feat(example): authentication
2017-09-23 04:49:07 -07:00

36 lines
1,023 B
JavaScript

'use strict';
var config = require('./config.json'),
Slouch = require('../scripts');
var Utils = function () {
this._dbId = 0;
this.createdDB = null;
this._slouch = new Slouch(this.couchDBURL());
};
Utils.prototype.couchDBURL = function () {
return config.couchdb.scheme + '://' + config.couchdb.username + ':' +
config.couchdb.password + '@' + config.couchdb.host + ':' + config.couchdb.port;
};
Utils.prototype.couchDBURLNoAuth = function () {
return config.couchdb.scheme + '://' + config.couchdb.host + ':' + config.couchdb.port;
};
Utils.prototype.nextId = function () {
return this._dbId++;
};
// Use unique DB names for each tests as there can be race conditions where a DB is destroyed, but
// has not yet been fully released.
Utils.prototype.createDB = function () {
this.createdDB = 'test_' + this.nextId();
return this._slouch.db.create(this.createdDB);
};
Utils.prototype.destroyDB = function () {
return this._slouch.db.destroy(this.createdDB);
};
module.exports = new Utils();