From 2a86ca3c2c82e06ee751805b864a18c02d2479a4 Mon Sep 17 00:00:00 2001 From: tugbadogan Date: Thu, 13 May 2021 00:41:51 +0100 Subject: [PATCH] Exclude concierge from IOU flows --- src/CONST.js | 1 + src/libs/OptionsListUtils.js | 12 +++ src/libs/actions/Report.js | 4 +- src/pages/home/report/ReportActionCompose.js | 4 +- .../IOUParticipantsRequest.js | 2 + .../IOUParticipantsSplit.js | 3 + tests/unit/OptionsListUtilsTest.js | 81 +++++++++++++++++++ 7 files changed, 103 insertions(+), 4 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index 823eb1b6436b..5da1d598a865 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -113,6 +113,7 @@ const CONST = { EMAIL: { CHRONOS: 'chronos@expensify.com', + CONCIERGE: 'concierge@expensify.com', }, ENVIRONMENT: { diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 567ddb9992ae..4d9007dbf957 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -167,6 +167,7 @@ function isSearchStringMatch(searchValue, searchText) { function getOptions(reports, personalDetails, draftComments, activeReportID, { selectedOptions = [], maxRecentReportsToShow = 0, + excludeConcierge = false, includeMultipleParticipantReports = false, includePersonalDetails = false, includeRecentReports = false, @@ -227,6 +228,11 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, { // Always exclude already selected options and the currently logged in user const loginOptionsToExclude = [...selectedOptions, {login: currentUserLogin}]; + + if (excludeConcierge) { + loginOptionsToExclude.push({login: CONST.EMAIL.CONCIERGE}); + } + if (includeRecentReports) { for (let i = 0; i < allReportOptions.length; i++) { // Stop adding options to the recentReports array when we reach the maxRecentReportsToShow value @@ -348,16 +354,19 @@ function getSearchOptions( * @param {Object} reports * @param {Object} personalDetails * @param {String} searchValue + * @param {Boolean} excludeConcierge * @returns {Object} */ function getNewChatOptions( reports, personalDetails, searchValue = '', + excludeConcierge, ) { return getOptions(reports, personalDetails, {}, 0, { searchValue, includePersonalDetails: true, + excludeConcierge, }); } @@ -399,6 +408,7 @@ function getIOUConfirmationOptionsFromParticipants( * @param {Object} personalDetails * @param {String} searchValue * @param {Array} selectedOptions + * @param {Boolean} excludeConcierge * @returns {Object} */ function getNewGroupOptions( @@ -406,6 +416,7 @@ function getNewGroupOptions( personalDetails, searchValue = '', selectedOptions = [], + excludeConcierge, ) { return getOptions(reports, personalDetails, {}, 0, { searchValue, @@ -414,6 +425,7 @@ function getNewGroupOptions( includePersonalDetails: true, includeMultipleParticipantReports: false, maxRecentReportsToShow: 5, + excludeConcierge, }); } diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index c60f17ec52fe..cf1817775bae 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -537,7 +537,7 @@ function updateReportWithNewAction(reportID, reportAction) { } // If the comment came from Concierge let's not show a notification since we already show one for expensify.com - if (lodashGet(reportAction, 'actorEmail') === 'concierge@expensify.com') { + if (lodashGet(reportAction, 'actorEmail') === CONST.EMAIL.CONCIERGE) { return; } @@ -846,7 +846,7 @@ function fetchAllReports( return fetchChatReportsByIDs(reportIDs); } - return fetchOrCreateChatReport([currentUserEmail, 'concierge@expensify.com'], false); + return fetchOrCreateChatReport([currentUserEmail, CONST.EMAIL.CONCIERGE], false); }) .then((returnedReportIDs) => { Onyx.set(ONYXKEYS.INITIAL_REPORT_DATA_LOADED, true); diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index 498488d1849c..49d79c1f3cfa 100755 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -308,10 +308,10 @@ class ReportActionCompose extends React.Component { render() { // eslint-disable-next-line no-unused-vars const hasMultipleParticipants = lodashGet(this.props.report, 'participants.length') > 1; + const hasConciergeParticipant = _.contains(this.props.report.participants, CONST.EMAIL.CONCIERGE); // Prevents focusing and showing the keyboard while the drawer is covering the chat. const isComposeDisabled = this.props.isDrawerOpen && this.props.isSmallScreenWidth; - return ( { }, }; + const REPORTS_WITH_CONCIERGE = { + ...REPORTS, + + 9: { + lastVisitedTimestamp: 1610666739302, + lastMessageTimestamp: 1, + isPinned: false, + reportID: 9, + participants: ['concierge@expensify.com'], + reportName: 'Concierge', + unreadActionCount: 1, + }, + }; + + const PERSONAL_DETAILS_WITH_CONCIERGE = { + ...PERSONAL_DETAILS, + + 'concierge@expensify.com': { + displayName: 'Concierge', + login: 'concierge@expensify.com', + }, + }; + // Set the currently logged in user, report data, and personal details beforeAll(() => { Onyx.init({ @@ -210,6 +233,29 @@ describe('OptionsListUtils', () => { expect(results.personalDetails[0].text).toBe('Spider-Man'); expect(results.personalDetails[1].text).toBe('Invisible Woman'); expect(results.personalDetails[2].login).toBe('natasharomanoff@expensify.com'); + + // Test for Concierge's existence in chat options + results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE); + + // Concierge is included in the results by default and all the personalDetails should be returned + // minus the currently logged in user + expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 1); + expect(results.personalDetails).toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'concierge@expensify.com'}), + ]), + ); + + // Test by excluding Concierge from the results + results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, '', true); + + // All the personalDetails should be returned minus the currently logged in user and Concierge + expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 2); + expect(results.personalDetails).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'concierge@expensify.com'}), + ]), + ); }); it('getNewGroupOptions()', () => { @@ -311,6 +357,41 @@ describe('OptionsListUtils', () => { expect(results.personalDetails.length).toBe(0); expect(results.userToInvite).not.toBe(null); expect(results.userToInvite.login).toBe('+15005550006'); + + // Test Concierge's existence in new group options + results = OptionsListUtils.getNewGroupOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE); + + // Concierge is included in the results by default. We should expect all the personalDetails to show + // (minus the 5 that are already showing and the currently logged in user) + expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 6); + expect(results.recentReports).toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'concierge@expensify.com'}), + ]), + ); + + // Test by excluding Concierge from the results + results = OptionsListUtils.getNewGroupOptions( + REPORTS_WITH_CONCIERGE, + PERSONAL_DETAILS_WITH_CONCIERGE, + '', + [], + true, + ); + + // We should expect all the personalDetails to show (minus the 5 that are already showing, + // the currently logged in user and Concierge) + expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 7); + expect(results.personalDetails).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'concierge@expensify.com'}), + ]), + ); + expect(results.recentReports).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'concierge@expensify.com'}), + ]), + ); }); it('getSidebarOptions() with default priority mode', () => {