<commit_before>/*!
 * 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({ contentParser: HttpClient.parsers.json});

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

  client[verb](echoServer.url + '/foo', { payload: payload })
  .on('success', function (data, resp) {
      callbacks += 1;
      assert.ok(data, 'Data must be provided');
      assert.ok(resp, 'Response must be provided');
      assert.strictEqual(data.method, upCase);
      assert.strictEqual(data.url, '/foo');
      assert.strictEqual(data.headers['user-agent'], 'node-wwwdude');
      assert.equal(data.headers['content-length'], payload.length);
      assert.strictEqual(data.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!');
};<commit_msg>Add test with umlaut content<commit_after>/*!
 * 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({ contentParser: HttpClient.parsers.json});

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

  client[verb](echoServer.url + '/foo', { payload: payload })
  .on('success', function (data, resp) {
      callbacks += 1;
      assert.ok(data, 'Data must be provided');
      assert.ok(resp, 'Response must be provided');
      assert.strictEqual(data.method, upCase);
      assert.strictEqual(data.url, '/foo');
      assert.strictEqual(data.headers['user-agent'], 'node-wwwdude');
      assert.equal(data.headers['content-length'], Buffer.byteLength(payload));
      assert.strictEqual(data.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!äääää');
};
{'fraction_non_alphanumeric': 0.15185444366689993, 'fraction_numerical': 0.005598320503848845, 'mean_word_length': 4.245871559633027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5263692', 'n_tokens_mistral': 895, 'n_tokens_neox': 866, 'n_words': 200}