@@ -1704,38 +1704,33 @@ describe('actions/IOU', () => {
17041704 mockFetch ?. resume ?.( ) ;
17051705 await waitForBatchedUpdates ( ) ;
17061706
1707- // Helper for collection data that requires waitForCollectionCallback
1708- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1709- const waitForCollectionData = < T > ( key : string ) : Promise < T > => {
1710- return new Promise < T > ( ( resolve ) => {
1711- const connection = Onyx . connect ( {
1712- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1713- key : key as any ,
1714- waitForCollectionCallback : true ,
1715- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1716- callback : ( data : any ) => {
1717- Onyx . disconnect ( connection ) ;
1718- resolve ( data as T ) ;
1719- } ,
1720- } ) ;
1721- } ) ;
1722- } ;
1723-
17241707 // Capture the created tracked expense data
1725- const allReports = await waitForCollectionData < OnyxCollection < Report > > ( ONYXKEYS . COLLECTION . REPORT ) ;
1726- const reports = Object . values ( allReports ?? { } ) ;
1727- const selfDMReportOnyx = reports . find ( ( report ) => report ?. reportID === selfDMReport . reportID ) ;
1728- const selfDMReportID = selfDMReportOnyx ?. reportID ;
1708+ let selfDMReportID : string | undefined ;
1709+ await getOnyxData ( {
1710+ key : ONYXKEYS . COLLECTION . REPORT ,
1711+ waitForCollectionCallback : true ,
1712+ callback : ( reports ) => {
1713+ const selfDMReportOnyx = Object . values ( reports ?? { } ) . find ( ( report ) => report ?. reportID === selfDMReport . reportID ) ;
1714+ selfDMReportID = selfDMReportOnyx ?. reportID ;
1715+ } ,
1716+ } ) ;
17291717
17301718 const reportActions = await getOnyxValue ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ selfDMReportID } ` ) ;
17311719 const actions = Object . values ( reportActions ?? { } ) ;
17321720 const linkedTrackedExpenseReportAction = actions . find ( ( action ) => action && isMoneyRequestAction ( action ) ) ;
17331721 const actionableWhisperReportActionID = actions . find ( ( action ) => action && isActionableTrackExpense ( action ) ) ?. reportActionID ;
17341722
1735- const allTransactions = await waitForCollectionData < OnyxCollection < Transaction > > ( ONYXKEYS . COLLECTION . TRANSACTION ) ;
1736- const transaction = Object . values ( allTransactions ?? { } ) . find ( ( t ) => ! isEmptyObject ( t ) ) ;
1737- const transactionID = transaction ?. transactionID ;
1738- const linkedTrackedExpenseReportID = transaction ?. reportID ;
1723+ let transactionID : string | undefined ;
1724+ let linkedTrackedExpenseReportID : string | undefined ;
1725+ await getOnyxData ( {
1726+ key : ONYXKEYS . COLLECTION . TRANSACTION ,
1727+ waitForCollectionCallback : true ,
1728+ callback : ( allTransactions ) => {
1729+ const transaction = Object . values ( allTransactions ?? { } ) . find ( ( t ) => ! isEmptyObject ( t ) ) ;
1730+ transactionID = transaction ?. transactionID ;
1731+ linkedTrackedExpenseReportID = transaction ?. reportID ;
1732+ } ,
1733+ } ) ;
17391734
17401735 // Now pause fetch and share the tracked expense with accountant
17411736 mockFetch ?. pause ?.( ) ;
@@ -1769,15 +1764,24 @@ describe('actions/IOU', () => {
17691764 await waitForBatchedUpdates ( ) ;
17701765
17711766 // Verify optimistic data is created with pending status
1772- const allReportsAfterShare = await waitForCollectionData < OnyxCollection < Report > > ( ONYXKEYS . COLLECTION . REPORT ) ;
1773- const reportsAfterShare = Object . values ( allReportsAfterShare ?? { } ) ;
1774-
1775- // Find the policy expense chat and money request report
1776- const policyExpenseChatOnyx = reportsAfterShare . find ( ( report ) => report ?. reportID === policyExpenseChat . reportID ) ;
1777- const moneyRequestReport = reportsAfterShare . find ( ( report ) => report ?. type === CONST . REPORT . TYPE . IOU ) ;
1778-
1779- const policyExpenseChatReportID = policyExpenseChatOnyx ?. reportID ;
1780- const moneyRequestReportID = moneyRequestReport ?. reportID ;
1767+ let policyExpenseChatReportID : string | undefined ;
1768+ let moneyRequestReportID : string | undefined ;
1769+ let policyExpenseChatOnyx : Report | undefined ;
1770+ let moneyRequestReport : Report | undefined ;
1771+ await getOnyxData ( {
1772+ key : ONYXKEYS . COLLECTION . REPORT ,
1773+ waitForCollectionCallback : true ,
1774+ callback : ( allReportsAfterShare ) => {
1775+ const reportsAfterShare = Object . values ( allReportsAfterShare ?? { } ) ;
1776+
1777+ // Find the policy expense chat and money request report
1778+ policyExpenseChatOnyx = reportsAfterShare . find ( ( report ) => report ?. reportID === policyExpenseChat . reportID ) ;
1779+ moneyRequestReport = reportsAfterShare . find ( ( report ) => report ?. type === CONST . REPORT . TYPE . IOU ) ;
1780+
1781+ policyExpenseChatReportID = policyExpenseChatOnyx ?. reportID ;
1782+ moneyRequestReportID = moneyRequestReport ?. reportID ;
1783+ } ,
1784+ } ) ;
17811785
17821786 // Verify accountant was added to the expense chat
17831787 expect ( policyExpenseChatOnyx ?. participants ?. [ accountant . accountID ] ) . toBeTruthy ( ) ;
0 commit comments