Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/libs/actions/OnyxDerived/configs/todos.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
}
}
Expand Down
49 changes: 49 additions & 0 deletions tests/unit/OnyxDerivedTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading