<commit_before>var _ = require('lodash');

var aliasedClientStubs = {};
var clientStubs = {};

/**
 * This module stubs the soap module to allow for offline
 * testing and stubbed clients.  All clients' methods are stubbed with sinon and have
 * additional functionality:
 *
 * <ul>
 * <li>.respondWithError() - Responds with the mocked client's sample error response.</li>
 * <li>.respondWithSuccess() - Responds with the mocked client's sample success response.</li>
 * </ul>
 *
 * Register a client by calling `.registerClient(urlToWsdl, clientStub)`.  For an
 * example client stub, see ./soap-stub-client-example.js.
 *
 * @property {Boolean} errOnCreateClient returns an error to the createClient method when set to true.
 */
module.exports = {
  createClient: createClient,
  createErroringStub: createErroringStub,
  createRespondingStub: createRespondingStub,
  errOnCreateClient: false,
  getStub: getStub,
  registerClient: registerClient,
  reset: reset,
  security: require('./lib/security')
};

/**
 * Return a stubbed client based on the value of wsdlUrl.
 *
 * @throws if wsdlUrl is unknown.
 *
 * @param {String} wsdlUrl
 * @param {Object} options
 * @param {Function} cb
 * @return {Object}
 */
function createClient(wsdlUrl, options, cb) {
  if (!cb) {
    cb = options;
    options = {};
  }

  if (this.errOnCreateClient) {
    return setTimeout(cb.bind(null, new Error('forced error on createClient')));
  }

  var client = getStub(wsdlUrl);

  if (client) {
    resetStubbedMethods(client);
    setTimeout(cb.bind(null, null, client));
  } else {
    setTimeout(cb.bind(null, new Error('no client stubbed for ' + wsdlUrl)));
  }
}

/**
 * Returns a method that calls all callbacks given to the method it is attached
 * to with the given error.
 *
 * <pre>
 * myClientStub.someMethod.errorOnCall = createErroringStub(error);
 *
 * // elsewhere
 *
 * myClientStub.someMethod.errorOnCall();
 * </pre>
 *
 * @param {?} object anything
 * @return {Function}
 */
function createErroringStub(err) {
  return function() {
    this.args.forEach(function(argSet) {
      setTimeout(argSet[1].bind(null, err));
    });
    this.yields(err);
  };
}

/**
 * Returns a method that calls all callbacks given to the method it is attached
 * to with the given response.
 *
 * <pre>
 * myClientStub.someMethod.respondWithError = createRespondingStub(errorResponse);
 *
 * // elsewhere
 *
 * myClientStub.someMethod.respondWithError();
 * </pre>
 *
 * @param {?} object anything
 * @return {Function}
 */
function createRespondingStub(object) {
  return function() {
    this.args.forEach(function(argSet) {
      setTimeout(argSet[1].bind(null, null, object));
    });
    this.yields(null, object);
  };<commit_msg>add body parameter (#897)<commit_after>var _ = require('lodash');

var aliasedClientStubs = {};
var clientStubs = {};

/**
 * This module stubs the soap module to allow for offline
 * testing and stubbed clients.  All clients' methods are stubbed with sinon and have
 * additional functionality:
 *
 * <ul>
 * <li>.respondWithError() - Responds with the mocked client's sample error response.</li>
 * <li>.respondWithSuccess() - Responds with the mocked client's sample success response.</li>
 * </ul>
 *
 * Register a client by calling `.registerClient(urlToWsdl, clientStub)`.  For an
 * example client stub, see ./soap-stub-client-example.js.
 *
 * @property {Boolean} errOnCreateClient returns an error to the createClient method when set to true.
 */
module.exports = {
  createClient: createClient,
  createErroringStub: createErroringStub,
  createRespondingStub: createRespondingStub,
  errOnCreateClient: false,
  getStub: getStub,
  registerClient: registerClient,
  reset: reset,
  security: require('./lib/security')
};

/**
 * Return a stubbed client based on the value of wsdlUrl.
 *
 * @throws if wsdlUrl is unknown.
 *
 * @param {String} wsdlUrl
 * @param {Object} options
 * @param {Function} cb
 * @return {Object}
 */
function createClient(wsdlUrl, options, cb) {
  if (!cb) {
    cb = options;
    options = {};
  }

  if (this.errOnCreateClient) {
    return setTimeout(cb.bind(null, new Error('forced error on createClient')));
  }

  var client = getStub(wsdlUrl);

  if (client) {
    resetStubbedMethods(client);
    setTimeout(cb.bind(null, null, client));
  } else {
    setTimeout(cb.bind(null, new Error('no client stubbed for ' + wsdlUrl)));
  }
}

/**
 * Returns a method that calls all callbacks given to the method it is attached
 * to with the given error.
 *
 * <pre>
 * myClientStub.someMethod.errorOnCall = createErroringStub(error);
 *
 * // elsewhere
 *
 * myClientStub.someMethod.errorOnCall();
 * </pre>
 *
 * @param {?} object anything
 * @return {Function}
 */
function createErroringStub(err) {
  return function() {
    this.args.forEach(function(argSet) {
      setTimeout(argSet[1].bind(null, err));
    });
    this.yields(err);
  };
}

/**
 * Returns a method that calls all callbacks given to the method it is attached
 * to with the given response.
 *
 * <pre>
 * myClientStub.someMethod.respondWithError = createRespondingStub(errorResponse);
 *
 * // elsewhere
 *
 * myClientStub.someMethod.respondWithError();
 * </pre>
 *
 * @param {?} object anything
 * @return {Function}
 */
function createRespondingStub(object, body) {
  return function() {
    this.args.forEach(function(argSet) {
      setTimeout(argSet[1].bind(null, null, object));
    });
    this.yields(null, object, body);
  };
{'fraction_non_alphanumeric': 0.13117453347969266, 'fraction_numerical': 0.0012806439809732895, 'mean_word_length': 3.8899821109123436, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1817782', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1720, 'n_words': 475}