Code coverage report for lib/profile.js

Statements: 100% (13 / 13)      Branches: 100% (4 / 4)      Functions: 100% (1 / 1)      Lines: 100% (13 / 13)      Ignored: none     

All files » lib/ » profile.js
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 28 29 30 31 32 33 34 35 36      1                 1 5 3     4 4   4 4   4 3 3           4   4    
'use strict';
 
// Polyfills
require('string.prototype.includes');
 
/**
 * Parse profile.
 *
 * @param {Object|String} json
 * @return {Object}
 * @api private
 */
exports.parse = function(json) {
  if (typeof json === 'string') {
    json = JSON.parse(json);
  }
 
  var profile = {};
  profile.id = json.ID;
 
  profile.username = json.user_login;
  profile.displayName = json.display_name;
 
  if (json.display_name.includes(' ')) {
    var nameParts = json.display_name.split(' ');
    profile.name = {
      familyName: nameParts.pop(),
      givenName: nameParts.join(' ')
    };
  }
 
  profile.emails = [{value: json.user_email}];
 
  return profile;
};