/*!
 * unit asserts to ensure delivery of payload within
 * HTTP POST/PUT requests works
 *
 * @author pfleidi
 */


var assert = require('assert');
var Helper = require('./test_helper');
var HttpClient = require('../index');
var client = HttpClient.createClient();

function _assertWithPayload(beforeExit, verb, payload) {
  var callbacks = 0;
  var echoServer = Helper.echoServer();
  var upCase = verb.toUpperCase();

  client[verb](echoServer.url + '/foo', payload)
  .on('success', function (data, resp) {
      callbacks += 1;
      var req = JSON.parse(data);
      assert.ok(data, 'Data must be provided');
      assert.ok(resp, 'Response must be provided');
      assert.strictEqual(req.method, upCase);
      assert.strictEqual(req.url, '/foo');
      assert.strictEqual(req.headers['user-agent'], 'node-wwwdude');
      assert.equal(req.headers['content-length'], payload.length);
      assert.strictEqual(req.payload, payload);
    })
  .on('complete', function (data, resp) {
      callbacks += 1;
    });

  beforeExit(function () {
      assert.strictEqual(callbacks, 2, 'Ensure all callbacks are called');
    });

}

exports.assertPayloadPut = function (beforeExit) {
  _assertWithPayload(beforeExit, 'put', 'ASAldfjsl');
};

exports.assertPayloadPost = function (beforeExit) {
  _assertWithPayload(beforeExit, 'post', '2342HurrDurrDerp!');
};

@@ -215,24 +215,25 @@
 ../index');%0A
+%0A
 var client =
@@ -257,16 +257,50 @@
 eClient(
+%7B%0A    parseContent: JSON.parse%0A  %7D
 );%0A%0Afunc
@@ -565,42 +565,8 @@
  1;%0A
-      var req = JSON.parse(data);%0A
     
@@ -686,19 +686,20 @@
 ctEqual(
-req
+data
 .method,
@@ -733,19 +733,20 @@
 ctEqual(
-req
+data
 .url, '/
@@ -773,27 +773,28 @@
 strictEqual(
-req
+data
 .headers%5B'us
@@ -841,19 +841,20 @@
 t.equal(
-req
+data
 .headers
@@ -915,19 +915,20 @@
 ctEqual(
-req
+data
 .payload

Add test for content parser