mirror of
https://github.com/donl/slouch.git
synced 2026-05-31 06:12:20 -06:00
* doc(readme): clean up reasons * doc(motto) * test(db-and-doc): more coverage * test(create-or-update-ignore-conflict) * test(upsert) * test(ignore-missing) * test(post-and-ignore-conflict) * test(get-merge-put) * refactor(all): rename post and put * test(get-merge-create-or-update) * test(get-merge-update-ignore-conflict) * test(get-merge-upsert) * test(get-modify-upsert) * refactor(doc): redundant code * test(destroy-ignore-conflict) * test(get-and-destroy) * test(mark-as-destroyed) * test(set-destroyed) * refactor(attachment) * test(doc): 100% coverage * test(attachment): create with base 64 * test(attachment): clean up binary code * test(attachment): get * test(attachment): destroy * test(system): is couchdb 1 * test(system): get * test(system): reset * test(updates) * test(updates) * test(all): unique DB names * test(system): reactivate tests * test(user): add role * test(user): downsert role * feat(stream-iterator): indefinite * test(user): 100% coverage * test(request-class) * test(request-class): 100% coverage * test(config) * test(config): more coverage * test(config): more coverage * test(config): 100% coverage * test(all): 100% coverage * refactor(beautify) * test(coverage): enforce 100% * test(system): fix race condition * test(user): shortcut for browser * test(updates): test continuous stream in phantomjs * test(updates): test continuous stream in phantomjs * test(continuous): mock for phantomjs * test(system): abort iterators * test(system): fake abort
94 lines
2.1 KiB
JavaScript
94 lines
2.1 KiB
JavaScript
'use strict';
|
|
|
|
var RequestClass = require('../../scripts/request-class'),
|
|
sporks = require('sporks'),
|
|
Backoff = require('backoff-promise'),
|
|
Promise = require('sporks/scripts/promise');
|
|
|
|
describe('request-class', function () {
|
|
|
|
var consoleLog = console.log,
|
|
request = null;
|
|
|
|
beforeEach(function () {
|
|
request = new RequestClass();
|
|
|
|
// Shorten the backoff
|
|
request._newBackoff = function () {
|
|
return new Backoff(10);
|
|
};
|
|
});
|
|
|
|
afterEach(function () {
|
|
// Restore console log
|
|
console.log = consoleLog;
|
|
|
|
RequestClass.LOG_EVERYTHING = false;
|
|
});
|
|
|
|
it('should log', function () {
|
|
RequestClass.LOG_EVERYTHING = true;
|
|
|
|
var logged = null;
|
|
|
|
// Spy
|
|
console.log = function (str) {
|
|
logged = str;
|
|
};
|
|
|
|
request._log('foo');
|
|
logged.should.eql('foo');
|
|
});
|
|
|
|
it('should get 404 status code', function () {
|
|
request._getStatusCode({
|
|
reason: 'Could not open source database'
|
|
}).should.eql(404);
|
|
});
|
|
|
|
it('should handle malformed error', function () {
|
|
// Fake
|
|
request._req = function () {
|
|
return Promise.resolve(null);
|
|
};
|
|
|
|
return sporks.shouldThrow(function () {
|
|
return request._request();
|
|
});
|
|
});
|
|
|
|
it('should reconnect when all DBs active', function () {
|
|
var err = new Error('all_dbs_active');
|
|
request._shouldReconnect(err).should.eql(true);
|
|
});
|
|
|
|
it('should throw error reach max retries', function () {
|
|
var err = new Error('all_dbs_active');
|
|
|
|
// Fake
|
|
request._request = function () {
|
|
return sporks.promiseError(err);
|
|
};
|
|
|
|
return sporks.shouldThrow(function () {
|
|
return request.request();
|
|
}, err);
|
|
});
|
|
|
|
it('should ignore default_authentication_handler errors when requesting', function () {
|
|
var err = new Error('default_authentication_handler');
|
|
|
|
// Fake
|
|
request._request = function () {
|
|
return sporks.promiseError(err);
|
|
};
|
|
|
|
return request.request();
|
|
});
|
|
|
|
it('should set max connections', function () {
|
|
request.setMaxConnections(2);
|
|
request._throttler.getMaxConcurrentProcesses().should.eql(2);
|
|
});
|
|
|
|
});
|