@@ -2,10 +2,10 @@ import type {KeyValueMapping} from 'react-native-onyx';
22import Onyx from 'react-native-onyx' ;
33import { isExpenseReport } from '@libs/ReportUtils' ;
44import { actionR14932 as mockIOUAction , originalMessageR14932 as mockOriginalMessage } from '../../__mocks__/reportData/actions' ;
5- import { iouReportR14932 as mockIOUReport } from '../../__mocks__/reportData/reports' ;
5+ import { chatReportR14932 as mockChatReport , iouReportR14932 as mockIOUReport } from '../../__mocks__/reportData/reports' ;
66import CONST from '../../src/CONST' ;
77import * as ReportActionsUtils from '../../src/libs/ReportActionsUtils' ;
8- import { getOneTransactionThreadReportID , getOriginalMessage , isIOUActionMatchingTransactionList } from '../../src/libs/ReportActionsUtils' ;
8+ import { getOneTransactionThreadReportID , getOriginalMessage , getSendMoneyFlowOneTransactionThreadID , isIOUActionMatchingTransactionList } from '../../src/libs/ReportActionsUtils' ;
99import ONYXKEYS from '../../src/ONYXKEYS' ;
1010import type { Report , ReportAction } from '../../src/types/onyx' ;
1111import createRandomReport from '../utils/collections/reports' ;
@@ -856,7 +856,68 @@ describe('ReportActionsUtils', () => {
856856 } ) ;
857857 } ) ;
858858
859- describe ( 'getOneTransactionThreadReportID' , ( ) => { } ) ;
859+ describe ( 'getSendMoneyFlowOneTransactionThreadID' , ( ) => {
860+ const mockChatReportID = 'REPORT' ;
861+ const mockDMChatReportID = 'REPORT_DM' ;
862+ const childReportID = 'childReport123' ;
863+
864+ const mockedReports : Record < `${typeof ONYXKEYS . COLLECTION . REPORT } ${string } `, Report > = {
865+ [ `${ ONYXKEYS . COLLECTION . REPORT } ${ mockChatReportID } ` ] : { ...mockChatReport , reportID : mockChatReportID } ,
866+ [ `${ ONYXKEYS . COLLECTION . REPORT } ${ mockDMChatReportID } ` ] : {
867+ ...mockChatReport ,
868+ reportID : mockDMChatReportID ,
869+ chatType : undefined ,
870+ parentReportID : undefined ,
871+ parentReportActionID : undefined ,
872+ } ,
873+ } ;
874+
875+ beforeEach ( async ( ) => {
876+ await Onyx . mergeCollection ( ONYXKEYS . COLLECTION . REPORT , mockedReports ) ;
877+ } ) ;
878+
879+ const createAction = {
880+ ...mockIOUAction ,
881+ childReportID,
882+ originalMessage : { ...getOriginalMessage ( mockIOUAction ) , type : CONST . IOU . TYPE . CREATE } ,
883+ } ;
884+
885+ const nonIOUAction = {
886+ ...mockIOUAction ,
887+ childReportID,
888+ type : CONST . REPORT . ACTIONS . TYPE . CREATED ,
889+ } ;
890+
891+ const payAction = {
892+ ...mockIOUAction ,
893+ childReportID,
894+ originalMessage : { ...getOriginalMessage ( mockIOUAction ) , type : CONST . IOU . TYPE . PAY } ,
895+ } ;
896+
897+ it ( 'should return undefined for a single non-IOU action' , ( ) => {
898+ expect ( getSendMoneyFlowOneTransactionThreadID ( [ nonIOUAction ] , mockDMChatReportID ) ) . toBeUndefined ( ) ;
899+ } ) ;
900+
901+ it ( 'should return undefined for multiple IOU actions regardless of type' , ( ) => {
902+ expect ( getSendMoneyFlowOneTransactionThreadID ( [ payAction , payAction ] , mockDMChatReportID ) ) . toBeUndefined ( ) ;
903+ } ) ;
904+
905+ it ( 'should return undefined for a single IOU action that is not `Pay`' , ( ) => {
906+ expect ( getSendMoneyFlowOneTransactionThreadID ( [ createAction ] , mockDMChatReportID ) ) . toBeUndefined ( ) ;
907+ } ) ;
908+
909+ it ( 'should return the appropriate childReportID for a valid single `Pay` IOU action in DM chat' , ( ) => {
910+ expect ( getSendMoneyFlowOneTransactionThreadID ( [ payAction ] , mockDMChatReportID ) ) . toEqual ( childReportID ) ;
911+ } ) ;
912+
913+ it ( 'should return undefined for a valid single `Pay` IOU action in a chat that is not DM' , ( ) => {
914+ expect ( getSendMoneyFlowOneTransactionThreadID ( [ payAction ] , mockChatReportID ) ) . toBeUndefined ( ) ;
915+ } ) ;
916+
917+ it ( 'should return undefined for a valid `Pay` IOU action in DM chat that has also a create IOU action' , ( ) => {
918+ expect ( getSendMoneyFlowOneTransactionThreadID ( [ payAction , createAction ] , mockDMChatReportID ) ) . toBeUndefined ( ) ;
919+ } ) ;
920+ } ) ;
860921
861922 describe ( 'shouldShowAddMissingDetails' , ( ) => {
862923 it ( 'should return true if personal detail is not completed' , async ( ) => {
0 commit comments