2013-11-13 17:01:15 +00:00
|
|
|
|
2015-10-11 22:59:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2013-11-13 17:01:15 +00:00
|
|
|
var context = require('../context');
|
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
describe('ctx.type=', function(){
|
|
|
|
describe('with a mime', function(){
|
|
|
|
it('should set the Content-Type', function(){
|
|
|
|
var ctx = context();
|
|
|
|
ctx.type = 'text/plain';
|
2014-02-14 17:16:39 +00:00
|
|
|
ctx.type.should.equal('text/plain');
|
2014-04-09 16:34:50 +00:00
|
|
|
ctx.response.header['content-type'].should.equal('text/plain; charset=utf-8');
|
2013-11-13 17:01:15 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with an extension', function(){
|
|
|
|
it('should lookup the mime', function(){
|
|
|
|
var ctx = context();
|
|
|
|
ctx.type = 'json';
|
2014-02-14 17:16:39 +00:00
|
|
|
ctx.type.should.equal('application/json');
|
2014-06-04 04:44:25 +00:00
|
|
|
ctx.response.header['content-type'].should.equal('application/json; charset=utf-8');
|
2013-11-13 17:01:15 +00:00
|
|
|
})
|
|
|
|
})
|
2014-04-09 16:34:50 +00:00
|
|
|
|
|
|
|
describe('without a charset', function(){
|
|
|
|
it('should default the charset', function(){
|
|
|
|
var ctx = context();
|
|
|
|
ctx.type = 'text/html';
|
|
|
|
ctx.type.should.equal('text/html');
|
|
|
|
ctx.response.header['content-type'].should.equal('text/html; charset=utf-8');
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with a charset', function(){
|
|
|
|
it('should not default the charset', function(){
|
|
|
|
var ctx = context();
|
|
|
|
ctx.type = 'text/html; charset=foo';
|
|
|
|
ctx.type.should.equal('text/html');
|
|
|
|
ctx.response.header['content-type'].should.equal('text/html; charset=foo');
|
|
|
|
})
|
|
|
|
})
|
2014-06-06 23:26:03 +00:00
|
|
|
|
|
|
|
describe('with an unknown extension', function(){
|
2015-10-19 04:15:50 +00:00
|
|
|
it('should not set a content-type', function(){
|
2014-06-06 23:26:03 +00:00
|
|
|
var ctx = context();
|
|
|
|
ctx.type = 'asdf';
|
2015-10-19 04:15:50 +00:00
|
|
|
assert(!ctx.type);
|
|
|
|
assert(!ctx.response.header['content-type']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-11-13 17:01:15 +00:00
|
|
|
|
|
|
|
describe('ctx.type', function(){
|
|
|
|
describe('with no Content-Type', function(){
|
2015-04-28 17:44:02 +00:00
|
|
|
it('should return ""', function(){
|
2013-11-13 17:01:15 +00:00
|
|
|
var ctx = context();
|
2016-03-01 23:01:32 +00:00
|
|
|
// this is lame
|
2015-04-28 17:44:02 +00:00
|
|
|
assert('' === ctx.type);
|
2013-11-13 17:01:15 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with a Content-Type', function(){
|
|
|
|
it('should return the mime', function(){
|
|
|
|
var ctx = context();
|
2014-02-14 17:16:39 +00:00
|
|
|
ctx.type = 'json';
|
|
|
|
ctx.type.should.equal('application/json');
|
2013-11-13 17:01:15 +00:00
|
|
|
})
|
|
|
|
})
|
2014-06-04 04:44:25 +00:00
|
|
|
})
|