src/lib/index.js
function makeRequest(baseUrl, method, schema, options, done) {
  debug(`making ${method.toUpperCase()} request to ${schema.endpoint}`);
  const endpoint = expandVars(schema.endpoint, options);
  const apiPath = url.resolve(baseUrl + "/", _.trimStart(endpoint, "/"));
  const headers = Object.assign({}, options.headers, schema.headers);
  const query = Object.assign({}, options.query, schema.query);
  const body = Object.assign({}, options.body, schema.body);

  let req = request[getMethodFuncName(method)](apiPath);

  // NOTE/deprecate: params
  if (schema.params) {
    deprecate("'params' property/extension in schema is deprecated. Use 'headers', 'query' or 'body' instead.");
    req = req[getParamFuncName(method)](schema.params);
  }
  if (Object.keys(headers).length) {
    expandVars(headers, options);
    for (let key in headers) {
      req = req.set(key, headers[key]);
    }
  }
  if (Object.keys(query).length) {
    expandVars(query, options);
    req = req.query(query);
  }
  if (Object.keys(body).length) {
    expandVars(body, options);
    req = req.send(body);
  }

  return req.end(function(error, response) {
    // catch network errors, etc.
    if (!response) {
      should(error).not.be.ok();
    }
    should(response).be.ok();
    should(response.body).be.ok();
    return validateResponse(schema, response, options, done);
  });
}
function makeRequest(baseUrl, method, schema, options, done) {
  debug(`making ${method.toUpperCase()} request to ${schema.endpoint}`);
  const endpoint = expandVars(schema.endpoint, options);
  const apiPath = url.resolve(baseUrl + "/", _.trimStart(endpoint, "/"));
  const headers = Object.assign({}, options.headers, schema.headers);
  const query = Object.assign({}, options.query, schema.query);
  const body = Object.assign({}, options.body, schema.body);

  let req = request[getMethodFuncName(method)](apiPath);

  // NOTE/deprecate: params
  if (schema.params) {
    deprecate("'params' property/extension in schema is deprecated. Use 'headers', 'query' or 'body' instead.");
    req = req[getParamFuncName(method)](schema.params);
  }
  if (Object.keys(headers).length) {
    expandVars(headers, options);
    for (let key in headers) {
      req = req.set(key, headers[key]);
    }
  }
  if (Object.keys(query).length) {
    expandVars(query, options);
    req = req.query(query);
  }
  if (Object.keys(body).length) {
    expandVars(body, options);
    req = req.send(body);
  }

  return req.end(function(error, response) {
    // catch network errors, etc.
    if (!response) {
      should(error).not.be.ok();
    }
    should(response).be.ok();
    should(response.body).be.ok();
    return validateResponse(schema, response, options, done);
  });
}
function makeRequest ( baseUrl , method , schema , options , done ) { debug ( ` ${ method . toUpperCase ( ) } ${ schema . endpoint } ` ) ; const endpoint = expandVars ( schema . endpoint , options ) ; const apiPath = url . resolve ( baseUrl + "/" , _ . trimStart ( endpoint , "/" ) ) ; const headers = Object . assign ( { } , options . headers , schema . headers ) ; const query = Object . assign ( { } , options . query , schema . query ) ; const body = Object . assign ( { } , options . body , schema . body ) ; let req = request [ getMethodFuncName ( method ) ] ( apiPath ) ; // NOTE/deprecate: params if ( schema . params ) { deprecate ( "'params' property/extension in schema is deprecated. Use 'headers', 'query' or 'body' instead." ) ; req = req [ getParamFuncName ( method ) ] ( schema . params ) ; } if ( Object . keys ( headers ) . length ) { expandVars ( headers , options ) ; for ( let key in headers ) { req = req . set ( key , headers [ key ] ) ; } } if ( Object . keys ( query ) . length ) { expandVars ( query , options ) ; req = req . query ( query ) ; } if ( Object . keys ( body ) . length ) { expandVars ( body , options ) ; req = req . send ( body ) ; } return req . end ( function ( error , response ) { // catch network errors, etc. if ( ! response ) { should ( error ) . not . be . ok ( ) ; } should ( response ) . be . ok ( ) ; should ( response . body ) . be . ok ( ) ; return validateResponse ( schema , response , options , done ) ; } ) ; }
Make a HTTP request against the remote server and validate the
response.

@private
@param  {String} baseUrl - base url e.g. "http://localhost:9090/"
@param  {String} method - http method to use for request e.g. "get"
@param  {Object} schema - schema used to validate response
@param  {Object} options - test configurations
@param  {Function} done - function called once request is completed
Make a HTTP request against the remote server and validate the response .