Code coverage report for common/models/User-Identity.js

Statements: 16.67% (4 / 24)      Branches: 0% (0 / 19)      Functions: 25% (1 / 4)      Lines: 18.18% (4 / 22)      Ignored: none     

All files » common/models/ » User-Identity.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 37 38 39 401   1     1 1                                                                  
var debug = require('debug')('freecc:models:userIdent');
 
var defaultProfileImage =
  require('../utils/constantStrings.json').defaultProfileImage;
 
module.exports = function(UserIdent) {
 UserIdent.observe('before save', function(ctx, next) {
  var userIdent = ctx.currentInstance || ctx.instance;
  if (!userIdent) {
    debug('no user identity instance found');
    return next();
  }
  userIdent.user(function(err, user) {
    if (err) { return next(err); }
    if (!user) {
      debug('no user attached to identity!');
      return next();
    }
 
    var picture = userIdent.profile && userIdent.profile[0] ?
      userIdent.profile[0].value :
      null;
 
    // check if user has picture
    //  set user.picture from twitter
    if (picture && !user.picture || user.picture === defaultProfileImage) {
      debug('use has no pic');
      user.picture = userIdent.profile.photos[0].value;
      user.save(function(err) {
        if (err) { return next(err); }
        next();
      });
    } else {
      debug('exiting after user ident');
      next();
    }
  });
 });
};