All files / src/security Role.js

100% Statements 18/18
84.62% Branches 11/13
100% Functions 4/4
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 671x       19x     17x                     17x 17x     119x   119x             1x                                 1x   2x 2x   2x 2x 2x     2x 2x     2x     1x  
var SecurityDocument = require('./SecurityDocument');
 
function Role(Security, id, content, meta) {
 
  SecurityDocument.call(this, Security, id, content, meta);
 
  // Define properties
  Object.defineProperties(this, {
    // private properties
    deleteActionName: {
      value: 'deleteRole'
    },
    updateActionName: {
      value: 'updateRole'
    }
  });
 
  // promisifying
  Eif (Security.kuzzle.bluebird) {
    return Security.kuzzle.bluebird.promisifyAll(this, {
      suffix: 'Promise',
      filter: function (name, func, target, passes) {
        var whitelist = ['save'];
 
        return passes && whitelist.indexOf(name) !== -1;
      }
    });
  }
 
}
 
Role.prototype = Object.create(SecurityDocument.prototype, {
  constructor: {
    value: Role
  }
});
 
/**
 * Saves this role into Kuzzle.
 *
 * If this is a new role, this function will create it in Kuzzle.
 * Otherwise, this method will replace the latest version of this role in Kuzzle by the current content
 * of this object.
 *
 * @param {object} [options] - Optional parameters
 * @param {responseCallback} [cb] - Handles the query response
 * @returns {Role} this object
 */
Role.prototype.save = function (options, cb) {
  var
    data = this.serialize(),
    self = this;
 
  Eif (options && cb === undefined && typeof options === 'function') {
    cb = options;
    options = null;
  }
 
  self.kuzzle.query(this.Security.buildQueryArgs('createOrReplaceRole'), data, options, cb && function (error) {
    cb(error, error ? undefined : self);
  });
 
  return this;
};
 
module.exports = Role;