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
2 changes: 1 addition & 1 deletion src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function MoneyRequestHeader({reportID: reportIDProp, onBackButtonPress}: MoneyRe
}`,
{},
);
const transactionViolations = useTransactionViolations(transaction?.transactionID);
const transactionViolations = useTransactionViolations(transaction?.transactionID, false);
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST);

const styles = useThemeStyles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function MoneyRequestReceiptView({
const [transactionReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transaction?.reportID}`);
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${moneyRequestReport?.policyID}`);
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST);
const transactionViolations = useTransactionViolations(transaction?.transactionID);
const transactionViolations = useTransactionViolations(transaction?.transactionID, false);
const [rawTransactionViolations] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${getNonEmptyStringOnyxID(transaction?.transactionID)}`);
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${moneyRequestReport?.policyID}`);

Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ function MoneyRequestView({
const [selfDMReportID] = useOnyx(ONYXKEYS.SELF_DM_REPORT_ID);

const [transactionBackup] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_BACKUP}${getNonEmptyStringOnyxID(linkedTransactionID)}`);
const transactionViolations = useTransactionViolations(transaction?.transactionID, true, distanceOriginalPolicy ?? policy);
const transactionViolations = useTransactionViolations(transaction?.transactionID, false, distanceOriginalPolicy ?? policy);
const allTransactionViolations = useAllTransactionViolations(transaction?.transactionID);
const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
Expand Down
4 changes: 2 additions & 2 deletions src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2188,7 +2188,7 @@ function shouldShowBrokenConnectionViolation(report: OnyxEntry<Report>, policy:
}

/**
* Check if user should see broken connection violation warning based on selected transactions.
* Check if user should see broken connection violation warning based on selected transactions. RTER violations stop being actionable once the report is paid, so they are hidden on settled reports.
*/
function shouldShowBrokenConnectionViolationForMultipleTransactions(
transactions: Transaction[],
Expand All @@ -2215,7 +2215,7 @@ function shouldShowBrokenConnectionViolationForMultipleTransactions(
return false;
}

return shouldShowViolation(report, policy, violation.name, currentUserEmail, currentUserAccountID, true, transaction);
return shouldShowViolation(report, policy, violation.name, currentUserEmail, currentUserAccountID, false, transaction);
});
});

