Skip to content

Commit

Permalink
Add a failing test case for using passThrough with baseURL
Browse files Browse the repository at this point in the history
  • Loading branch information
ctimmerm committed Jul 2, 2019
1 parent 436cbda commit 4fcf05e
Showing 1 changed file with 51 additions and 36 deletions.
87 changes: 51 additions & 36 deletions test/pass_through.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ describe('passThrough tests (requires Node)', function() {
resp.end();
} else {
resp.statusCode = 200;
// Reply with path minus leading /
resp.end(req.url.slice(1), 'utf8');
// Reply with path
resp.end(req.url, 'utf8');
}
})
.listen(0, '127.0.0.1', function() {
Expand All @@ -45,22 +45,20 @@ describe('passThrough tests (requires Node)', function() {
mock.onGet('/bar').passThrough();

return Promise.all([
instance.get('/foo')
.then(function(response) {
expect(response.status).to.equal(200);
expect(response.data).to.equal('bar');
}),
instance.get('/error')
.then(function(response) {
expect(response.status).to.equal(200);
expect(response.data).to.equal('success');
}),
instance.get('/bar')
.then(function(response) {
expect(response.status).to.equal(200);
expect(response.data).to.equal('bar');
}),
instance.get('/noHandler')
instance.get('/foo').then(function(response) {
expect(response.status).to.equal(200);
expect(response.data).to.equal('bar');
}),
instance.get('/error').then(function(response) {
expect(response.status).to.equal(200);
expect(response.data).to.equal('success');
}),
instance.get('/bar').then(function(response) {
expect(response.status).to.equal(200);
expect(response.data).to.equal('/bar');
}),
instance
.get('/noHandler')
.then(function(response) {
// Mock adapter should return an error
expect(true).to.be.false;
Expand All @@ -74,7 +72,8 @@ describe('passThrough tests (requires Node)', function() {
it('handles errors correctly', function() {
mock.onGet('/error').passThrough();

return instance.get('/error')
return instance
.get('/error')
.then(function() {
// The server should've returned an error
expect(false).to.be.true;
Expand All @@ -86,27 +85,43 @@ describe('passThrough tests (requires Node)', function() {

it('allows setting default passThrough handler', function() {
mock
.onGet('/foo').reply(200, 'bar')
.onAny().passThrough();
.onGet('/foo')
.reply(200, 'bar')
.onAny()
.passThrough();

var randomPath = 'xyz' + Math.round(10000 * Math.random());

return Promise.all([
instance.get('/foo')
.then(function(response) {
expect(response.status).to.equal(200);
expect(response.data).to.equal('bar');
}),
instance.get('/' + randomPath)
.then(function(response) {
expect(response.status).to.equal(200);
expect(response.data).to.equal(randomPath);
}),
instance.post('/post')
.then(function(response) {
expect(response.status).to.equal(200);
expect(response.data).to.equal('post');
})
instance.get('/foo').then(function(response) {
expect(response.status).to.equal(200);
expect(response.data).to.equal('bar');
}),
instance.get('/' + randomPath).then(function(response) {
expect(response.status).to.equal(200);
expect(response.data).to.equal('/' + randomPath);
}),
instance.post('/post').then(function(response) {
expect(response.status).to.equal(200);
expect(response.data).to.equal('/post');
})
]);
});

it('handles baseURL correctly', function() {
instance = axios.create({
baseURL: '/test',
proxy: {
host: '127.0.0.1',
port: httpServer.address().port
}
});
mock = new MockAdapter(instance);

mock.onAny().passThrough();
return instance.get('/foo').then(function(response) {
expect(response.status).to.equal(200);
expect(response.data).to.equal('http://null/test/foo');
});
});
});

0 comments on commit 4fcf05e

Please sign in to comment.