@@ -22,6 +22,7 @@ import {
2222 canAddTransaction ,
2323 canDeleteReportAction ,
2424 canDeleteTransaction ,
25+ canEditFieldOfMoneyRequest ,
2526 canEditReportDescription ,
2627 canEditRoomVisibility ,
2728 canEditWriteCapability ,
@@ -295,6 +296,71 @@ describe('ReportUtils', () => {
295296 } ) ;
296297 beforeEach ( ( ) => IntlStore . load ( CONST . LOCALES . DEFAULT ) . then ( waitForBatchedUpdates ) ) ;
297298
299+ describe ( 'canEditFieldOfMoneyRequest' , ( ) => {
300+ const reportActionID = 2 ;
301+ const IOUReportID = '1234' ;
302+ const IOUTransactionID = '123' ;
303+ const randomReportAction = createRandomReportAction ( reportActionID ) ;
304+ const policyID = '2424' ;
305+ const amount = 39 ;
306+
307+ const policy1 = { ...createRandomPolicy ( Number ( policyID ) , CONST . POLICY . TYPE . TEAM ) , areInvoicesEnabled : true , role : CONST . POLICY . ROLE . ADMIN } ;
308+
309+ // Given that there is at least one outstanding expense report in a policy
310+ const outstandingExpenseReport = {
311+ ...createExpenseReport ( 483 ) ,
312+ policyID,
313+ stateNum : CONST . REPORT . STATE_NUM . OPEN ,
314+ statusNum : CONST . REPORT . STATUS_NUM . OPEN ,
315+ ownerAccountID : currentUserAccountID ,
316+ } ;
317+
318+ // When a user creates an invoice in the same policy
319+
320+ const reportAction = {
321+ ...randomReportAction ,
322+ actionName : CONST . REPORT . ACTIONS . TYPE . IOU ,
323+ actorAccountID : currentUserAccountID ,
324+ childStateNum : CONST . REPORT . STATE_NUM . OPEN ,
325+ childStatusNum : CONST . REPORT . STATUS_NUM . OPEN ,
326+ originalMessage : {
327+ // eslint-disable-next-line deprecation/deprecation
328+ ...randomReportAction . originalMessage ,
329+ IOUReportID,
330+ IOUTransactionID,
331+ type : CONST . IOU . ACTION . CREATE ,
332+ amount,
333+ currency : CONST . CURRENCY . USD ,
334+ } ,
335+ } ;
336+
337+ const moneyRequestTransaction = { ...createRandomTransaction ( Number ( IOUTransactionID ) ) , reportID : IOUReportID , transactionID : IOUTransactionID , amount} ;
338+
339+ const invoiceReport = {
340+ ...createInvoiceReport ( Number ( IOUReportID ) ) ,
341+ policyID,
342+ ownerAccountID : currentUserAccountID ,
343+ state : CONST . REPORT . ACTIONS . TYPE . SUBMITTED ,
344+ stateNum : CONST . REPORT . STATE_NUM . SUBMITTED ,
345+ statusNum : CONST . REPORT . STATUS_NUM . SUBMITTED ,
346+ managerID : 8723 ,
347+ } ;
348+
349+ beforeAll ( ( ) => {
350+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ IOUTransactionID } ` , moneyRequestTransaction ) ;
351+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } ${ IOUReportID } ` , invoiceReport ) ;
352+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } ${ 483 } ` , outstandingExpenseReport ) ;
353+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` , policy1 ) ;
354+ return waitForBatchedUpdates ( ) ;
355+ } ) ;
356+
357+ // Then the user should be able to move the invoice to the outstanding expense report
358+ it ( 'should return true for invoice report action given that there is a minimum of one outstanding report' , ( ) => {
359+ const canEditReportField = canEditFieldOfMoneyRequest ( reportAction , CONST . EDIT_REQUEST_FIELD . REPORT ) ;
360+ expect ( canEditReportField ) . toBe ( true ) ;
361+ } ) ;
362+ } ) ;
363+
298364 describe ( 'prepareOnboardingOnyxData' , ( ) => {
299365 it ( 'provides test drive url to task title' , ( ) => {
300366 const title = jest . fn ( ) ;
0 commit comments