Skip to content

Commit

Permalink
Merge pull request #1 from jrford/patch-1
Browse files Browse the repository at this point in the history
Adding a test for default agent requests
  • Loading branch information
bkuker committed Aug 3, 2018
2 parents bf38a51 + c69fad7 commit 57d7d74
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,49 @@ describe('request', function () {
.then(done, done);
});

it('agent can be used to set default headers', function (done){
var agent = request.agent('https://httpbin.org');
agent.set("Header-Name", "header_value");

agent
.get('/headers')
.then(function (res){
res.should.have.status(200);
res.body.headers.should.have.property('Header-Name').that.equals("header_value");
agent.close();
})
.then(done, done);
});

it('agent can be used to set default baerer authentication', function (done){
var agent = request.agent('https://httpbin.org');
agent.set("Authorization", "Bearer test_bearer");

agent
.get('/bearer')
.then(function (res){
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('authenticated').that.equals(true);
res.body.should.have.property('token').that.equals("test_bearer");
agent.close();
})
.then(done, done);
});

it('agent can be used to set default basic authentication', function (done){
var agent = request.agent('https://httpbin.org');
agent.auth("user", "passwd");

agent
.get('/basic-auth/user/passwd')
.then(function (res){
res.should.have.status(200);
agent.close();
})
.then(done, done);
});

it('automatically closes the server down once done with it', function (done) {
var server = require('http').createServer(function (req, res) {
res.writeHeader(200, { 'content-type' : 'text/plain' });
Expand Down

0 comments on commit 57d7d74

Please sign in to comment.