Skip to content
This repository was archived by the owner on Nov 5, 2018. It is now read-only.

Request defaults tests #297

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -31,8 +31,7 @@
"jscs": "^1.7.0",
"nock": "^0.48.1",
"endswith": "^0.0.0",
"tape-it": "^0.3.1",
"pre-commit": "0.0.9"
"tape-it": "^0.3.1"
},
"scripts": {
"test": "DEBUG=* NOCK_OFF=true istanbul cover tape tests/*/*/*.js",
8 changes: 8 additions & 0 deletions tests/fixtures/shared/config.json
Original file line number Diff line number Diff line change
@@ -13,6 +13,14 @@
, { "path" : "/_all_dbs"
, "response" : "{}"
}
, { "path" : "/_all_dbs"
, "status" : 401
, "response" : "{}"
}
, { "path" : "/foo/_all_docs"
, "status" : 401
, "response" : "{}"
}
, { "method" : "delete"
, "path" : "/shared_config"
, "response" : "{ \"ok\": true }"
47 changes: 47 additions & 0 deletions tests/integration/shared/config.js
Original file line number Diff line number Diff line change
@@ -146,3 +146,50 @@ it('should prevent shallow object copies', function(assert) {

assert.end();
});

it('should accept requestDefaults', function(assert) {
var nanoWithDefaultHeaders = Nano({
url: helpers.couch,
requestDefaults: {
auth: {
user: 'wiki',
pass: 'pedia'
}
}
});

var req = nanoWithDefaultHeaders.db.list(function(err) {
assert.equal(err.statusCode, 401, 'should be access denied');
assert.end();
});

assert.equal(
req.headers['authorization'],
'Basic d2lraTpwZWRpYQ==',
'header `Authorization` honored');
});

it('should preserve requestDefaults on database api', function(assert) {
var nanoWithDefaultHeaders = Nano({
url: helpers.couch,
requestDefaults: {
auth: {
user: 'wiki',
pass: 'pedia'
}
}
});

var nanoDatabaseWithDefaultHeaders = nanoWithDefaultHeaders.use('foo');

var req = nanoDatabaseWithDefaultHeaders.list(function(err) {
assert.equal(err.statusCode, 401, 'should be access denied');
assert.end();
});

assert.equal(
req.headers['authorization'],
'Basic d2lraTpwZWRpYQ==',
'header `Authorization` honored');
});