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
9 changes: 7 additions & 2 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12434,8 +12434,12 @@ function shouldOptimisticallyUpdateSearch(
shouldOptimisticallyUpdateByStatus &&
validSearchTypes &&
(currentSearchQueryJSON.flatFilters.length === 0 ||
[submitQueryJSON?.similarSearchHash, approveQueryJSON?.similarSearchHash].includes(currentSearchQueryJSON.similarSearchHash) ||
(unapprovedCashSimilarSearchHash === currentSearchQueryJSON.similarSearchHash && isExpenseReport(iouReport) && transaction?.reimbursable))
(submitQueryJSON?.similarSearchHash === currentSearchQueryJSON.similarSearchHash && expenseReportStatusFilterMapping[CONST.SEARCH.STATUS.EXPENSE.DRAFTS](iouReport)) ||
(approveQueryJSON?.similarSearchHash === currentSearchQueryJSON.similarSearchHash && expenseReportStatusFilterMapping[CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING](iouReport)) ||
(unapprovedCashSimilarSearchHash === currentSearchQueryJSON.similarSearchHash &&
isExpenseReport(iouReport) &&
(expenseReportStatusFilterMapping[CONST.SEARCH.STATUS.EXPENSE.DRAFTS](iouReport) || expenseReportStatusFilterMapping[CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING](iouReport)) &&
transaction?.reimbursable))
);
}

Expand Down Expand Up @@ -13855,6 +13859,7 @@ export {
updateMoneyRequestTaxRate,
mergeDuplicates,
updateLastLocationPermissionPrompt,
shouldOptimisticallyUpdateSearch,
resolveDuplicates,
getIOUReportActionToApproveOrPay,
getNavigationUrlOnMoneyRequestDelete,
Expand Down
168 changes: 168 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {deepEqual} from 'fast-equals';
import type {OnyxCollection, OnyxEntry, OnyxInputValue} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import OnyxListItemProvider from '@components/OnyxListItemProvider';
import type {SearchQueryJSON, SearchStatus} from '@components/Search/types';
import useReportWithTransactionsAndViolations from '@hooks/useReportWithTransactionsAndViolations';
import type {PerDiemExpenseTransactionParams, RequestMoneyParticipantParams} from '@libs/actions/IOU';
import {
Expand Down Expand Up @@ -38,6 +39,7 @@ import {
sendInvoice,
setDraftSplitTransaction,
setMoneyRequestCategory,
shouldOptimisticallyUpdateSearch,
splitBill,
startSplitBill,
submitReport,
Expand Down Expand Up @@ -205,6 +207,172 @@ describe('actions/IOU', () => {
jest.clearAllMocks();
});

describe('shouldOptimisticallyUpdateSearch', () => {
it('when the current hash is submit action query it should only return true if the iou report is in draft state', () => {
const transaction = {
...createRandomTransaction(1),
};
const currentSearchQueryJSON = {
type: CONST.SEARCH.DATA_TYPES.EXPENSE,
status: '' as SearchStatus,
sortBy: CONST.SEARCH.TABLE_COLUMNS.DATE,
sortOrder: CONST.SEARCH.SORT_ORDER.DESC,
groupBy: CONST.SEARCH.GROUP_BY.REPORTS,
filters: {
operator: CONST.SEARCH.SYNTAX_OPERATORS.AND,
left: {
operator: CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO,
left: CONST.SEARCH.SYNTAX_FILTER_KEYS.ACTION,
right: 'submit',
},
right: {
operator: CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO,
left: 'from',
right: '20671314',
},
},
inputQuery: 'sortBy:date sortOrder:desc type:expense groupBy:reports action:submit from:20671314',
flatFilters: [
{
key: CONST.SEARCH.SYNTAX_FILTER_KEYS.ACTION,
filters: [
{
operator: CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO,
value: 'submit',
},
],
},
{
key: CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM,
filters: [
{
operator: CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO,
value: '20671314',
},
],
},
],
hash: 1920151829,
recentSearchHash: 2100977843,
similarSearchHash: 1476388677,
} as SearchQueryJSON;
const iouReport: Report = {...createRandomReport(2), type: CONST.REPORT.TYPE.EXPENSE, stateNum: CONST.REPORT.STATE_NUM.OPEN, statusNum: CONST.REPORT.STATUS_NUM.OPEN};

// When the report is in draft status it should return true
expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, transaction)).toBeTruthy();

// If the report is not in draft state it should return false
iouReport.stateNum = CONST.REPORT.STATE_NUM.SUBMITTED;
iouReport.statusNum = CONST.REPORT.STATUS_NUM.SUBMITTED;
expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, transaction)).toBeFalsy();
});

it('when the current hash is approve action query it should only return true if the iou report is in outstanding state', () => {
const transaction = {
...createRandomTransaction(1),
};
const currentSearchQueryJSON = {
type: CONST.SEARCH.DATA_TYPES.EXPENSE,
status: '' as SearchStatus,
sortBy: CONST.SEARCH.TABLE_COLUMNS.DATE,
sortOrder: CONST.SEARCH.SORT_ORDER.DESC,
groupBy: CONST.SEARCH.GROUP_BY.REPORTS,
filters: {
operator: CONST.SEARCH.SYNTAX_OPERATORS.AND,
left: {
operator: CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO,
left: CONST.SEARCH.SYNTAX_FILTER_KEYS.ACTION,
right: 'approve',
},
right: {
operator: CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO,
left: 'from',
right: '20671314',
},
},
flatFilters: [
{
key: CONST.SEARCH.SYNTAX_FILTER_KEYS.ACTION,
filters: [
{
operator: CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO,
value: 'approve',
},
],
},
{
key: CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM,
filters: [
{
operator: CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO,
value: '20671314',
},
],
},
],

hash: 1510971479,
inputQuery: 'sortBy:date sortOrder:desc type:expense groupBy:reports action:approve to:20671314',
recentSearchHash: 967911777,
similarSearchHash: 601088623,
} as SearchQueryJSON;
const iouReport: Report = {...createRandomReport(2), type: CONST.REPORT.TYPE.EXPENSE, stateNum: CONST.REPORT.STATE_NUM.OPEN, statusNum: CONST.REPORT.STATUS_NUM.OPEN};

// When the report is in draft status it should return false
expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, transaction)).toBeFalsy();

// If the report is in outstanding state it should return true
iouReport.stateNum = CONST.REPORT.STATE_NUM.SUBMITTED;
iouReport.statusNum = CONST.REPORT.STATUS_NUM.SUBMITTED;
expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, transaction)).toBeTruthy();
});

