diff --git a/src/libs/actions/OnyxDerived/configs/todos.ts b/src/libs/actions/OnyxDerived/configs/todos.ts index dba81b38cff4..9b8976c2b80f 100644 --- a/src/libs/actions/OnyxDerived/configs/todos.ts +++ b/src/libs/actions/OnyxDerived/configs/todos.ts @@ -1,5 +1,4 @@ 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'; @@ -68,7 +67,7 @@ const createTodosReportsAndTransactions = ({ if (isPrimaryPayAction(report, currentUserAccountID, login, bankAccountList, policy, reportNameValuePair)) { reportsToPay.push(report); } - if (isExportAction(report, login, policy, reportActions) && policy && isPreferredExporter(policy, login)) { + if (isExportAction(report, login, policy, reportActions) && policy?.exporter === login) { reportsToExport.push(report); } } diff --git a/tests/unit/OnyxDerivedTest.tsx b/tests/unit/OnyxDerivedTest.tsx index f340a224dd2e..d63481e83c09 100644 --- a/tests/unit/OnyxDerivedTest.tsx +++ b/tests/unit/OnyxDerivedTest.tsx @@ -741,6 +741,7 @@ describe('OnyxDerived', () => { const policyWithConnection = { ...createMockPolicy(POLICY_WITH_CONNECTION_ID, { role: CONST.POLICY.ROLE.ADMIN, + exporter: CURRENT_USER_EMAIL, }), connections: { // QuickBooks Online connection with auto-sync disabled @@ -921,6 +922,54 @@ describe('OnyxDerived', () => { }); }); + it('excludes export reports when user is connection-level exporter but not policy.exporter', async () => { + const EXPORT_POLICY_ID = 'policy_export_mismatch'; + const reportID = 'export_mismatch_report'; + + const report = createMockReport(reportID, { + policyID: EXPORT_POLICY_ID, + stateNum: CONST.REPORT.STATE_NUM.APPROVED, + statusNum: CONST.REPORT.STATUS_NUM.APPROVED, + ownerAccountID: OTHER_USER_ACCOUNT_ID, + isWaitingOnBankAccount: false, + }); + + const policy = { + ...createMockPolicy(EXPORT_POLICY_ID, { + role: CONST.POLICY.ROLE.ADMIN, + exporter: 'someone-else@mail.com', + }), + connections: { + [CONST.POLICY.CONNECTIONS.NAME.QBO]: { + lastSync: { + isConnected: true, + isSuccessful: true, + isAuthenticationError: false, + source: 'DIRECT', + }, + config: { + autoSync: { + jobID: 'job123', + enabled: false, + }, + export: { + exporter: CURRENT_USER_EMAIL, + }, + }, + }, + }, + } as Policy; + + await Onyx.set(ONYXKEYS.SESSION, {email: CURRENT_USER_EMAIL, accountID: CURRENT_USER_ACCOUNT_ID}); + await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${EXPORT_POLICY_ID}`, policy); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, report); + + await waitForBatchedUpdates(); + const todos = await OnyxUtils.get(ONYXKEYS.DERIVED.TODOS); + + expect(todos?.reportsToExport).toHaveLength(0); + }); + describe('uses primary login from personalDetailsList', () => { const SECONDARY_LOGIN = '+15555551234'; // Phone number as secondary login const PRIMARY_LOGIN = 'primary@example.com'; // Primary email