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/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@

let allTransactions: OnyxCollection<Transaction> = {};

Onyx.connect({

Check warning on line 118 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -127,7 +127,7 @@
});

let allReports: OnyxCollection<Report> = {};
Onyx.connect({

Check warning on line 130 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -136,7 +136,7 @@
});

let allTransactionViolations: OnyxCollection<TransactionViolations> = {};
Onyx.connect({

Check warning on line 139 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => (allTransactionViolations = value),
Expand All @@ -144,7 +144,7 @@

let currentUserEmail = '';
let currentUserAccountID = -1;
Onyx.connect({

Check warning on line 147 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (val) => {
currentUserEmail = val?.email ?? '';
Expand Down Expand Up @@ -1104,13 +1104,14 @@
const isSubmitter = isCurrentUserSubmitter(iouReport);
const isPolicyMember = isPolicyMemberPolicyUtils(policy, currentUserEmail);
const isReportOpen = isOpenExpenseReport(iouReport);
const isOpenOrProcessingReport = isReportOpen || isProcessingReport(iouReport);

if (violationName === CONST.VIOLATIONS.AUTO_REPORTED_REJECTED_EXPENSE) {
return isSubmitter || isPolicyAdmin(policy);
}

if (violationName === CONST.VIOLATIONS.OVER_AUTO_APPROVAL_LIMIT) {
return isPolicyAdmin(policy) && !isSubmitter;
return isPolicyAdmin(policy) && !isSubmitter && isOpenOrProcessingReport;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from #78197 checklist: as approver the violation shouldn't show on draft report so condition just update to check processing report

}

if (violationName === CONST.VIOLATIONS.RTER) {
Expand Down
23 changes: 22 additions & 1 deletion tests/unit/TransactionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import type {CustomUnit, Rate} from '@src/types/onyx/Policy';
import type {ReportCollectionDataSet} from '@src/types/onyx/Report';
import type {TransactionCustomUnit} from '@src/types/onyx/Transaction';
import * as TransactionUtils from '../../src/libs/TransactionUtils';
import type {Policy, Transaction} from '../../src/types/onyx';
import type {Policy, Report, Transaction} from '../../src/types/onyx';
import createRandomPolicy, {createCategoryTaxExpenseRules} from '../utils/collections/policies';
import {createRandomReport} from '../utils/collections/reports';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

function generateTransaction(values: Partial<Transaction> = {}): Transaction {
Expand Down Expand Up @@ -726,4 +727,24 @@ describe('TransactionUtils', () => {
expect(result).toBe(true);
});
});

describe('shouldShowViolation', () => {
it('should return false for auto approval limit violation when report is not open/processing report', () => {
const iouReport: Report = {
...createRandomReport(0),
type: CONST.REPORT.TYPE.EXPENSE,
chatType: undefined,
statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
ownerAccountID: 2,
};

const policy: Policy = {
...createRandomPolicy(0, CONST.POLICY.TYPE.TEAM),
role: CONST.POLICY.ROLE.ADMIN,
};

expect(TransactionUtils.shouldShowViolation(iouReport, policy, CONST.VIOLATIONS.OVER_AUTO_APPROVAL_LIMIT)).toBe(false);
});
});
});
Loading