tests: update req.is tests to run through express
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 7ef92f8 · Browse files · 1 file·+133 added−68 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+133 added−68 removed
- tests:+133 added−68 removed
Provenance
- Commit
eb326d7- Tree
47eeebb- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
7ef92f8
1 file changed+133 added−68 removed
modified:test/req.is.js+133 added-68 removed
123234567891011125678914151011121317181920211415161718192021222324252627282930313233343536373839404142434445464748495025262728515253545556575859606162636465333435366667683839406970717273747576777879804445464748818283845051528586878889909192939454955657585960969798626364991001011021031041051061071081096768697071110111112737475113114115116117118119120121122123124125818283841261271288687881291301311321331341351361371381399192939495140141142979899143144145146147148149150151152153154155156157158159160161162163164165166167168
var express = require('../') , request = require('supertest');var express = require('..')var request = require('supertest')
function req(ct) { var req = { headers: { 'content-type': ct, 'transfer-encoding': 'chunked' }, __proto__: express.request };describe('req.is()', function () { describe('when given a mime type', function () { it('should return the type when matching', function (done) { var app = express()
return req;} app.use(function (req, res) { res.json(req.is('application/json')) })
describe('req.is()', function(){ it('should ignore charset', function(){ req('application/json') .is('json') .should.equal('json'); request(app) .post('/') .type('application/json') .send('{}') .expect(200, '"application/json"', done) })
it('should return false when not matching', function (done) { var app = express()
app.use(function (req, res) { res.json(req.is('image/jpeg')) })
request(app) .post('/') .type('application/json') .send('{}') .expect(200, 'false', done) })
it('should ignore charset', function (done) { var app = express()
app.use(function (req, res) { res.json(req.is('application/json')) })
request(app) .post('/') .type('application/json; charset=UTF-8') .send('{}') .expect(200, '"application/json"', done) }) })
describe('when content-type is not present', function(){ it('should return false', function(){ req('') .is('json') .should.be.false; it('should return false', function (done) { var app = express()
app.use(function (req, res) { res.json(req.is('application/json')) })
request(app) .post('/') .send('{}') .expect(200, 'false', done) }) })
describe('when given an extension', function(){ it('should lookup the mime type', function(){ req('application/json') .is('json') .should.equal('json'); it('should lookup the mime type', function (done) { var app = express()
req('text/html') .is('json') .should.be.false; app.use(function (req, res) { res.json(req.is('json')) })
request(app) .post('/') .type('application/json') .send('{}') .expect(200, '"json"', done) }) })
describe('when given a mime type', function(){ it('should match', function(){ req('application/json') .is('application/json') .should.equal('application/json'); describe('when given */subtype', function(){ it('should return the full type when matching', function (done) { var app = express()
req('image/jpeg') .is('application/json') .should.be.false; app.use(function (req, res) { res.json(req.is('*/json')) })
request(app) .post('/') .type('application/json') .send('{}') .expect(200, '"application/json"', done) }) })
describe('when given */subtype', function(){ it('should match', function(){ req('application/json') .is('*/json') .should.equal('application/json'); it('should return false when not matching', function (done) { var app = express()
req('image/jpeg') .is('*/json') .should.be.false; app.use(function (req, res) { res.json(req.is('*/html')) })
request(app) .post('/') .type('application/json') .send('{}') .expect(200, 'false', done) })
describe('with a charset', function(){ it('should match', function(){ req('text/html; charset=utf-8') .is('*/html') .should.equal('text/html'); it('should ignore charset', function (done) { var app = express()
req('text/plain; charset=utf-8') .is('*/html') .should.be.false; app.use(function (req, res) { res.json(req.is('*/json')) })
request(app) .post('/') .type('application/json; charset=UTF-8') .send('{}') .expect(200, '"application/json"', done) }) })
describe('when given type/*', function(){ it('should match', function(){ req('image/png') .is('image/*') .should.equal('image/png'); it('should return the full type when matching', function (done) { var app = express()
req('text/html') .is('image/*') .should.be.false; app.use(function (req, res) { res.json(req.is('application/*')) })
request(app) .post('/') .type('application/json') .send('{}') .expect(200, '"application/json"', done) })
describe('with a charset', function(){ it('should match', function(){ req('text/html; charset=utf-8') .is('text/*') .should.equal('text/html'); it('should return false when not matching', function (done) { var app = express()
req('something/html; charset=utf-8') .is('text/*') .should.be.false; app.use(function (req, res) { res.json(req.is('text/*')) })
request(app) .post('/') .type('application/json') .send('{}') .expect(200, 'false', done) })
it('should ignore charset', function (done) { var app = express()
app.use(function (req, res) { res.json(req.is('application/*')) })
request(app) .post('/') .type('application/json; charset=UTF-8') .send('{}') .expect(200, '"application/json"', done) }) })})