All files / server/test normalize.js

90.91% Statements 10/11
84.62% Branches 11/13
100% Functions 1/1
100% Lines 10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27    28x     138x     138x 138x 3x       138x 138x       138x 6x       138x    
 
// Make an object with the options as expected by request()
module.exports = (method, url, port, options) => {
 
  // Make sure it's a simple object
  Iif (typeof options === 'string') options = { url: options };
 
  // Assign independent parts
  options = Object.assign({}, { headers: {} }, options, { url, method });
  if (options && options.body && typeof options.body === 'string') {
    options.headers['Content-Type'] = 'text/plain';
  }
 
  // Make sure it has a right URL or localhost otherwise
  Eif (!/^https?:\/\//.test(options.url)) {
    options.url = `http://localhost:${port}${options.url}`;
  }
 
  // Set it to send a JSON when appropriate
  if (options.body && typeof options.body === 'object') {
    options.json = true;
  }
 
  // Finally return the fully formed object
  return options;
};