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: 2 additions & 1 deletion src/libs/actions/OnyxDerived/configs/todos.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/OnyxDerivedTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,9 @@ describe('OnyxDerived', () => {
jobID: 'job123',
enabled: false, // Auto-sync disabled so manual export is available
},
export: {
exporter: CURRENT_USER_EMAIL,
},
},
},
},
Expand Down
100 changes: 99 additions & 1 deletion tests/unit/ReportPrimaryActionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
});
});
Loading