chore(test): requestDefaults tests Closes #296
diff --git a/tests/fixtures/shared/config.json b/tests/fixtures/shared/config.json index 148e0c1..d8d1f32 100644 --- a/tests/fixtures/shared/config.json +++ b/tests/fixtures/shared/config.json
@@ -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 }"
diff --git a/tests/integration/shared/config.js b/tests/integration/shared/config.js index 0b00e2e..0636e8d 100644 --- a/tests/integration/shared/config.js +++ b/tests/integration/shared/config.js
@@ -146,3 +146,50 @@ 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'); +}); +