forked from expressjs/express
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
148 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
var express = require('../') | ||
, request = require('./support/http') | ||
, utils = require('../lib/utils'); | ||
|
||
var app = express(); | ||
|
||
app.use(function(req, res, next){ | ||
res.respondTo({ | ||
'text/plain': function(){ | ||
res.type('text').send('hey'); | ||
}, | ||
|
||
'text/html': function(){ | ||
res.send('<p>hey</p>'); | ||
}, | ||
|
||
'appliation/json': function(){ | ||
res.send({ message: 'hey' }); | ||
} | ||
}); | ||
}); | ||
|
||
app.use(function(err, req, res, next){ | ||
res.send(406, 'Supports: ' + err.types.join(', ')); | ||
}) | ||
|
||
describe('req', function(){ | ||
describe('.respondTo(obj)', function(){ | ||
it('should utilize qvalues in negotiation', function(done){ | ||
request(app) | ||
.get('/') | ||
.set('Accept', 'text/html; q=.5, appliation/json, */*; q=.1') | ||
.expect('{"message":"hey"}', done); | ||
}) | ||
|
||
it('should allow wildcard type/subtypes', function(done){ | ||
request(app) | ||
.get('/') | ||
.set('Accept', 'text/html; q=.5, appliation/*, */*; q=.1') | ||
.expect('{"message":"hey"}', done); | ||
}) | ||
|
||
describe('when Accept is not present', function(){ | ||
it('should invoke the first callback', function(done){ | ||
request(app) | ||
.get('/') | ||
.expect('hey', done); | ||
}) | ||
}) | ||
|
||
describe('when no match is made', function(){ | ||
it('should should respond with 406 not acceptable', function(done){ | ||
request(app) | ||
.get('/') | ||
.set('Accept', 'foo/bar') | ||
.end(function(res){ | ||
res.should.have.status(406); | ||
res.body.should.equal('Supports: text/plain, text/html, appliation/json'); | ||
done(); | ||
}); | ||
}) | ||
}) | ||
}) | ||
}) |