2013-11-13 17:01:15 +00:00
|
|
|
|
2015-10-11 22:59:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-05 18:23:47 +00:00
|
|
|
const context = require('../context');
|
|
|
|
const assert = require('assert');
|
2013-11-13 17:01:15 +00:00
|
|
|
|
|
|
|
describe('ctx.type=', function(){
|
|
|
|
describe('with a mime', function(){
|
|
|
|
it('should set the Content-Type', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2013-11-13 17:01:15 +00:00
|
|
|
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(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2013-11-13 17:01:15 +00:00
|
|
|
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(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2014-04-09 16:34:50 +00:00
|
|
|
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(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2014-04-09 16:34:50 +00:00
|
|
|
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(){
|
|
|
|
it('should default to application/octet-stream',function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2014-06-06 23:26:03 +00:00
|
|
|
ctx.type = 'asdf';
|
|
|
|
ctx.type.should.equal('application/octet-stream');
|
|
|
|
ctx.response.header['content-type'].should.equal('application/octet-stream');
|
|
|
|
})
|
|
|
|
})
|
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(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2014-02-14 17:16:39 +00:00
|
|
|
// TODO: 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(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const 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
|
|
|
})
|