Skip to content

Commit de8556f

Browse files
committed
Change function name to createUnreportedExpenses and fix eslint checks
1 parent 2ef8043 commit de8556f

3 files changed

Lines changed: 19 additions & 20 deletions

File tree

src/libs/TransactionUtils/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,7 @@ function getChildTransactions(transactions: OnyxCollection<Transaction>, reports
22362236
/**
22372237
* Creates sections data for unreported expenses, marking transactions with DELETE pending action as disabled
22382238
*/
2239-
function createUnreportedExpenseSections(transactions: Array<Transaction | undefined>): Array<UnreportedExpenseListItemType> {
2239+
function createUnreportedExpenses(transactions: Array<Transaction | undefined>): UnreportedExpenseListItemType[] {
22402240
return transactions
22412241
.filter((t): t is Transaction => t !== undefined)
22422242
.map(
@@ -2359,7 +2359,7 @@ export {
23592359
getTransactionPendingAction,
23602360
isTransactionPendingDelete,
23612361
getChildTransactions,
2362-
createUnreportedExpenseSections,
2362+
createUnreportedExpenses,
23632363
isDemoTransaction,
23642364
shouldShowViolation,
23652365
isUnreportedAndHasInvalidDistanceRateTransaction,

src/pages/AddUnreportedExpense.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {canSubmitPerDiemExpenseFromWorkspace, getPerDiemCustomUnit} from '@libs/
2727
import {getTransactionDetails, isIOUReport} from '@libs/ReportUtils';
2828
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
2929
import tokenizedSearch from '@libs/tokenizedSearch';
30-
import {createUnreportedExpenseSections, getAmount, getCurrency, getDescription, getMerchant, isPerDiemRequest} from '@libs/TransactionUtils';
30+
import {createUnreportedExpenses, getAmount, getCurrency, getDescription, getMerchant, isPerDiemRequest} from '@libs/TransactionUtils';
3131
import Navigation from '@navigation/Navigation';
3232
import type {PlatformStackScreenProps} from '@navigation/PlatformStackNavigation/types';
3333
import {convertBulkTrackedExpensesToIOU, startMoneyRequest} from '@userActions/IOU';
@@ -154,7 +154,7 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
154154
}, [debouncedSearchValue, shouldShowTextInput, transactions]);
155155

156156
const unreportedExpenses = useMemo(() => {
157-
return createUnreportedExpenseSections(filteredTransactions).map((item) => ({
157+
return createUnreportedExpenses(filteredTransactions).map((item) => ({
158158
...item,
159159
isSelected: selectedIds.has(item.transactionID),
160160
}));

tests/unit/AddUnreportedExpenseTest.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createUnreportedExpenseSections} from '@libs/TransactionUtils';
1+
import {createUnreportedExpenses} from '@libs/TransactionUtils';
22
import CONST from '@src/CONST';
33
import type Transaction from '@src/types/onyx/Transaction';
44

@@ -24,7 +24,7 @@ function generateTransaction(values: Partial<Transaction> = {}): Transaction {
2424
}
2525

2626
describe('AddUnreportedExpense', () => {
27-
describe('createUnreportedExpenseSections', () => {
27+
describe('createUnreportedExpenses', () => {
2828
it('should mark transactions with DELETE pendingAction as disabled', () => {
2929
const normalTransaction = generateTransaction({
3030
transactionID: '123',
@@ -41,16 +41,15 @@ describe('AddUnreportedExpense', () => {
4141
});
4242

4343
const transactions = [normalTransaction, deletedTransaction];
44-
const sections = createUnreportedExpenseSections(transactions);
44+
const unreportedExpenses = createUnreportedExpenses(transactions);
4545

46-
// Should create one section
47-
expect(sections).toHaveLength(2);
46+
expect(unreportedExpenses).toHaveLength(2);
4847

49-
const processedNormalTransaction = sections.find((t) => t.transactionID === '123');
48+
const processedNormalTransaction = unreportedExpenses.find((t) => t.transactionID === '123');
5049
expect(processedNormalTransaction?.isDisabled).toBe(false);
5150
expect(processedNormalTransaction?.keyForList).toBe('123');
5251

53-
const processedDeletedTransaction = sections.find((t) => t.transactionID === '456');
52+
const processedDeletedTransaction = unreportedExpenses.find((t) => t.transactionID === '456');
5453
expect(processedDeletedTransaction?.isDisabled).toBe(true);
5554
expect(processedDeletedTransaction?.keyForList).toBe('456');
5655
});
@@ -78,11 +77,11 @@ describe('AddUnreportedExpense', () => {
7877
});
7978

8079
const transactions = [normalTransaction, updateTransaction, addTransaction];
81-
const sections = createUnreportedExpenseSections(transactions);
80+
const unreportedExpenses = createUnreportedExpenses(transactions);
8281

83-
expect(sections).toHaveLength(3);
82+
expect(unreportedExpenses).toHaveLength(3);
8483
// eslint-disable-next-line unicorn/no-array-for-each
85-
sections.forEach((transaction) => {
84+
unreportedExpenses.forEach((transaction) => {
8685
expect(transaction.isDisabled).toBe(false);
8786
});
8887
});
@@ -103,11 +102,11 @@ describe('AddUnreportedExpense', () => {
103102
});
104103

105104
const transactions = [deletedTransaction1, deletedTransaction2];
106-
const sections = createUnreportedExpenseSections(transactions);
105+
const unreportedExpenses = createUnreportedExpenses(transactions);
107106

108-
expect(sections).toHaveLength(2);
107+
expect(unreportedExpenses).toHaveLength(2);
109108
// eslint-disable-next-line unicorn/no-array-for-each
110-
sections.forEach((transaction) => {
109+
unreportedExpenses.forEach((transaction) => {
111110
expect(transaction.isDisabled).toBe(true);
112111
expect(transaction.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);
113112
});
@@ -119,10 +118,10 @@ describe('AddUnreportedExpense', () => {
119118
});
120119

121120
const transactions = [normalTransaction, undefined];
122-
const result = createUnreportedExpenseSections(transactions);
121+
const unreportedExpenses = createUnreportedExpenses(transactions);
123122

124-
expect(result).toHaveLength(1);
125-
expect(result[0].transactionID).toBe('123');
123+
expect(unreportedExpenses).toHaveLength(1);
124+
expect(unreportedExpenses.at(0)?.transactionID).toBe('123');
126125
});
127126
});
128127
});

0 commit comments

Comments
 (0)