Spaces:
Sleeping
Sleeping
File size: 1,332 Bytes
05a77ff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
/*
* simple-test.js: Simple tests for basic streaming and non-streaming HTTP requests with union.
*
* (C) 2011, Charlie Robbins & the Contributors
* MIT LICENSE
*
*/
var assert = require('assert'),
connect = require('connect'),
request = require('request'),
vows = require('vows'),
union = require('../');
vows.describe('union/body-parser').addBatch({
"When using union with connect body parsing via urlencoded() or json()": {
topic: function () {
union.createServer({
buffer: false,
before: [
connect.urlencoded(),
connect.json(),
function (req, res) {
res.end(JSON.stringify(req.body, true, 2));
}
]
}).listen(8082, this.callback);
},
"a request to /": {
topic: function () {
request.post({
uri: 'http://localhost:8082/',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({ a: "foo", b: "bar" })
}, this.callback);
},
"should respond with a body-decoded object": function (err, res, body) {
assert.isNull(err);
assert.equal(res.statusCode, 200);
assert.deepEqual(
JSON.parse(body),
{ a: 'foo', b: 'bar' }
);
}
}
}
}).export(module);
|