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