11/* eslint-disable @typescript-eslint/no-unsafe-assignment */
22import Onyx from 'react-native-onyx' ;
33import type { OnyxEntry , OnyxInputValue } from 'react-native-onyx' ;
4+ import * as Hold from '@libs/actions/IOU/Hold' ;
45import { putOnHold } from '@libs/actions/IOU/Hold' ;
56import { cancelPayment , completePaymentOnboarding , payMoneyRequest } from '@libs/actions/IOU/PayMoneyRequest' ;
67import { requestMoney } from '@libs/actions/IOU/TrackExpense' ;
@@ -9,6 +10,7 @@ import {createWorkspace, generatePolicyID} from '@libs/actions/Policy/Policy';
910import { notifyNewAction } from '@libs/actions/Report' ;
1011import type * as PolicyUtils from '@libs/PolicyUtils' ;
1112import { getOriginalMessage , getReportActionHtml , getReportActionText , isMoneyRequestAction } from '@libs/ReportActionsUtils' ;
13+ import * as ReportUtils from '@libs/ReportUtils' ;
1214import { buildOptimisticIOUReport , buildOptimisticIOUReportAction } from '@libs/ReportUtils' ;
1315import { buildOptimisticTransaction } from '@libs/TransactionUtils' ;
1416import CONST from '@src/CONST' ;
@@ -252,6 +254,7 @@ describe('actions/IOU/PayMoneyRequest', () => {
252254 userBillingGracePeriodEnds : undefined ,
253255 amountOwed : 0 ,
254256 chatReportPolicy : chatReportPolicyFromChat ( chatReport ) ,
257+ conciergeReportID : undefined ,
255258 } ) ;
256259 return waitForBatchedUpdates ( ) ;
257260 } )
@@ -464,6 +467,7 @@ describe('actions/IOU/PayMoneyRequest', () => {
464467 userBillingGracePeriodEnds : undefined ,
465468 amountOwed : 0 ,
466469 chatReportPolicy : chatReportPolicyFromChat ( chatReport ) ,
470+ conciergeReportID : undefined ,
467471 } ) ;
468472 return waitForBatchedUpdates ( ) ;
469473 } )
@@ -630,6 +634,7 @@ describe('actions/IOU/PayMoneyRequest', () => {
630634 userBillingGracePeriodEnds : undefined ,
631635 amountOwed : 0 ,
632636 chatReportPolicy : chatReportPolicyFromChat ( chatReport ) ,
637+ conciergeReportID : undefined ,
633638 } ) ;
634639 return waitForBatchedUpdates ( ) ;
635640 } )
@@ -684,6 +689,7 @@ describe('actions/IOU/PayMoneyRequest', () => {
684689 userBillingGracePeriodEnds : undefined ,
685690 amountOwed : 0 ,
686691 chatReportPolicy,
692+ conciergeReportID : undefined ,
687693 } ) ;
688694
689695 await waitForBatchedUpdates ( ) ;
@@ -801,6 +807,7 @@ describe('actions/IOU/PayMoneyRequest', () => {
801807 userBillingGracePeriodEnds : undefined ,
802808 amountOwed : 0 ,
803809 chatReportPolicy : chatReportPolicyFromChat ( partialPayChatReport ) ,
810+ conciergeReportID : undefined ,
804811 } ) ;
805812 return waitForBatchedUpdates ( ) ;
806813 } )
@@ -898,6 +905,7 @@ describe('actions/IOU/PayMoneyRequest', () => {
898905 isSelfTourViewed : false ,
899906 userBillingGracePeriodEnds : undefined ,
900907 amountOwed : 0 ,
908+ conciergeReportID : undefined ,
901909 } ) ;
902910 await waitForBatchedUpdates ( ) ;
903911 const newExpenseReport = await getOnyxValue ( `${ ONYXKEYS . COLLECTION . REPORT } ${ newExpenseReportID } ` ) ;
@@ -935,6 +943,7 @@ describe('actions/IOU/PayMoneyRequest', () => {
935943 userBillingGracePeriodEnds : undefined ,
936944 amountOwed : 0 ,
937945 chatReportPolicy : chatReportPolicyTrueTour ,
946+ conciergeReportID : undefined ,
938947 } ) ;
939948
940949 await waitForBatchedUpdates ( ) ;
@@ -985,6 +994,7 @@ describe('actions/IOU/PayMoneyRequest', () => {
985994 userBillingGracePeriodEnds : undefined ,
986995 amountOwed : 0 ,
987996 chatReportPolicy : chatReportPolicyFalseTour ,
997+ conciergeReportID : undefined ,
988998 } ) ;
989999
9901000 await waitForBatchedUpdates ( ) ;
@@ -1056,6 +1066,7 @@ describe('actions/IOU/PayMoneyRequest', () => {
10561066 ownerBillingGracePeriodEnd : pastDate ,
10571067 policy,
10581068 chatReportPolicy : policy ,
1069+ conciergeReportID : undefined ,
10591070 } ) ;
10601071
10611072 await waitForBatchedUpdates ( ) ;
@@ -1122,6 +1133,7 @@ describe('actions/IOU/PayMoneyRequest', () => {
11221133 ownerBillingGracePeriodEnd : pastDate ,
11231134 policy : expensePolicy ,
11241135 chatReportPolicy : workspacePolicy ,
1136+ conciergeReportID : undefined ,
11251137 } ) ;
11261138
11271139 await waitForBatchedUpdates ( ) ;
@@ -1178,6 +1190,7 @@ describe('actions/IOU/PayMoneyRequest', () => {
11781190 ownerBillingGracePeriodEnd : futureGraceEnd ,
11791191 chatReportPolicy : workspacePolicy ,
11801192 policy : workspacePolicy ,
1193+ conciergeReportID : undefined ,
11811194 } ) ;
11821195
11831196 await waitForBatchedUpdates ( ) ;
@@ -1214,6 +1227,7 @@ describe('actions/IOU/PayMoneyRequest', () => {
12141227 userBillingGracePeriodEnds : undefined ,
12151228 amountOwed : 0 ,
12161229 chatReportPolicy : chatReportPolicyAmountZero ,
1230+ conciergeReportID : undefined ,
12171231 } ) ;
12181232
12191233 await waitForBatchedUpdates ( ) ;
@@ -1233,6 +1247,94 @@ describe('actions/IOU/PayMoneyRequest', () => {
12331247
12341248 mockFetch ?. resume ?.( ) ;
12351249 } ) ;
1250+
1251+ it ( 'forwards the provided conciergeReportID to buildOptimisticReportPreview when partially paying' , async ( ) => {
1252+ // Given an iou report with two transactions, one of which is held (so partial pay is possible)
1253+ const iouReport = buildOptimisticIOUReport ( 1 , 2 , 100 , '1' , 'USD' ) ;
1254+ const transaction1 = buildOptimisticTransaction ( {
1255+ transactionParams : { amount : 100 , currency : 'USD' , reportID : iouReport . reportID } ,
1256+ } ) ;
1257+ const transaction2 = buildOptimisticTransaction ( {
1258+ transactionParams : { amount : 100 , currency : 'USD' , reportID : iouReport . reportID } ,
1259+ } ) ;
1260+ const concierge42TransactionDataSet : TransactionCollectionDataSet = {
1261+ [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ transaction1 . transactionID } ` ] : transaction1 ,
1262+ [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ transaction2 . transactionID } ` ] : transaction2 ,
1263+ } ;
1264+ await Onyx . multiSet ( concierge42TransactionDataSet ) ;
1265+ putOnHold ( transaction1 . transactionID , 'comment' , iouReport . reportID , false , RORY_EMAIL , RORY_ACCOUNT_ID ) ;
1266+ await waitForBatchedUpdates ( ) ;
1267+
1268+ const buildOptimisticReportPreviewSpy = jest . spyOn ( ReportUtils , 'buildOptimisticReportPreview' ) ;
1269+ const partialPayChatReport = { reportID : topMostReportID , policyID : CONST . POLICY . ID_FAKE } ;
1270+ const conciergeReportID = 'concierge_report_id_42' ;
1271+
1272+ // When partial paying with a specific conciergeReportID
1273+ payMoneyRequest ( {
1274+ paymentType : CONST . IOU . PAYMENT_TYPE . ELSEWHERE ,
1275+ chatReport : partialPayChatReport ,
1276+ iouReport,
1277+ introSelected : undefined ,
1278+ iouReportCurrentNextStepDeprecated : undefined ,
1279+ currentUserAccountID : CARLOS_ACCOUNT_ID ,
1280+ currentUserLogin : CARLOS_EMAIL ,
1281+ full : false ,
1282+ betas : [ CONST . BETAS . ALL ] ,
1283+ isSelfTourViewed : false ,
1284+ userBillingGracePeriodEnds : undefined ,
1285+ amountOwed : 0 ,
1286+ chatReportPolicy : chatReportPolicyFromChat ( partialPayChatReport ) ,
1287+ conciergeReportID,
1288+ } ) ;
1289+ await waitForBatchedUpdates ( ) ;
1290+
1291+ // Then buildOptimisticReportPreview should receive the same conciergeReportID
1292+ expect ( buildOptimisticReportPreviewSpy ) . toHaveBeenCalled ( ) ;
1293+ const callsWithConciergeID = buildOptimisticReportPreviewSpy . mock . calls . filter ( ( args ) => args . at ( 6 ) === conciergeReportID ) ;
1294+ expect ( callsWithConciergeID . length ) . toBeGreaterThan ( 0 ) ;
1295+
1296+ buildOptimisticReportPreviewSpy . mockRestore ( ) ;
1297+ } ) ;
1298+
1299+ it ( 'does not invoke getReportFromHoldRequestsOnyxData when full paying, so conciergeReportID is not forwarded' , async ( ) => {
1300+ // Given an iou report and a non-partial pay (full=true is the default)
1301+ const chatReport = {
1302+ ...createRandomReport ( 0 , undefined ) ,
1303+ lastReadTime : DateUtils . getDBTime ( ) ,
1304+ lastVisibleActionCreated : DateUtils . getDBTime ( ) ,
1305+ } ;
1306+ const iouReport = {
1307+ ...createRandomReport ( 1 , undefined ) ,
1308+ chatType : undefined ,
1309+ type : CONST . REPORT . TYPE . IOU ,
1310+ total : 10 ,
1311+ } ;
1312+ const getReportFromHoldRequestsOnyxDataSpy = jest . spyOn ( Hold , 'getReportFromHoldRequestsOnyxData' ) ;
1313+ const conciergeReportID = 'concierge_report_id_should_not_propagate' ;
1314+
1315+ // When fully paying
1316+ payMoneyRequest ( {
1317+ paymentType : CONST . IOU . PAYMENT_TYPE . ELSEWHERE ,
1318+ chatReport,
1319+ iouReport,
1320+ introSelected : undefined ,
1321+ iouReportCurrentNextStepDeprecated : undefined ,
1322+ currentUserAccountID : CARLOS_ACCOUNT_ID ,
1323+ currentUserLogin : CARLOS_EMAIL ,
1324+ betas : [ CONST . BETAS . ALL ] ,
1325+ isSelfTourViewed : false ,
1326+ userBillingGracePeriodEnds : undefined ,
1327+ amountOwed : 0 ,
1328+ chatReportPolicy : chatReportPolicyFromChat ( chatReport ) ,
1329+ conciergeReportID,
1330+ } ) ;
1331+ await waitForBatchedUpdates ( ) ;
1332+
1333+ // Then getReportFromHoldRequestsOnyxData is not called at all because full pay skips the hold flow
1334+ expect ( getReportFromHoldRequestsOnyxDataSpy ) . not . toHaveBeenCalled ( ) ;
1335+
1336+ getReportFromHoldRequestsOnyxDataSpy . mockRestore ( ) ;
1337+ } ) ;
12361338 } ) ;
12371339
12381340 describe ( 'a expense chat with a cancelled payment' , ( ) => {
@@ -1338,6 +1440,7 @@ describe('actions/IOU/PayMoneyRequest', () => {
13381440 userBillingGracePeriodEnds : undefined ,
13391441 amountOwed : 0 ,
13401442 chatReportPolicy : chatReportPolicyFromChat ( chatReport ) ,
1443+ conciergeReportID : undefined ,
13411444 } ) ;
13421445 return waitForBatchedUpdates ( ) ;
13431446 } )
@@ -1563,6 +1666,7 @@ describe('actions/IOU/PayMoneyRequest', () => {
15631666 userBillingGracePeriodEnds : undefined ,
15641667 amountOwed : 0 ,
15651668 chatReportPolicy : chatReportPolicyFromChat ( chatReport ) ,
1669+ conciergeReportID : undefined ,
15661670 } ) ;
15671671 }
15681672 await waitForBatchedUpdates ( ) ;
0 commit comments