vendredi 17 mars 2017

Setting authenticated user while testing Meteor app

I have added user roles to my Meteor app and need to test permissions over certain server methods. These methods are written such as, for example :

Meteor.methods({
  'inventory.update.qty'(id, qty) {
    // SECURITY
    if (!Roles.userIsInRole(this.userId, ['manage-stock'],  'inventory-items')) {
      throw new Meteor.Error('inv.crud', 'Access denied');
    }

    const modifier = {
      $inc: { qty }
    };

    InventoryItems.update(id, modifier);
  },
});

But how can I set this this.userId while running tests?

Aucun commentaire:

Enregistrer un commentaire