From ff024759450512fc0feddeeb0b1dea1a8da3b4e7 Mon Sep 17 00:00:00 2001 From: thelullabyy <182625428+thelullabyy@users.noreply.github.com> Date: Mon, 7 Sep 2026 00:33:52 +0800 Subject: [PATCH] feat: refactor canFlagReportAction --- src/libs/ReportUtils.ts | 15 +- src/pages/DynamicFlagCommentPage.tsx | 6 +- .../report/ContextMenu/ContextMenuActions.tsx | 4 +- tests/unit/ReportUtilsTest.ts | 393 ++++++++++++++++-- 4 files changed, 384 insertions(+), 34 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 6efa65d8eff7..8080f4c0b5be 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -10541,9 +10541,8 @@ function chatIncludesChronosWithID(reportOrID?: string | Report): boolean { * - It's a welcome message whisper * - It's an ADD_COMMENT that is not an attachment */ -// TODO: currentUserAccountID will be required eventually so this becomes a pure function. Subscribe the data via useOnyx and pass it from the component. Refactor issue: https://github.com/Expensify/App/issues/66412 -function canFlagReportAction(reportAction: OnyxInputOrEntry, reportID: string | undefined, currentUserAccountID?: number): boolean { - const isCurrentUserAction = reportAction?.actorAccountID === (currentUserAccountID ?? deprecatedCurrentUserAccountID); +function canFlagReportAction(reportAction: OnyxInputOrEntry, reportID: string | undefined, currentUserAccountID: number | undefined): boolean { + const isCurrentUserAction = reportAction?.actorAccountID === currentUserAccountID; if (isWhisperAction(reportAction)) { // Allow flagging whispers that are sent by other users if (!isCurrentUserAction && reportAction?.actorAccountID !== CONST.ACCOUNT_ID.CONCIERGE) { @@ -10576,9 +10575,15 @@ function canFlagReportAction(reportAction: OnyxInputOrEntry, repor /** * Whether flag comment page should show */ -function shouldShowFlagComment(reportAction: OnyxInputOrEntry, report: OnyxInputOrEntry, conciergeReportID: string | undefined, isReportArchived = false): boolean { +function shouldShowFlagComment( + reportAction: OnyxInputOrEntry, + report: OnyxInputOrEntry, + conciergeReportID: string | undefined, + isReportArchived: boolean, + currentUserAccountID: number | undefined, +): boolean { return ( - canFlagReportAction(reportAction, report?.reportID) && + canFlagReportAction(reportAction, report?.reportID, currentUserAccountID) && !isArchivedNonExpenseReport(report, isReportArchived) && !chatIncludesChronos(report) && !isConciergeChatReport(report, conciergeReportID) && diff --git a/src/pages/DynamicFlagCommentPage.tsx b/src/pages/DynamicFlagCommentPage.tsx index bd422f0cee91..b2175bfd53c3 100644 --- a/src/pages/DynamicFlagCommentPage.tsx +++ b/src/pages/DynamicFlagCommentPage.tsx @@ -6,6 +6,7 @@ import ScrollView from '@components/ScrollView'; import Text from '@components/Text'; import {useWideRHPState} from '@components/WideRHPContextProvider'; +import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useDynamicBackPath from '@hooks/useDynamicBackPath'; import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; @@ -52,6 +53,7 @@ type SeverityItemList = SeverityItem[]; function DynamicFlagCommentPage({parentReportAction, report, parentReport, reportAction}: DynamicFlagCommentPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); + const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails(); const backPath = useDynamicBackPath(DYNAMIC_ROUTES.FLAG_COMMENT.path); const isReportArchived = useReportIsArchived(report?.reportID); let reportID: string | undefined = report?.reportID; @@ -119,7 +121,7 @@ function DynamicFlagCommentPage({parentReportAction, report, parentReport, repor ]; const flagComment = (severity: Severity) => { - if (reportAction && canFlagReportAction(reportAction, reportID)) { + if (reportAction && canFlagReportAction(reportAction, reportID, currentUserAccountID)) { flagCommentUtil(reportAction, severity, originalReport, isOriginalReportArchived); } @@ -149,7 +151,7 @@ function DynamicFlagCommentPage({parentReportAction, report, parentReport, repor testID="DynamicFlagCommentPage" > {({safeAreaPaddingBottomStyle}) => ( - + Navigation.goBack(backPath)} diff --git a/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx b/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx index 89d3c37ef9f5..bd129cb83695 100644 --- a/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx @@ -1538,9 +1538,9 @@ const ContextMenuActions: ContextMenuAction[] = [ isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.flagAsOffensive', icon: 'Flag', - shouldShow: ({type, reportAction, isArchivedRoom, isChronosReport, reportID}) => + shouldShow: ({type, reportAction, isArchivedRoom, isChronosReport, reportID, currentUserAccountID}) => type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION && - canFlagReportAction(reportAction, reportID) && + canFlagReportAction(reportAction, reportID, currentUserAccountID) && !isArchivedRoom && !isChronosReport && reportAction?.actorAccountID !== CONST.ACCOUNT_ID.CONCIERGE, diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index b14f765c699e..8ca2cd97876e 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -13360,7 +13360,7 @@ describe('ReportUtils', () => { }; // The reportID doesn't matter because there is an early return for whisper actions and the report is not looked at - expect(canFlagReportAction(whisperReportActionFromConcierge, '123456')).toBe(false); + expect(canFlagReportAction(whisperReportActionFromConcierge, '123456', currentUserAccountID)).toBe(false); }); it('cannot be flagged if it is from the current user', () => { @@ -13370,11 +13370,11 @@ describe('ReportUtils', () => { }; // The reportID doesn't matter because there is an early return for whisper actions and the report is not looked at - expect(canFlagReportAction(whisperReportActionFromCurrentUser, '123456')).toBe(false); + expect(canFlagReportAction(whisperReportActionFromCurrentUser, '123456', currentUserAccountID)).toBe(false); }); it('can be flagged if it is not from concierge or the current user', () => { - expect(canFlagReportAction(whisperReportAction, '123456')).toBe(true); + expect(canFlagReportAction(whisperReportAction, '123456', currentUserAccountID)).toBe(true); }); it('cannot be flagged if it is from the explicitly passed currentUserAccountID', () => { @@ -13386,6 +13386,47 @@ describe('ReportUtils', () => { // The reportID doesn't matter because there is an early return for whisper actions and the report is not looked at expect(canFlagReportAction(whisperReportActionFromAccount, '123456', 909090)).toBe(false); }); + + it('can be flagged even when it is deleted, because a whisper never reaches the deleted check', () => { + const deletedWhisperFromSomeoneElse = createMock({ + ...whisperReportAction, + actorAccountID: 60201, + message: [ + { + whisperedTo: [currentUserAccountID], + html: '', + deleted: getRandomDate(), + }, + ], + }); + + expect(canFlagReportAction(deletedWhisperFromSomeoneElse, '123456', currentUserAccountID)).toBe(true); + }); + + it('can be flagged even when the action is not a comment, because a whisper never reaches the action name check', () => { + const iouWhisperFromSomeoneElse = createMock({ + ...whisperReportAction, + actionName: CONST.REPORT.ACTIONS.TYPE.IOU, + actorAccountID: 60202, + message: [ + { + whisperedTo: [currentUserAccountID], + }, + ], + }); + + expect(canFlagReportAction(iouWhisperFromSomeoneElse, '123456', currentUserAccountID)).toBe(true); + }); + + it('cannot be flagged if it is from concierge, whichever account the check runs for', () => { + const whisperReportActionFromConcierge = { + ...whisperReportAction, + actorAccountID: CONST.ACCOUNT_ID.CONCIERGE, + }; + + expect(canFlagReportAction(whisperReportActionFromConcierge, '123456', 60203)).toBe(false); + expect(canFlagReportAction(whisperReportActionFromConcierge, '123456', undefined)).toBe(false); + }); }); describe('a non-whisper action', () => { @@ -13413,7 +13454,7 @@ describe('ReportUtils', () => { ...nonWhisperReportAction, actorAccountID: currentUserAccountID, }; - expect(canFlagReportAction(nonWhisperReportActionFromCurrentUser, report.reportID)).toBe(false); + expect(canFlagReportAction(nonWhisperReportActionFromCurrentUser, report.reportID, currentUserAccountID)).toBe(false); }); it('cannot be flagged if the action name is something other than ADD_COMMENT', () => { @@ -13421,7 +13462,7 @@ describe('ReportUtils', () => { ...nonWhisperReportAction, actionName: CONST.REPORT.ACTIONS.TYPE.APPROVED, }; - expect(canFlagReportAction(nonWhisperReportActionWithDifferentActionName, report.reportID)).toBe(false); + expect(canFlagReportAction(nonWhisperReportActionWithDifferentActionName, report.reportID, currentUserAccountID)).toBe(false); }); it('cannot be flagged if the action is deleted', () => { @@ -13435,7 +13476,7 @@ describe('ReportUtils', () => { }, ], }); - expect(canFlagReportAction(deletedReportAction, report.reportID)).toBe(false); + expect(canFlagReportAction(deletedReportAction, report.reportID, currentUserAccountID)).toBe(false); }); it('cannot be flagged if the action is a created task report', () => { @@ -13446,27 +13487,279 @@ describe('ReportUtils', () => { taskReportID: '123456', }, }); - expect(canFlagReportAction(createdTaskReportAction, report.reportID)).toBe(false); + expect(canFlagReportAction(createdTaskReportAction, report.reportID, currentUserAccountID)).toBe(false); }); it('cannot be flagged if the report does not exist', () => { // cspell:disable-next-line - expect(canFlagReportAction(nonWhisperReportAction, 'starwarsisthebest')).toBe(false); + expect(canFlagReportAction(nonWhisperReportAction, 'starwarsisthebest', currentUserAccountID)).toBe(false); }); - it('cannot be flagged if the report is not allowed to be commented on', () => { + it('cannot be flagged if the report is not allowed to be commented on', async () => { // eslint-disable-next-line rulesdir/no-negated-variables const reportThatCannotBeCommentedOn = createMock({ ...createRandomReport(2, undefined), - // If the permissions does not contain WRITE, then it cannot be commented on - permissions: [], + // If the permissions do not contain WRITE or COMMENT, then it cannot be commented on + permissions: [CONST.REPORT.PERMISSIONS.READ], + }); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${reportThatCannotBeCommentedOn.reportID}`, reportThatCannotBeCommentedOn); + + expect(canFlagReportAction(nonWhisperReportAction, reportThatCannotBeCommentedOn.reportID, currentUserAccountID)).toBe(false); + + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${reportThatCannotBeCommentedOn.reportID}`, null); + }); + + it('can be flagged when the report only exists as a draft', async () => { + const draftReport = createRandomReport(60204, undefined); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${draftReport.reportID}`, draftReport); + + expect(canFlagReportAction(nonWhisperReportAction, draftReport.reportID, currentUserAccountID)).toBe(true); + + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${draftReport.reportID}`, null); + }); + + it('can be flagged in a read-only report when the user is an auditor', async () => { + const auditedReport = createMock({ + ...createRandomReport(60205, undefined), + + // The auditor permission opts the report out of the write check + permissions: [CONST.REPORT.PERMISSIONS.READ, CONST.REPORT.PERMISSIONS.AUDITOR], + }); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${auditedReport.reportID}`, auditedReport); + + expect(canFlagReportAction(nonWhisperReportAction, auditedReport.reportID, currentUserAccountID)).toBe(true); + + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${auditedReport.reportID}`, null); + }); + + it('is evaluated against the report the ID points at when the action opened a different thread', () => { + const actionWithAnUnrelatedThread = createMock({ + ...nonWhisperReportAction, + actorAccountID: 60206, + + // The child report is not the report being evaluated, so the parent lookup must not kick in + childReportID: '60207', }); - expect(canFlagReportAction(nonWhisperReportAction, reportThatCannotBeCommentedOn.reportID)).toBe(false); + + expect(canFlagReportAction(actionWithAnUnrelatedThread, report.reportID, currentUserAccountID)).toBe(true); + }); + it('can be flagged when the comment is an attachment', () => { + const attachmentComment = createMock({ + ...nonWhisperReportAction, + actorAccountID: 60208, + isAttachmentOnly: true, + }); + + // Attachments are flagged like any other comment, the check does not look at isAttachmentOnly + expect(canFlagReportAction(attachmentComment, report.reportID, currentUserAccountID)).toBe(true); + }); + + it('can be flagged when the action was whispered to nobody', () => { + const commentWhisperedToNobody = createMock({ + ...nonWhisperReportAction, + actorAccountID: 60209, + message: [ + { + whisperedTo: [], + }, + ], + }); + + // An empty whisper list is not a whisper, so the normal comment rules apply + expect(canFlagReportAction(commentWhisperedToNobody, report.reportID, currentUserAccountID)).toBe(true); }); it('can be flagged', () => { - expect(canFlagReportAction(nonWhisperReportAction, report.reportID)).toBe(true); + expect(canFlagReportAction(nonWhisperReportAction, report.reportID, currentUserAccountID)).toBe(true); + }); + }); + + describe('the account the check runs for', () => { + const chatReport = createRandomReport(60101, undefined); + const otherAccountID = 60102; + + const buildComment = (actorAccountID: number | undefined) => + createMock({ + ...createRandomReportAction(2), + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + actorAccountID, + message: [ + { + whisperedTo: undefined, + }, + ], + }); + + const buildWhisper = (actorAccountID: number | undefined) => + createMock({ + ...createRandomReportAction(3), + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + actorAccountID, + message: [ + { + whisperedTo: [otherAccountID], + }, + ], + }); + + beforeAll(async () => { + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, chatReport); + }); + + afterAll(async () => { + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, null); + }); + + it('is taken from the parameter and not from the Onyx session', () => { + // Given a comment from the signed-in user and a comment from another account + const commentFromSessionUser = buildComment(currentUserAccountID); + const commentFromOtherUser = buildComment(otherAccountID); + + // When the check runs for that other account, the signed-in user's comment is somebody else's comment + expect(canFlagReportAction(commentFromSessionUser, chatReport.reportID, otherAccountID)).toBe(true); + + // And the other account cannot flag its own comment, even though the session belongs to somebody else + expect(canFlagReportAction(commentFromOtherUser, chatReport.reportID, otherAccountID)).toBe(false); + }); + + it('is taken from the parameter for whispers as well', () => { + // The reportID doesn't matter because there is an early return for whisper actions and the report is not looked at + expect(canFlagReportAction(buildWhisper(currentUserAccountID), chatReport.reportID, otherAccountID)).toBe(true); + expect(canFlagReportAction(buildWhisper(otherAccountID), chatReport.reportID, otherAccountID)).toBe(false); + }); + + it('lets an account that is not signed in yet flag somebody else’s comment', () => { + expect(canFlagReportAction(buildComment(otherAccountID), chatReport.reportID, undefined)).toBe(true); + }); + + it('cannot flag an action without an actor when no account is passed', () => { + // An action with no actor cannot be told apart from the passed account when that is undefined too, + // so it counts as the current user's own action + expect(canFlagReportAction(buildComment(undefined), chatReport.reportID, undefined)).toBe(false); + }); + }); + + describe('a thread parent action', () => { + const parentChatReport = createRandomReport(60103, undefined); + const threadReport = { + ...createRandomReport(60104, undefined), + parentReportID: parentChatReport.reportID, + }; + const threadParentAction = createMock({ + ...createRandomReportAction(4), + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + actorAccountID: 60105, + childReportID: threadReport.reportID, + message: [ + { + whisperedTo: undefined, + }, + ], + }); + + beforeEach(async () => { + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${parentChatReport.reportID}`, parentChatReport); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${threadReport.reportID}`, threadReport); + }); + + afterAll(async () => { + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${parentChatReport.reportID}`, null); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${threadReport.reportID}`, null); + }); + + it('can be flagged when the parent report allows comments', () => { + expect(canFlagReportAction(threadParentAction, threadReport.reportID, currentUserAccountID)).toBe(true); + }); + + it('cannot be flagged when the thread has no parent report', async () => { + // Given a thread that lost its parent report + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${threadReport.reportID}`, {parentReportID: null}); + + // Then there is no report left to evaluate the action against + expect(canFlagReportAction(threadParentAction, threadReport.reportID, currentUserAccountID)).toBe(false); + }); + + it('cannot be flagged when the parent report does not allow comments', async () => { + // Given a parent report that the user may only read + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${parentChatReport.reportID}`, {permissions: [CONST.REPORT.PERMISSIONS.READ]}); + + // Then the thread parent action cannot be flagged, even though the thread itself is unrestricted + expect(canFlagReportAction(threadParentAction, threadReport.reportID, currentUserAccountID)).toBe(false); + }); + }); + + describe('a room that only admins can write in', () => { + const policyID = '60106'; + const adminsOnlyRoom = { + ...createRandomReport(60107, CONST.REPORT.CHAT_TYPE.POLICY_ROOM), + policyID, + writeCapability: CONST.REPORT.WRITE_CAPABILITIES.ADMINS, + }; + const commentFromSomeoneElse = createMock({ + ...createRandomReportAction(5), + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + actorAccountID: 60108, + message: [ + { + whisperedTo: undefined, + }, + ], + }); + + beforeAll(async () => { + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${adminsOnlyRoom.reportID}`, adminsOnlyRoom); + }); + + afterAll(async () => { + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${adminsOnlyRoom.reportID}`, null); + await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, null); + }); + + it('cannot be flagged when the workspace is not in Onyx', async () => { + const roomOfAnUnknownWorkspace = { + ...createRandomReport(60108, CONST.REPORT.CHAT_TYPE.POLICY_ROOM), + policyID: '60109', + writeCapability: CONST.REPORT.WRITE_CAPABILITIES.ADMINS, + }; + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${roomOfAnUnknownWorkspace.reportID}`, roomOfAnUnknownWorkspace); + + // The role in the workspace decides, and there is no workspace to read it from + expect(canFlagReportAction(commentFromSomeoneElse, roomOfAnUnknownWorkspace.reportID, currentUserAccountID)).toBe(false); + + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${roomOfAnUnknownWorkspace.reportID}`, null); + }); + + it('cannot be flagged by a workspace member', async () => { + await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {...createRandomPolicy(Number(policyID)), id: policyID, role: CONST.POLICY.ROLE.USER}); + + expect(canFlagReportAction(commentFromSomeoneElse, adminsOnlyRoom.reportID, currentUserAccountID)).toBe(false); + }); + + it('can be flagged by a workspace admin', async () => { + await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {...createRandomPolicy(Number(policyID)), id: policyID, role: CONST.POLICY.ROLE.ADMIN}); + + expect(canFlagReportAction(commentFromSomeoneElse, adminsOnlyRoom.reportID, currentUserAccountID)).toBe(true); + }); + }); + + describe('missing input', () => { + it('cannot flag a missing report action', () => { + expect(canFlagReportAction(undefined, '60109', currentUserAccountID)).toBe(false); + }); + + it('cannot flag an action without a report', () => { + const comment = createMock({ + ...createRandomReportAction(6), + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + actorAccountID: 60110, + message: [ + { + whisperedTo: undefined, + }, + ], + }); + expect(canFlagReportAction(comment, undefined, currentUserAccountID)).toBe(false); }); }); }); @@ -13535,19 +13828,69 @@ describe('ReportUtils', () => { }); it('should return true for an archived expense report with an action that can be flagged', () => { - expect(shouldShowFlagComment(reportActionThatCanBeFlagged, expenseReport, undefined, true)).toBe(true); + expect(shouldShowFlagComment(reportActionThatCanBeFlagged, expenseReport, undefined, true, currentUserAccountID)).toBe(true); }); it('should return true for a non-archived expense report with an action that can be flagged', () => { - expect(shouldShowFlagComment(reportActionThatCanBeFlagged, expenseReport, undefined, false)).toBe(true); + expect(shouldShowFlagComment(reportActionThatCanBeFlagged, expenseReport, undefined, false, currentUserAccountID)).toBe(true); }); it('should return false for an archived expense report with an action that cannot be flagged', () => { - expect(shouldShowFlagComment(reportActionThatCannotBeFlagged, expenseReport, undefined, true)).toBe(false); + expect(shouldShowFlagComment(reportActionThatCannotBeFlagged, expenseReport, undefined, true, currentUserAccountID)).toBe(false); }); it('should return false for a non-archived expense report with an action that cannot be flagged', () => { - expect(shouldShowFlagComment(reportActionThatCannotBeFlagged, expenseReport, undefined, false)).toBe(false); + expect(shouldShowFlagComment(reportActionThatCannotBeFlagged, expenseReport, undefined, false, currentUserAccountID)).toBe(false); + }); + + it('should hand the passed account down to canFlagReportAction', () => { + // The action was written by account 123456, so the flag option is offered to everybody but that account + expect(shouldShowFlagComment(reportActionThatCanBeFlagged, expenseReport, undefined, false, 123456)).toBe(false); + }); + + it('should hand an undefined account down to canFlagReportAction', () => { + // An account that has not loaded yet is nobody, so it is not the author of the action either + expect(shouldShowFlagComment(reportActionThatCanBeFlagged, expenseReport, undefined, false, undefined)).toBe(true); + }); + }); + + describe('archived reports', () => { + let chatReport: Report; + + // A plain comment rather than the whisper above, so the report itself decides the outcome + const plainComment = createMock({ + ...createRandomReportAction(7), + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + actorAccountID: 60302, + message: [ + { + whisperedTo: undefined, + }, + ], + }); + + beforeAll(async () => { + chatReport = { + ...createRandomReport(60301, undefined), + type: CONST.REPORT.TYPE.CHAT, + }; + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, chatReport); + }); + + afterAll(async () => { + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, null); + }); + + it('should return false for an archived chat with an action that can be flagged', () => { + expect(shouldShowFlagComment(plainComment, chatReport, undefined, true, currentUserAccountID)).toBe(false); + }); + + it('should return true for the same chat while it is not archived', () => { + expect(shouldShowFlagComment(plainComment, chatReport, undefined, false, currentUserAccountID)).toBe(true); + }); + + it('should return false when there is no report to flag the action in', () => { + expect(shouldShowFlagComment(plainComment, undefined, undefined, false, currentUserAccountID)).toBe(false); }); }); @@ -13568,11 +13911,11 @@ describe('ReportUtils', () => { }); it('should return false for an archived chat report', () => { - expect(shouldShowFlagComment(validReportAction, chatReport, undefined, true)).toBe(false); + expect(shouldShowFlagComment(validReportAction, chatReport, undefined, true, currentUserAccountID)).toBe(false); }); it('should return false for a non-archived chat report', () => { - expect(shouldShowFlagComment(validReportAction, chatReport, undefined, false)).toBe(false); + expect(shouldShowFlagComment(validReportAction, chatReport, undefined, false, currentUserAccountID)).toBe(false); }); }); @@ -13595,11 +13938,11 @@ describe('ReportUtils', () => { }); it('should return false for an archived chat report', () => { - expect(shouldShowFlagComment(validReportAction, chatReport, chatReport.reportID, true)).toBe(false); + expect(shouldShowFlagComment(validReportAction, chatReport, chatReport.reportID, true, currentUserAccountID)).toBe(false); }); it('should return false for a non-archived chat report', () => { - expect(shouldShowFlagComment(validReportAction, chatReport, chatReport.reportID, false)).toBe(false); + expect(shouldShowFlagComment(validReportAction, chatReport, chatReport.reportID, false, currentUserAccountID)).toBe(false); }); }); @@ -13624,11 +13967,11 @@ describe('ReportUtils', () => { }); it('should return false for an archived chat report', () => { - expect(shouldShowFlagComment(actionFromConcierge, chatReport, undefined, true)).toBe(false); + expect(shouldShowFlagComment(actionFromConcierge, chatReport, undefined, true, currentUserAccountID)).toBe(false); }); it('should return false for a non-archived chat report', () => { - expect(shouldShowFlagComment(actionFromConcierge, chatReport, undefined, false)).toBe(false); + expect(shouldShowFlagComment(actionFromConcierge, chatReport, undefined, false, currentUserAccountID)).toBe(false); }); }); @@ -13649,11 +13992,11 @@ describe('ReportUtils', () => { }); it('should return true for a regular chat when conciergeReportID does not match', () => { - expect(shouldShowFlagComment(validReportAction, chatReport, conciergeReportID, false)).toBe(true); + expect(shouldShowFlagComment(validReportAction, chatReport, conciergeReportID, false, currentUserAccountID)).toBe(true); }); it('should return false for a chat when conciergeReportID matches the report', () => { - expect(shouldShowFlagComment(validReportAction, chatReport, chatReport.reportID, false)).toBe(false); + expect(shouldShowFlagComment(validReportAction, chatReport, chatReport.reportID, false, currentUserAccountID)).toBe(false); }); }); });