@@ -6017,7 +6017,7 @@ describe('actions/Policy', () => {
60176017
60186018 // eslint-disable-next-line @typescript-eslint/naming-convention
60196019 const mockTranslate = ( ( key : string ) => key ) as unknown as Parameters < typeof Policy . createWorkspaceFromIOUPayment > [ 8 ] ;
6020- Policy . createWorkspaceFromIOUPayment ( iouReport , undefined , customAccountID , customEmail , iouReportOwnerEmail , undefined , CONST . CURRENCY . USD , undefined , mockTranslate ) ;
6020+ Policy . createWorkspaceFromIOUPayment ( iouReport , undefined , customAccountID , customEmail , iouReportOwnerEmail , undefined , CONST . CURRENCY . USD , undefined , mockTranslate , { } ) ;
60216021 await waitForBatchedUpdates ( ) ;
60226022
60236023 const writeOptions = apiWriteSpy . mock . calls . at ( 0 ) ?. at ( 2 ) as {
@@ -6059,8 +6059,75 @@ describe('actions/Policy', () => {
60596059 CONST . CURRENCY . USD ,
60606060 undefined ,
60616061 mockTranslate ,
6062+ { } ,
60626063 ) ;
60636064 expect ( result ) . toBeUndefined ( ) ;
60646065 } ) ;
6066+
6067+ it ( 'should use reportActionsList parameter instead of deprecated Onyx connection' , async ( ) => {
6068+ await Onyx . set ( ONYXKEYS . SESSION , { email : ESH_EMAIL , accountID : ESH_ACCOUNT_ID } ) ;
6069+ await waitForBatchedUpdates ( ) ;
6070+
6071+ const employeeAccountID = 300 ;
6072+ const iouReportOwnerEmail = 'employee@example.com' ;
6073+
6074+ const existingChatReportID = '700' ;
6075+
6076+ // Create a report preview action for the existing chat
6077+ const reportPreviewAction : ReportAction = {
6078+ reportActionID : 'previewAction1' ,
6079+ actionName : CONST . REPORT . ACTIONS . TYPE . REPORT_PREVIEW ,
6080+ childReportID : 'childReport1' ,
6081+ created : '2024-01-01' ,
6082+ message : [ ] ,
6083+ } ;
6084+
6085+ // Pass reportActionsList explicitly - this should be used instead of the deprecated Onyx connection
6086+ const reportActionsList = {
6087+ [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ existingChatReportID } ` ] : {
6088+ [ reportPreviewAction . reportActionID ] : reportPreviewAction ,
6089+ } ,
6090+ } ;
6091+
6092+ const iouReport : Report = {
6093+ ...createRandomReport ( 1 , undefined ) ,
6094+ reportID : '800' ,
6095+ type : CONST . REPORT . TYPE . IOU ,
6096+ ownerAccountID : employeeAccountID ,
6097+ chatReportID : '801' ,
6098+ policyID : 'oldPolicyID' ,
6099+ currency : CONST . CURRENCY . USD ,
6100+ total : 2000 ,
6101+ } ;
6102+
6103+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . REPORT } ${ iouReport . reportID } ` , iouReport ) ;
6104+ await waitForBatchedUpdates ( ) ;
6105+
6106+ const isIOUReportUsingReportSpy = jest . spyOn ( ReportUtils , 'isIOUReportUsingReport' ) . mockReturnValue ( true ) ;
6107+ const apiWriteSpy = jest . spyOn ( require ( '@libs/API' ) , 'write' ) . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
6108+
6109+ // eslint-disable-next-line @typescript-eslint/naming-convention
6110+ const mockTranslate = ( ( key : string ) => key ) as unknown as Parameters < typeof Policy . createWorkspaceFromIOUPayment > [ 8 ] ;
6111+ const result = Policy . createWorkspaceFromIOUPayment (
6112+ iouReport ,
6113+ undefined ,
6114+ ESH_ACCOUNT_ID ,
6115+ ESH_EMAIL ,
6116+ iouReportOwnerEmail ,
6117+ undefined ,
6118+ CONST . CURRENCY . USD ,
6119+ undefined ,
6120+ mockTranslate ,
6121+ reportActionsList ,
6122+ ) ;
6123+
6124+ // Verify the function returns a valid result (not undefined)
6125+ expect ( result ) . toBeDefined ( ) ;
6126+ expect ( result ?. policyID ) . toBeDefined ( ) ;
6127+ expect ( result ?. workspaceChatReportID ) . toBeDefined ( ) ;
6128+
6129+ apiWriteSpy . mockRestore ( ) ;
6130+ isIOUReportUsingReportSpy . mockRestore ( ) ;
6131+ } ) ;
60656132 } ) ;
60666133} ) ;
0 commit comments