@@ -18,6 +18,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
1818import type { PersonalDetailsList , Policy , PolicyTagLists , Report , ReportAction , ReportActions , ReportAttributesDerivedValue , ReportNameValuePairs , Transaction } from '@src/types/onyx' ;
1919import createRandomPolicy from '../utils/collections/policies' ;
2020import { createAdminRoom , createExpenseReport , createPolicyExpenseChat , createRegularChat , createRegularTaskReport , createSelfDM , createWorkspaceThread } from '../utils/collections/reports' ;
21+ import createRandomTransaction from '../utils/collections/transaction' ;
2122import { fakePersonalDetails } from '../utils/LHNTestUtils' ;
2223import { formatPhoneNumber } from '../utils/TestHelper' ;
2324import waitForBatchedUpdates from '../utils/waitForBatchedUpdates' ;
@@ -549,6 +550,7 @@ describe('ReportNameUtils', () => {
549550 report : thread ,
550551 reports : emptyCollections . reports ,
551552 policies : emptyCollections . policies ,
553+ transactions : { } ,
552554 personalDetailsList : participantsPersonalDetails ,
553555 reportActions : reportActionsCollection ,
554556 currentUserAccountID,
@@ -1288,4 +1290,132 @@ describe('ReportNameUtils', () => {
12881290 expect ( reportName ) . not . toBe ( '' ) ;
12891291 } ) ;
12901292 } ) ;
1293+
1294+ describe ( 'computeReportName - Transaction thread with linkedTransaction' , ( ) => {
1295+ test ( 'returns formatted expense name for transaction thread' , ( ) => {
1296+ const transactionID = '999' ;
1297+ const parentReportID = '100' ;
1298+ const parentReportActionID = '200' ;
1299+ const expenseReportID = '300' ;
1300+
1301+ const thread : Report = {
1302+ ...createWorkspaceThread ( 60 ) ,
1303+ parentReportID,
1304+ parentReportActionID,
1305+ } ;
1306+
1307+ const parentAction : ReportAction = {
1308+ actionName : CONST . REPORT . ACTIONS . TYPE . IOU ,
1309+ reportActionID : parentReportActionID ,
1310+ message : [ { type : 'TEXT' , text : 'test' } ] ,
1311+ created : '2024-01-01 00:00:00' ,
1312+ lastModified : '' ,
1313+ actorAccountID : 1 ,
1314+ person : [ ] ,
1315+ originalMessage : {
1316+ type : CONST . IOU . REPORT_ACTION_TYPE . CREATE ,
1317+ IOUTransactionID : transactionID ,
1318+ IOUReportID : expenseReportID ,
1319+ amount : 2500 ,
1320+ currency : CONST . CURRENCY . USD ,
1321+ participantAccountIDs : [ 1 , 2 ] ,
1322+ } ,
1323+ } as ReportAction ;
1324+
1325+ const transaction : Transaction = {
1326+ ...createRandomTransaction ( 1 ) ,
1327+ transactionID,
1328+ reportID : expenseReportID ,
1329+ merchant : 'Coffee Shop' ,
1330+ modifiedMerchant : '' ,
1331+ amount : - 2500 ,
1332+ currency : CONST . CURRENCY . USD ,
1333+ comment : { comment : '' } ,
1334+ } ;
1335+
1336+ const reportActionsCollection : Record < string , ReportActions > = {
1337+ [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ parentReportID } ` ] : {
1338+ [ parentReportActionID ] : parentAction ,
1339+ } ,
1340+ } ;
1341+
1342+ const transactionsCollection : Record < string , Transaction > = {
1343+ [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionID } ` ] : transaction ,
1344+ } ;
1345+
1346+ const expenseReport : Report = {
1347+ ...createExpenseReport ( 300 ) ,
1348+ reportID : expenseReportID ,
1349+ type : CONST . REPORT . TYPE . EXPENSE ,
1350+ } ;
1351+
1352+ const reportsCollection : Record < string , Report > = {
1353+ [ `${ ONYXKEYS . COLLECTION . REPORT } ${ parentReportID } ` ] : createRegularChat ( 100 , [ 1 , 2 ] ) ,
1354+ [ `${ ONYXKEYS . COLLECTION . REPORT } ${ expenseReportID } ` ] : expenseReport ,
1355+ } ;
1356+
1357+ const name = computeReportName (
1358+ thread ,
1359+ reportsCollection ,
1360+ emptyCollections . policies ,
1361+ transactionsCollection ,
1362+ undefined ,
1363+ participantsPersonalDetails ,
1364+ reportActionsCollection ,
1365+ currentUserAccountID ,
1366+ ) ;
1367+
1368+ expect ( name ) . toContain ( '$25.00' ) ;
1369+ expect ( name ) . toContain ( 'Coffee Shop' ) ;
1370+ } ) ;
1371+
1372+ test ( 'returns expense fallback when transaction is not in collection' , ( ) => {
1373+ const transactionID = '888' ;
1374+ const parentReportID = '101' ;
1375+ const parentReportActionID = '201' ;
1376+
1377+ const thread : Report = {
1378+ ...createWorkspaceThread ( 61 ) ,
1379+ parentReportID,
1380+ parentReportActionID,
1381+ } ;
1382+
1383+ const parentAction : ReportAction = {
1384+ actionName : CONST . REPORT . ACTIONS . TYPE . IOU ,
1385+ reportActionID : parentReportActionID ,
1386+ message : [ { type : 'TEXT' , text : 'test' } ] ,
1387+ created : '2024-01-01 00:00:00' ,
1388+ lastModified : '' ,
1389+ actorAccountID : 1 ,
1390+ person : [ ] ,
1391+ originalMessage : {
1392+ type : CONST . IOU . REPORT_ACTION_TYPE . CREATE ,
1393+ IOUTransactionID : transactionID ,
1394+ IOUReportID : '301' ,
1395+ amount : 1000 ,
1396+ currency : CONST . CURRENCY . USD ,
1397+ participantAccountIDs : [ 1 , 2 ] ,
1398+ } ,
1399+ } as ReportAction ;
1400+
1401+ const reportActionsCollection : Record < string , ReportActions > = {
1402+ [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ parentReportID } ` ] : {
1403+ [ parentReportActionID ] : parentAction ,
1404+ } ,
1405+ } ;
1406+
1407+ const name = computeReportName (
1408+ thread ,
1409+ emptyCollections . reports ,
1410+ emptyCollections . policies ,
1411+ { } ,
1412+ undefined ,
1413+ participantsPersonalDetails ,
1414+ reportActionsCollection ,
1415+ currentUserAccountID ,
1416+ ) ;
1417+
1418+ expect ( name ) . toBe ( translate ( CONST . LOCALES . EN , 'iou.expense' ) ) ;
1419+ } ) ;
1420+ } ) ;
12911421} ) ;
0 commit comments