@@ -5718,7 +5718,7 @@ describe('actions/Policy', () => {
57185718
57195719 // eslint-disable-next-line @typescript-eslint/naming-convention
57205720 const mockTranslate = ( ( key : string ) => key ) as unknown as Parameters < typeof Policy . createWorkspaceFromIOUPayment > [ 7 ] ;
5721- Policy . createWorkspaceFromIOUPayment ( iouReport , undefined , customAccountID , customEmail , iouReportOwnerEmail , undefined , undefined , mockTranslate ) ;
5721+ Policy . createWorkspaceFromIOUPayment ( iouReport , undefined , customAccountID , customEmail , iouReportOwnerEmail , undefined , undefined , mockTranslate , { } ) ;
57225722 await waitForBatchedUpdates ( ) ;
57235723
57245724 const writeOptions = apiWriteSpy . mock . calls . at ( 0 ) ?. at ( 2 ) as {
@@ -5750,8 +5750,63 @@ describe('actions/Policy', () => {
57505750
57515751 // eslint-disable-next-line @typescript-eslint/naming-convention
57525752 const mockTranslate = ( ( key : string ) => key ) as unknown as Parameters < typeof Policy . createWorkspaceFromIOUPayment > [ 7 ] ;
5753- const result = Policy . createWorkspaceFromIOUPayment ( nonIOUReport , undefined , ESH_ACCOUNT_ID , ESH_EMAIL , 'owner@example.com' , undefined , undefined , mockTranslate ) ;
5753+ const result = Policy . createWorkspaceFromIOUPayment ( nonIOUReport , undefined , ESH_ACCOUNT_ID , ESH_EMAIL , 'owner@example.com' , undefined , undefined , mockTranslate , { } ) ;
57545754 expect ( result ) . toBeUndefined ( ) ;
57555755 } ) ;
5756+
5757+ it ( 'should use reportActionsList parameter instead of deprecated Onyx connection' , async ( ) => {
5758+ await Onyx . set ( ONYXKEYS . SESSION , { email : ESH_EMAIL , accountID : ESH_ACCOUNT_ID } ) ;
5759+ await waitForBatchedUpdates ( ) ;
5760+
5761+ const employeeAccountID = 300 ;
5762+ const iouReportOwnerEmail = 'employee@example.com' ;
5763+
5764+ const existingChatReportID = '700' ;
5765+
5766+ // Create a report preview action for the existing chat
5767+ const reportPreviewAction : ReportAction = {
5768+ reportActionID : 'previewAction1' ,
5769+ actionName : CONST . REPORT . ACTIONS . TYPE . REPORT_PREVIEW ,
5770+ childReportID : 'childReport1' ,
5771+ created : '2024-01-01' ,
5772+ message : [ ] ,
5773+ } ;
5774+
5775+ // Pass reportActionsList explicitly - this should be used instead of the deprecated Onyx connection
5776+ const reportActionsList = {
5777+ [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ existingChatReportID } ` ] : {
5778+ [ reportPreviewAction . reportActionID ] : reportPreviewAction ,
5779+ } ,
5780+ } ;
5781+
5782+ const iouReport : Report = {
5783+ ...createRandomReport ( 1 , undefined ) ,
5784+ reportID : '800' ,
5785+ type : CONST . REPORT . TYPE . IOU ,
5786+ ownerAccountID : employeeAccountID ,
5787+ chatReportID : '801' ,
5788+ policyID : 'oldPolicyID' ,
5789+ currency : CONST . CURRENCY . USD ,
5790+ total : 2000 ,
5791+ } ;
5792+
5793+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . REPORT } ${ iouReport . reportID } ` , iouReport ) ;
5794+ await waitForBatchedUpdates ( ) ;
5795+
5796+ const isIOUReportUsingReportSpy = jest . spyOn ( ReportUtils , 'isIOUReportUsingReport' ) . mockReturnValue ( true ) ;
5797+ const apiWriteSpy = jest . spyOn ( require ( '@libs/API' ) , 'write' ) . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
5798+
5799+ // eslint-disable-next-line @typescript-eslint/naming-convention
5800+ const mockTranslate = ( ( key : string ) => key ) as unknown as Parameters < typeof Policy . createWorkspaceFromIOUPayment > [ 7 ] ;
5801+ const result = Policy . createWorkspaceFromIOUPayment ( iouReport , undefined , ESH_ACCOUNT_ID , ESH_EMAIL , iouReportOwnerEmail , undefined , undefined , mockTranslate , reportActionsList ) ;
5802+
5803+ // Verify the function returns a valid result (not undefined)
5804+ expect ( result ) . toBeDefined ( ) ;
5805+ expect ( result ?. policyID ) . toBeDefined ( ) ;
5806+ expect ( result ?. workspaceChatReportID ) . toBeDefined ( ) ;
5807+
5808+ apiWriteSpy . mockRestore ( ) ;
5809+ isIOUReportUsingReportSpy . mockRestore ( ) ;
5810+ } ) ;
57565811 } ) ;
57575812} ) ;
0 commit comments