2014-06-13 07:30:59 +00:00
|
|
|
|
2015-10-11 22:59:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-12 04:59:30 +00:00
|
|
|
const context = require('../helpers/context');
|
2015-10-05 18:23:47 +00:00
|
|
|
const assert = require('assert');
|
2014-06-13 07:30:59 +00:00
|
|
|
|
|
|
|
describe('response.is(type)', function(){
|
|
|
|
it('should ignore params', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const res = context().response;
|
2014-06-13 07:30:59 +00:00
|
|
|
res.type = 'text/html; charset=utf-8';
|
|
|
|
|
|
|
|
res.is('text/*').should.equal('text/html');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
2014-06-13 07:30:59 +00:00
|
|
|
|
|
|
|
describe('when no type is set', function(){
|
|
|
|
it('should return false', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const res = context().response;
|
2014-06-13 07:30:59 +00:00
|
|
|
|
|
|
|
assert(false === res.is());
|
|
|
|
assert(false === res.is('html'));
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
2014-06-13 07:30:59 +00:00
|
|
|
|
|
|
|
describe('when given no types', function(){
|
|
|
|
it('should return the type', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const res = context().response;
|
2014-06-13 07:30:59 +00:00
|
|
|
res.type = 'text/html; charset=utf-8';
|
|
|
|
|
|
|
|
res.is().should.equal('text/html');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
2014-06-13 07:30:59 +00:00
|
|
|
|
|
|
|
describe('given one type', function(){
|
|
|
|
it('should return the type or false', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const res = context().response;
|
2014-06-13 07:30:59 +00:00
|
|
|
res.type = 'image/png';
|
|
|
|
|
|
|
|
res.is('png').should.equal('png');
|
|
|
|
res.is('.png').should.equal('.png');
|
|
|
|
res.is('image/png').should.equal('image/png');
|
|
|
|
res.is('image/*').should.equal('image/png');
|
|
|
|
res.is('*/png').should.equal('image/png');
|
|
|
|
|
|
|
|
res.is('jpeg').should.be.false;
|
|
|
|
res.is('.jpeg').should.be.false;
|
|
|
|
res.is('image/jpeg').should.be.false;
|
|
|
|
res.is('text/*').should.be.false;
|
|
|
|
res.is('*/jpeg').should.be.false;
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
2014-06-13 07:30:59 +00:00
|
|
|
|
|
|
|
describe('given multiple types', function(){
|
|
|
|
it('should return the first match or false', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const res = context().response;
|
2014-06-13 07:30:59 +00:00
|
|
|
res.type = 'image/png';
|
|
|
|
|
|
|
|
res.is('png').should.equal('png');
|
|
|
|
res.is('.png').should.equal('.png');
|
|
|
|
res.is('text/*', 'image/*').should.equal('image/png');
|
|
|
|
res.is('image/*', 'text/*').should.equal('image/png');
|
|
|
|
res.is('image/*', 'image/png').should.equal('image/png');
|
|
|
|
res.is('image/png', 'image/*').should.equal('image/png');
|
|
|
|
|
2014-07-06 08:43:14 +00:00
|
|
|
res.is(['text/*', 'image/*']).should.equal('image/png');
|
|
|
|
res.is(['image/*', 'text/*']).should.equal('image/png');
|
|
|
|
res.is(['image/*', 'image/png']).should.equal('image/png');
|
|
|
|
res.is(['image/png', 'image/*']).should.equal('image/png');
|
|
|
|
|
2014-06-13 07:30:59 +00:00
|
|
|
res.is('jpeg').should.be.false;
|
|
|
|
res.is('.jpeg').should.be.false;
|
|
|
|
res.is('text/*', 'application/*').should.be.false;
|
|
|
|
res.is('text/html', 'text/plain', 'application/json; charset=utf-8').should.be.false;
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
2014-06-13 07:30:59 +00:00
|
|
|
|
|
|
|
describe('when Content-Type: application/x-www-form-urlencoded', function(){
|
|
|
|
it('should match "urlencoded"', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const res = context().response;
|
2014-06-13 07:30:59 +00:00
|
|
|
res.type = 'application/x-www-form-urlencoded';
|
|
|
|
|
|
|
|
res.is('urlencoded').should.equal('urlencoded');
|
|
|
|
res.is('json', 'urlencoded').should.equal('urlencoded');
|
|
|
|
res.is('urlencoded', 'json').should.equal('urlencoded');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|