2014-02-14 17:38:59 +00:00
|
|
|
|
2015-10-11 22:59:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-12 04:59:30 +00:00
|
|
|
const request = require('../helpers/context').request;
|
2015-10-05 18:23:47 +00:00
|
|
|
const assert = require('assert');
|
2014-02-14 17:38:59 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('req.charset', () => {
|
|
|
|
describe('with no content-type present', () => {
|
|
|
|
it('should return ""', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const req = request();
|
2015-04-28 17:44:02 +00:00
|
|
|
assert('' === req.charset);
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
2014-02-14 17:38:59 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('with charset present', () => {
|
|
|
|
it('should return ""', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const req = request();
|
2014-02-14 17:38:59 +00:00
|
|
|
req.header['content-type'] = 'text/plain';
|
2015-04-28 17:44:02 +00:00
|
|
|
assert('' === req.charset);
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
2014-02-14 17:38:59 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('with a charset', () => {
|
|
|
|
it('should return the charset', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const req = request();
|
2014-02-14 17:38:59 +00:00
|
|
|
req.header['content-type'] = 'text/plain; charset=utf-8';
|
|
|
|
req.charset.should.equal('utf-8');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
2017-02-13 03:05:35 +00:00
|
|
|
|
|
|
|
it('should return "" if content-type is invalid', () => {
|
|
|
|
const req = request();
|
|
|
|
req.header['content-type'] = 'application/json; application/text; charset=utf-8';
|
|
|
|
req.charset.should.equal('');
|
|
|
|
});
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|