2013-11-14 19:30:56 +00:00
|
|
|
|
2015-10-11 22:59:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-05 18:23:47 +00:00
|
|
|
const context = require('../context');
|
2013-11-14 19:30:56 +00:00
|
|
|
|
|
|
|
describe('ctx.toJSON()', function(){
|
|
|
|
it('should return a json representation', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2013-11-14 19:30:56 +00:00
|
|
|
|
|
|
|
ctx.req.method = 'POST';
|
|
|
|
ctx.req.url = '/items';
|
|
|
|
ctx.req.headers['content-type'] = 'text/plain';
|
|
|
|
ctx.status = 200;
|
|
|
|
ctx.body = '<p>Hey</p>';
|
|
|
|
|
2015-10-05 18:23:47 +00:00
|
|
|
const obj = JSON.parse(JSON.stringify(ctx));
|
|
|
|
const req = obj.request;
|
|
|
|
const res = obj.response;
|
2013-11-14 19:30:56 +00:00
|
|
|
|
|
|
|
req.should.eql({
|
|
|
|
method: 'POST',
|
|
|
|
url: '/items',
|
|
|
|
header: {
|
|
|
|
'content-type': 'text/plain'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
res.should.eql({
|
|
|
|
status: 200,
|
2014-10-01 12:12:20 +00:00
|
|
|
message: 'OK',
|
2013-11-14 19:30:56 +00:00
|
|
|
header: {
|
|
|
|
'content-type': 'text/html; charset=utf-8',
|
|
|
|
'content-length': '10'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
2014-10-01 12:12:20 +00:00
|
|
|
})
|