diff --git a/packages/@webex/internal-plugin-conversation/src/conversation.js b/packages/@webex/internal-plugin-conversation/src/conversation.js index a3fa8f89c85..ebdc02019d9 100644 --- a/packages/@webex/internal-plugin-conversation/src/conversation.js +++ b/packages/@webex/internal-plugin-conversation/src/conversation.js @@ -340,33 +340,36 @@ const Conversation = WebexPlugin.extend({ * @param {String} recipientId, * @returns {Promise} */ - addReaction(conversation, displayName, activity, recipientId) { - return this.createReactionHmac(displayName, activity).then((hmac) => { - const addReactionPayload = { - actor: {objectType: 'person', id: this.webex.internal.device.userId}, - target: { - id: conversation.id, - objectType: 'conversation', - }, - verb: 'add', - objectType: 'activity', - parent: { - type: 'reaction', - id: activity.id, - }, - object: { - objectType: 'reaction2', - displayName, - hmac, - }, - }; + async addReaction(conversation, displayName, activity, recipientId) { + let hmac; + if (this.config.includeEncryptionTransforms) { + hmac = await this.createReactionHmac(displayName, activity); + } - if (recipientId) { - addReactionPayload.recipients = {items: [{id: recipientId, objectType: 'person'}]}; - } + const addReactionPayload = { + actor: {objectType: 'person', id: this.webex.internal.device.userId}, + target: { + id: conversation.id, + objectType: 'conversation', + }, + verb: 'add', + objectType: 'activity', + parent: { + type: 'reaction', + id: activity.id, + }, + object: { + objectType: 'reaction2', + displayName, + hmac, + }, + }; - return this.sendReaction(conversation, addReactionPayload); - }); + if (recipientId) { + addReactionPayload.recipients = {items: [{id: recipientId, objectType: 'person'}]}; + } + + return this.sendReaction(conversation, addReactionPayload); }, /** diff --git a/packages/@webex/internal-plugin-conversation/test/unit/spec/conversation.js b/packages/@webex/internal-plugin-conversation/test/unit/spec/conversation.js index ee967bc2453..05a6f117352 100644 --- a/packages/@webex/internal-plugin-conversation/test/unit/spec/conversation.js +++ b/packages/@webex/internal-plugin-conversation/test/unit/spec/conversation.js @@ -41,49 +41,27 @@ describe('plugin-conversation', () => { const {conversation} = webex.internal; const recipientId = 'example-recipient-id'; const expected = {items: [{id: recipientId, objectType: 'person'}]}; + conversation.config.includeEncryptionTransforms = true; conversation.sendReaction = sinon.stub().returns(Promise.resolve()); conversation.createReactionHmac = sinon.stub().returns(Promise.resolve('hmac')); return conversation.addReaction({}, 'example-display-name', {}, recipientId).then(() => { + assert.called(conversation.createReactionHmac); assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expected); }); }); - }); - - describe('deleteReaction()', () => { - it('should add recipients to the payload if provided', () => { - const {conversation} = webex.internal; - const recipientId = 'example-recipient-id'; - const expected = {items: [{id: recipientId, objectType: 'person'}]}; - conversation.sendReaction = sinon.stub().returns(Promise.resolve()); - - return conversation.deleteReaction({}, 'example-reaction-id', recipientId).then(() => { - assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expected); - }); - }); - }); - describe('prepare()', () => { - it('should ammend activity recipients to the returned object', () => { - const {conversation} = webex.internal; - const activity = {recipients: 'example-recipients'}; - - return conversation.prepare(activity).then((results) => { - assert.deepEqual(results.recipients, activity.recipients); - }); - }); - }); - - describe('addReaction()', () => { - it('should add recipients to the payload if provided', () => { + it('will not call createReactionHmac if config prohibits', () => { const {conversation} = webex.internal; const recipientId = 'example-recipient-id'; const expected = {items: [{id: recipientId, objectType: 'person'}]}; + conversation.config.includeEncryptionTransforms = false; conversation.sendReaction = sinon.stub().returns(Promise.resolve()); - conversation.createReactionHmac = sinon.stub().returns(Promise.resolve('hmac')); + conversation.createReactionHmac = sinon.stub(); return conversation.addReaction({}, 'example-display-name', {}, recipientId).then(() => { assert.deepEqual(conversation.sendReaction.args[0][1].recipients, expected); + assert.notCalled(conversation.createReactionHmac); }); }); });