Skip to content

Commit

Permalink
Added prefix option for agents
Browse files Browse the repository at this point in the history
  • Loading branch information
Thann committed Mar 7, 2018
1 parent 199506d commit 02aa70f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/agent.js
Expand Up @@ -29,6 +29,7 @@ function TestAgent(app, options) {
this._ca = options.ca;
this._key = options.key;
this._cert = options.cert;
this._prefix = options.prefix;
}
Agent.call(this);
this.app = app;
Expand All @@ -43,7 +44,8 @@ TestAgent.prototype.__proto__ = Agent.prototype;
// override HTTP verb methods
methods.forEach(function(method) {
TestAgent.prototype[method] = function(url, fn) { // eslint-disable-line no-unused-vars
var req = new Test(this.app, method.toUpperCase(), url);
// TODO: support prefix on actual urls
var req = new Test(this.app, method.toUpperCase(), (this._prefix || '') + url);
req.ca(this._ca);
req.cert(this._cert);
req.key(this._key);
Expand Down
11 changes: 11 additions & 0 deletions test/supertest.js
Expand Up @@ -815,6 +815,17 @@ describe('request.agent(app)', function() {
});
});

describe('request.agent(app, {prefix})', function() {
it('should apply prefix', function(done) {
var app = express();
var agent = request.agent(app, { prefix: '/api' });

agent
.get('/dummy')
.expect(404, 'Cannot GET /api/dummy\n', done);
});
});

describe('.<http verb> works as expected', function() {
it('.delete should work', function (done) {
var app = express();
Expand Down

0 comments on commit 02aa70f

Please sign in to comment.