From 4a072ba3951ce43fc93b920cf64421f6cfc46a77 Mon Sep 17 00:00:00 2001 From: Adam Grzybowski Date: Mon, 23 Feb 2026 15:36:11 +0100 Subject: [PATCH 1/2] Filter export todos to only include reports where user is the preferred exporter --- src/libs/actions/OnyxDerived/configs/todos.ts | 3 +- tests/unit/ReportPrimaryActionUtilsTest.ts | 100 +++++++++++++++++- 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/OnyxDerived/configs/todos.ts b/src/libs/actions/OnyxDerived/configs/todos.ts index c63cb7d40c70..dba81b38cff4 100644 --- a/src/libs/actions/OnyxDerived/configs/todos.ts +++ b/src/libs/actions/OnyxDerived/configs/todos.ts @@ -1,4 +1,5 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; +import {isPreferredExporter} from '@libs/PolicyUtils'; import {isApproveAction, isExportAction, isPrimaryPayAction, isSubmitAction} from '@libs/ReportPrimaryActionUtils'; import createOnyxDerivedValueConfig from '@userActions/OnyxDerived/createOnyxDerivedValueConfig'; import CONST from '@src/CONST'; @@ -67,7 +68,7 @@ const createTodosReportsAndTransactions = ({ if (isPrimaryPayAction(report, currentUserAccountID, login, bankAccountList, policy, reportNameValuePair)) { reportsToPay.push(report); } - if (isExportAction(report, login, policy, reportActions)) { + if (isExportAction(report, login, policy, reportActions) && policy && isPreferredExporter(policy, login)) { reportsToExport.push(report); } } diff --git a/tests/unit/ReportPrimaryActionUtilsTest.ts b/tests/unit/ReportPrimaryActionUtilsTest.ts index 3c3114d5a6fe..82b8b953f034 100644 --- a/tests/unit/ReportPrimaryActionUtilsTest.ts +++ b/tests/unit/ReportPrimaryActionUtilsTest.ts @@ -2,13 +2,14 @@ import {renderHook} from '@testing-library/react-native'; import Onyx from 'react-native-onyx'; import type {OnyxCollection} from 'react-native-onyx'; import useReportIsArchived from '@hooks/useReportIsArchived'; -import {getValidConnectedIntegration} from '@libs/PolicyUtils'; +import {getValidConnectedIntegration, isPreferredExporter} from '@libs/PolicyUtils'; // eslint-disable-next-line no-restricted-syntax import type * as PolicyUtils from '@libs/PolicyUtils'; import { getReportPrimaryAction, getTransactionThreadPrimaryAction, isApproveAction, + isExportAction, isMarkAsResolvedAction, isPrimaryMarkAsResolvedAction, isReviewDuplicatesAction, @@ -510,6 +511,47 @@ describe('getPrimaryAction', () => { ).toBe(CONST.REPORT.PRIMARY_ACTIONS.EXPORT_TO_ACCOUNTING); }); + it('should return EXPORT TO ACCOUNTING for admin who is not the preferred exporter', async () => { + const report = { + reportID: REPORT_ID, + type: CONST.REPORT.TYPE.EXPENSE, + ownerAccountID: CURRENT_USER_ACCOUNT_ID, + statusNum: CONST.REPORT.STATUS_NUM.CLOSED, + } as unknown as Report; + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); + const policy = { + role: CONST.POLICY.ROLE.ADMIN, + connections: { + intacct: { + config: { + export: { + exporter: 'someone.else@mail.com', + }, + }, + }, + }, + }; + const transaction = { + reportID: `${REPORT_ID}`, + } as unknown as Transaction; + + (getValidConnectedIntegration as jest.Mock).mockReturnValue('intacct'); + + expect( + getReportPrimaryAction({ + currentUserLogin: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, + report, + chatReport, + reportTransactions: [transaction], + violations: {}, + bankAccountList: {}, + policy: policy as Policy, + isChatReportArchived: false, + }), + ).toBe(CONST.REPORT.PRIMARY_ACTIONS.EXPORT_TO_ACCOUNTING); + }); + it('should not return EXPORT TO ACCOUNTING for invoice reports', async () => { const report = { reportID: REPORT_ID, @@ -1511,3 +1553,59 @@ describe('getTransactionThreadPrimaryAction', () => { }); }); }); + +describe('isExportAction and isPreferredExporter for todos filtering', () => { + it('isExportAction returns true for admin who is not the preferred exporter', () => { + const policy = { + role: CONST.POLICY.ROLE.ADMIN, + connections: { + [CONST.POLICY.CONNECTIONS.NAME.QBO]: { + config: { + autoSync: {enabled: false}, + export: {exporter: 'other.exporter@mail.com'}, + }, + }, + }, + } as unknown as Policy; + + const report = { + reportID: '1', + type: CONST.REPORT.TYPE.EXPENSE, + stateNum: CONST.REPORT.STATE_NUM.APPROVED, + statusNum: CONST.REPORT.STATUS_NUM.APPROVED, + isWaitingOnBankAccount: false, + } as Report; + + (getValidConnectedIntegration as jest.Mock).mockReturnValue(CONST.POLICY.CONNECTIONS.NAME.QBO); + + expect(isExportAction(report, CURRENT_USER_EMAIL, policy)).toBe(true); + }); + + it('isPreferredExporter returns false when user is not the configured exporter', () => { + const policy = { + connections: { + [CONST.POLICY.CONNECTIONS.NAME.QBO]: { + config: { + export: {exporter: 'other.exporter@mail.com'}, + }, + }, + }, + } as unknown as Policy; + + expect(isPreferredExporter(policy, CURRENT_USER_EMAIL)).toBe(false); + }); + + it('isPreferredExporter returns true when user is the configured exporter', () => { + const policy = { + connections: { + [CONST.POLICY.CONNECTIONS.NAME.QBO]: { + config: { + export: {exporter: CURRENT_USER_EMAIL}, + }, + }, + }, + } as unknown as Policy; + + expect(isPreferredExporter(policy, CURRENT_USER_EMAIL)).toBe(true); + }); +}); From 6a8953c8db098821847f4a632375110a2c53954c Mon Sep 17 00:00:00 2001 From: Adam Grzybowski Date: Fri, 27 Feb 2026 16:06:38 +0100 Subject: [PATCH 2/2] Fix tests --- tests/unit/OnyxDerivedTest.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/OnyxDerivedTest.tsx b/tests/unit/OnyxDerivedTest.tsx index d753e2095788..f340a224dd2e 100644 --- a/tests/unit/OnyxDerivedTest.tsx +++ b/tests/unit/OnyxDerivedTest.tsx @@ -756,6 +756,9 @@ describe('OnyxDerived', () => { jobID: 'job123', enabled: false, // Auto-sync disabled so manual export is available }, + export: { + exporter: CURRENT_USER_EMAIL, + }, }, }, },