Skip to content

Commit e206f40

Browse files
MelvinBotrojiphil
andcommitted
Fix ESLint and TypeScript errors in BulkEditTest
- Add block-level eslint-disable for no-unsafe-assignment and no-unsafe-member-access in test assertion blocks using `as any` - Add missing `created` property to report action mock object - Add OnyxCollection and ReportActions type imports Co-authored-by: Roji Philip <rojiphil@users.noreply.github.com>
1 parent 01c5981 commit e206f40

1 file changed

Lines changed: 11 additions & 21 deletions

File tree

tests/actions/IOUTest/BulkEditTest.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Onyx from 'react-native-onyx';
2-
import type {OnyxKey} from 'react-native-onyx';
2+
import type {OnyxCollection, OnyxKey} from 'react-native-onyx';
33
import {clearBulkEditDraftTransaction, initBulkEditDraftTransaction, updateBulkEditDraftTransaction, updateMultipleMoneyRequests} from '@libs/actions/IOU/BulkEdit';
44
import CONST from '@src/CONST';
55
import * as API from '@src/libs/API';
66
import ONYXKEYS from '@src/ONYXKEYS';
7-
import type {Policy, Report} from '@src/types/onyx';
7+
import type {Policy, Report, ReportActions} from '@src/types/onyx';
88
import type Transaction from '@src/types/onyx/Transaction';
99
import createRandomPolicy, {createCategoryTaxExpenseRules} from '../../utils/collections/policies';
1010
import {createRandomReport} from '../../utils/collections/reports';
@@ -1554,25 +1554,21 @@ describe('actions/IOU/BulkEdit', () => {
15541554
});
15551555

15561556
expect(writeSpy).toHaveBeenCalled();
1557-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1557+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
15581558
const onyxData = writeSpy.mock.calls.at(0)?.[2] as any;
1559-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
15601559
const optimisticData = onyxData?.optimisticData as any[];
15611560

15621561
// An optimistic thread report should be created via SET
15631562
const optimisticReportSet = optimisticData.find(
1564-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
15651563
(entry: any) => String(entry.key).startsWith(ONYXKEYS.COLLECTION.REPORT) && entry.onyxMethod === 'set' && entry.key !== `${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`,
15661564
);
15671565
expect(optimisticReportSet).toBeDefined();
15681566
const optimisticThreadReportID = String(optimisticReportSet.key).replace(ONYXKEYS.COLLECTION.REPORT, '');
15691567

15701568
// The transaction optimistic data should link back to the new thread via transactionThreadReportID
1571-
const transactionMerge = optimisticData.find(
1572-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1573-
(entry: any) => entry.key === `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
1574-
);
1569+
const transactionMerge = optimisticData.find((entry: any) => entry.key === `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`);
15751570
expect(transactionMerge?.value?.transactionThreadReportID).toBe(optimisticThreadReportID);
1571+
/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
15761572

15771573
writeSpy.mockRestore();
15781574
canEditFieldSpy.mockRestore();
@@ -1635,9 +1631,10 @@ describe('actions/IOU/BulkEdit', () => {
16351631
IOUTransactionID: transactionID,
16361632
},
16371633
childReportID,
1634+
created: '2026-01-01 00:00:00',
16381635
},
16391636
},
1640-
};
1637+
} as OnyxCollection<ReportActions>;
16411638

16421639
const canEditFieldSpy = jest.spyOn(require('@libs/ReportUtils'), 'canEditFieldOfMoneyRequest').mockReturnValue(true);
16431640
// eslint-disable-next-line rulesdir/no-multiple-api-calls
@@ -1658,31 +1655,24 @@ describe('actions/IOU/BulkEdit', () => {
16581655
});
16591656

16601657
expect(writeSpy).toHaveBeenCalled();
1661-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1658+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
16621659
const onyxData = writeSpy.mock.calls.at(0)?.[2] as any;
1663-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
16641660
const optimisticData = onyxData?.optimisticData as any[];
16651661

16661662
// No optimistic thread report should be created — the existing thread from childReportID should be used
16671663
const optimisticReportSet = optimisticData.find(
1668-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
16691664
(entry: any) => String(entry.key).startsWith(ONYXKEYS.COLLECTION.REPORT) && entry.onyxMethod === 'set' && entry.key !== `${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`,
16701665
);
16711666
expect(optimisticReportSet).toBeUndefined();
16721667

16731668
// The MODIFIED_EXPENSE report action should be written to the childReportID thread, not the transactionThreadReportID thread
1674-
const reportActionMerge = optimisticData.find(
1675-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1676-
(entry: any) => entry.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${childReportID}`,
1677-
);
1669+
const reportActionMerge = optimisticData.find((entry: any) => entry.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${childReportID}`);
16781670
expect(reportActionMerge).toBeDefined();
16791671

16801672
// No report action should be written to the transactionThreadReportID thread
1681-
const wrongThreadReportAction = optimisticData.find(
1682-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1683-
(entry: any) => entry.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadID}`,
1684-
);
1673+
const wrongThreadReportAction = optimisticData.find((entry: any) => entry.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadID}`);
16851674
expect(wrongThreadReportAction).toBeUndefined();
1675+
/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
16861676

16871677
writeSpy.mockRestore();
16881678
canEditFieldSpy.mockRestore();

0 commit comments

Comments
 (0)