Expand Down
118 changes: 118 additions & 0 deletions tests/unit/TransactionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const FAKE_OPEN_REPORT_ID = 'FAKE_OPEN_REPORT_ID';
const FAKE_OPEN_REPORT_SECOND_USER_ID = 'FAKE_OPEN_REPORT_SECOND_USER_ID';
const FAKE_PROCESSING_REPORT_ID = 'FAKE_PROCESSING_REPORT_ID';
const FAKE_APPROVED_REPORT_ID = 'FAKE_APPROVED_REPORT_ID';
const FAKE_SETTLED_REPORT_ID = 'FAKE_SETTLED_REPORT_ID';
const FAKE_CHAT_REPORT_ID = '12345';
const openReport = {
reportID: FAKE_OPEN_REPORT_ID,
Expand All @@ -74,6 +75,13 @@ const approvedReport = {
type: CONST.REPORT.TYPE.EXPENSE,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
};
const settledReport = {
reportID: FAKE_SETTLED_REPORT_ID,
ownerAccountID: CURRENT_USER_ID,
type: CONST.REPORT.TYPE.EXPENSE,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED,
};
const secondUserOpenReport = {
reportID: FAKE_OPEN_REPORT_SECOND_USER_ID,
ownerAccountID: SECOND_USER_ID,
Expand All @@ -92,6 +100,7 @@ const reportCollectionDataSet = {
[`${ONYXKEYS.COLLECTION.REPORT}${FAKE_OPEN_REPORT_ID}`]: openReport,
[`${ONYXKEYS.COLLECTION.REPORT}${FAKE_PROCESSING_REPORT_ID}`]: processingReport,
[`${ONYXKEYS.COLLECTION.REPORT}${FAKE_APPROVED_REPORT_ID}`]: approvedReport,
[`${ONYXKEYS.COLLECTION.REPORT}${FAKE_SETTLED_REPORT_ID}`]: settledReport,
[`${ONYXKEYS.COLLECTION.REPORT}${FAKE_OPEN_REPORT_SECOND_USER_ID}`]: secondUserOpenReport,
[`${ONYXKEYS.COLLECTION.REPORT}${FAKE_CHAT_REPORT_ID}`]: chatReport,
} as OnyxCollection<Report>;
Expand Down Expand Up @@ -2007,6 +2016,115 @@ describe('TransactionUtils', () => {

expect(showBrokenConnectionViolation).toBe(false);
});

it('should return false for the report status bar when the expense report has been paid', () => {
const policy = createMock<Policy>({role: CONST.POLICY.ROLE.USER});
const transaction = generateTransaction();
const transactionViolations = {
[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`]: [
{
type: CONST.VIOLATION_TYPES.VIOLATION,
name: CONST.VIOLATIONS.RTER,
data: {rterType: CONST.RTER_VIOLATION_TYPES.BROKEN_CARD_CONNECTION_REAUTH},
},
],
};
const showBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions(
[transaction],
settledReport,
CURRENT_USER_EMAIL,
policy,
transactionViolations,
CURRENT_USER_EMAIL,
CURRENT_USER_ID,
);

expect(showBrokenConnectionViolation).toBe(false);
});

it('should return true for the report status bar when the same expense report is still processing', () => {
const policy = createMock<Policy>({role: CONST.POLICY.ROLE.USER});
const transaction = generateTransaction();
const transactionViolations = {
[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`]: [
{
type: CONST.VIOLATION_TYPES.VIOLATION,
name: CONST.VIOLATIONS.RTER,
data: {rterType: CONST.RTER_VIOLATION_TYPES.BROKEN_CARD_CONNECTION_REAUTH},
},
],
};
const showBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions(
[transaction],
processingReport,
CURRENT_USER_EMAIL,
policy,
transactionViolations,
CURRENT_USER_EMAIL,
CURRENT_USER_ID,
);

expect(showBrokenConnectionViolation).toBe(true);
});
});

describe('getVisibleTransactionViolations', () => {
const brokenConnectionViolation: TransactionViolation = {
type: CONST.VIOLATION_TYPES.VIOLATION,
name: CONST.VIOLATIONS.RTER,
data: {rterType: CONST.RTER_VIOLATION_TYPES.BROKEN_CARD_CONNECTION_REAUTH},
};

it('should hide an RTER violation on a paid report when shouldShowRterForSettledReport is false', () => {
const policy = createMock<Policy>({role: CONST.POLICY.ROLE.USER});
const transaction = generateTransaction({reportID: FAKE_SETTLED_REPORT_ID});
const visibleViolations = TransactionUtils.getVisibleTransactionViolations(
transaction,
[brokenConnectionViolation],
CURRENT_USER_EMAIL,
CURRENT_USER_ID,
settledReport,
CURRENT_USER_EMAIL,
policy,
false,
);

expect(visibleViolations).toEqual([]);
});

it('should keep an RTER violation on a paid report when shouldShowRterForSettledReport is true', () => {
const policy = createMock<Policy>({role: CONST.POLICY.ROLE.USER});
const transaction = generateTransaction({reportID: FAKE_SETTLED_REPORT_ID});
const visibleViolations = TransactionUtils.getVisibleTransactionViolations(
transaction,
[brokenConnectionViolation],
CURRENT_USER_EMAIL,
CURRENT_USER_ID,
settledReport,
CURRENT_USER_EMAIL,
policy,
true,
);

expect(visibleViolations).toEqual([brokenConnectionViolation]);
});

it('should keep an RTER violation on a report that has not been paid even when shouldShowRterForSettledReport is false', () => {
const policy = createMock<Policy>({role: CONST.POLICY.ROLE.USER});
const transaction = generateTransaction({reportID: FAKE_PROCESSING_REPORT_ID});
const visibleViolations = TransactionUtils.getVisibleTransactionViolations(
transaction,
[brokenConnectionViolation],
CURRENT_USER_EMAIL,
CURRENT_USER_ID,
processingReport,
CURRENT_USER_EMAIL,
policy,
false,
);

expect(visibleViolations).toEqual([brokenConnectionViolation]);
});
});

describe('hasPendingRTERViolation', () => {
Expand Down
Loading