You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3 KiB

7 years ago
  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. var assert = require('assert'),
  9. connect = require('connect'),
  10. request = require('request'),
  11. vows = require('vows'),
  12. union = require('../');
  13. vows.describe('union/body-parser').addBatch({
  14. "When using union with connect body parsing via urlencoded() or json()": {
  15. topic: function () {
  16. union.createServer({
  17. buffer: false,
  18. before: [
  19. connect.urlencoded(),
  20. connect.json(),
  21. function (req, res) {
  22. res.end(JSON.stringify(req.body, true, 2));
  23. }
  24. ]
  25. }).listen(8082, this.callback);
  26. },
  27. "a request to /": {
  28. topic: function () {
  29. request.post({
  30. uri: 'http://localhost:8082/',
  31. headers: {
  32. 'content-type': 'application/json'
  33. },
  34. body: JSON.stringify({ a: "foo", b: "bar" })
  35. }, this.callback);
  36. },
  37. "should respond with a body-decoded object": function (err, res, body) {
  38. assert.isNull(err);
  39. assert.equal(res.statusCode, 200);
  40. assert.deepEqual(
  41. JSON.parse(body),
  42. { a: 'foo', b: 'bar' }
  43. );
  44. }
  45. }
  46. }
  47. }).export(module);