2013-11-13 17:01:15 +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');
|
2013-11-13 17:01:15 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('ctx.type=', () => {
|
|
|
|
describe('with a mime', () => {
|
|
|
|
it('should set the Content-Type', () => {
|
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');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
2013-11-13 17:01:15 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('with an extension', () => {
|
|
|
|
it('should lookup the mime', () => {
|
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');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
2014-04-09 16:34:50 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('without a charset', () => {
|
|
|
|
it('should default the charset', () => {
|
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');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
2014-04-09 16:34:50 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('with a charset', () => {
|
|
|
|
it('should not default the charset', () => {
|
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');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
2014-06-06 23:26:03 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('with an unknown extension', () => {
|
|
|
|
it('should not set a content-type', () => {
|
2015-10-22 22:46:47 +00:00
|
|
|
const ctx = context();
|
2014-06-06 23:26:03 +00:00
|
|
|
ctx.type = 'asdf';
|
2015-10-19 04:15:50 +00:00
|
|
|
assert(!ctx.type);
|
|
|
|
assert(!ctx.response.header['content-type']);
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-11-13 17:01:15 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('ctx.type', () => {
|
|
|
|
describe('with no Content-Type', () => {
|
|
|
|
it('should return ""', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2015-10-31 13:01:26 +00:00
|
|
|
assert(!ctx.type);
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
2013-11-13 17:01:15 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('with a Content-Type', () => {
|
|
|
|
it('should return the mime', () => {
|
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');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|