it('when the current hash is unapproved cash action query it should only return true if the iou report is in either draft or outstanding state', () => {
const transaction = {
...createRandomTransaction(1),
reimbursable: true,
};
const currentSearchQueryJSON = {
type: CONST.SEARCH.DATA_TYPES.EXPENSE,
status: '' as SearchStatus,
sortBy: CONST.SEARCH.TABLE_COLUMNS.DATE,
sortOrder: CONST.SEARCH.SORT_ORDER.DESC,
groupBy: CONST.SEARCH.GROUP_BY.REPORTS,
filters: {
operator: CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO,
left: 'reimbursable',

right: 'yes',
},
flatFilters: [
{
key: CONST.SEARCH.SYNTAX_FILTER_KEYS.REIMBURSABLE,
filters: [
{
operator: CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO,
value: 'yes',
},
],
},
],
hash: 71801560,
inputQuery: 'sortBy:date sortOrder:desc type:expense groupBy:from status:drafts,outstanding reimbursable:yes',
recentSearchHash: 1043581824,
similarSearchHash: 1832274510,
} as SearchQueryJSON;

const iouReport: Report = {...createRandomReport(2), type: CONST.REPORT.TYPE.EXPENSE, stateNum: CONST.REPORT.STATE_NUM.OPEN, statusNum: CONST.REPORT.STATUS_NUM.OPEN};

// When the report is in draft status it should return true
expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, transaction)).toBeTruthy();

// If the report is in approved state it should return false
iouReport.stateNum = CONST.REPORT.STATE_NUM.APPROVED;
iouReport.statusNum = CONST.REPORT.STATUS_NUM.APPROVED;
expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, transaction)).toBeFalsy();
});
});

describe('trackExpense', () => {
it('category a distance expense of selfDM report', async () => {
/*
Expand Down