@@ -2846,6 +2846,7 @@ describe('actions/Policy', () => {
28462846 lastUsedPaymentMethods : undefined ,
28472847 localeCompare : TestHelper . localeCompare ,
28482848 currentUserAccountID : ESH_ACCOUNT_ID ,
2849+ accountIDToLogin : { } ,
28492850 } ) ;
28502851
28512852 await waitForBatchedUpdates ( ) ;
@@ -2945,6 +2946,7 @@ describe('actions/Policy', () => {
29452946 lastUsedPaymentMethods : undefined ,
29462947 localeCompare : TestHelper . localeCompare ,
29472948 currentUserAccountID : ESH_ACCOUNT_ID ,
2949+ accountIDToLogin : { } ,
29482950 } ) ;
29492951
29502952 await waitForBatchedUpdates ( ) ;
@@ -3002,6 +3004,7 @@ describe('actions/Policy', () => {
30023004 lastUsedPaymentMethods : undefined ,
30033005 localeCompare : TestHelper . localeCompare ,
30043006 currentUserAccountID : ESH_ACCOUNT_ID ,
3007+ accountIDToLogin : { } ,
30053008 } ) ;
30063009 await waitForBatchedUpdates ( ) ;
30073010
@@ -3040,6 +3043,7 @@ describe('actions/Policy', () => {
30403043 lastUsedPaymentMethods : undefined ,
30413044 localeCompare : TestHelper . localeCompare ,
30423045 currentUserAccountID : ESH_ACCOUNT_ID ,
3046+ accountIDToLogin : { } ,
30433047 } ) ;
30443048 await waitForBatchedUpdates ( ) ;
30453049
@@ -3080,6 +3084,7 @@ describe('actions/Policy', () => {
30803084 lastUsedPaymentMethods : undefined ,
30813085 localeCompare : TestHelper . localeCompare ,
30823086 currentUserAccountID : ESH_ACCOUNT_ID ,
3087+ accountIDToLogin : { } ,
30833088 } ) ;
30843089 await waitForBatchedUpdates ( ) ;
30853090
@@ -3095,6 +3100,129 @@ describe('actions/Policy', () => {
30953100
30963101 expect ( lastAccessedWorkspacePolicyIDAfterDelete ) . toBe ( lastAccessedWorkspacePolicyID ) ;
30973102 } ) ;
3103+
3104+ it ( 'should use accountIDToLogin to resolve owner email in closed report action' , async ( ) => {
3105+ const ownerAccountID = 42 ;
3106+ const ownerLogin = 'owner@example.com' ;
3107+ const fakePolicy = createRandomPolicy ( 0 ) ;
3108+ const fakeReport = {
3109+ ...createRandomReport ( 0 , CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ) ,
3110+ ownerAccountID,
3111+ stateNum : CONST . REPORT . STATE_NUM . OPEN ,
3112+ statusNum : CONST . REPORT . STATUS_NUM . OPEN ,
3113+ policyName : fakePolicy . name ,
3114+ } ;
3115+
3116+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ fakePolicy . id } ` , fakePolicy ) ;
3117+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } ${ fakeReport . reportID } ` , fakeReport ) ;
3118+
3119+ Policy . deleteWorkspace ( {
3120+ policies : { [ `${ ONYXKEYS . COLLECTION . POLICY } ${ fakePolicy . id } ` ] : fakePolicy } ,
3121+ policyID : fakePolicy . id ,
3122+ personalPolicyID : undefined ,
3123+ activePolicyID : undefined ,
3124+ policyName : fakePolicy . name ,
3125+ lastAccessedWorkspacePolicyID : undefined ,
3126+ policyCardFeeds : undefined ,
3127+ reportsToArchive : [ fakeReport ] ,
3128+ transactionViolations : undefined ,
3129+ reimbursementAccountError : undefined ,
3130+ lastUsedPaymentMethods : undefined ,
3131+ localeCompare : TestHelper . localeCompare ,
3132+ currentUserAccountID : ESH_ACCOUNT_ID ,
3133+ accountIDToLogin : { [ ownerAccountID ] : ownerLogin } ,
3134+ } ) ;
3135+
3136+ await waitForBatchedUpdates ( ) ;
3137+
3138+ // Then the closed report action should contain the owner's login from accountIDToLogin
3139+ const reportActions = await getOnyxValue ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ fakeReport . reportID } ` as const ) ;
3140+ const closedAction = Object . values ( reportActions ?? { } ) . find ( ( action ) => action && 'actionName' in action && action . actionName === CONST . REPORT . ACTIONS . TYPE . CLOSED ) ;
3141+ expect ( closedAction ) . toBeDefined ( ) ;
3142+ const message = closedAction && 'message' in closedAction && Array . isArray ( closedAction . message ) ? closedAction . message . at ( 0 ) : undefined ;
3143+ expect ( message ?. text ) . toBe ( ownerLogin ) ;
3144+ } ) ;
3145+
3146+ it ( 'should use fake owner email when ownerAccountID is fake' , async ( ) => {
3147+ const fakePolicy = createRandomPolicy ( 0 ) ;
3148+ const fakeReport = {
3149+ ...createRandomReport ( 0 , CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ) ,
3150+ ownerAccountID : CONST . POLICY . OWNER_ACCOUNT_ID_FAKE ,
3151+ stateNum : CONST . REPORT . STATE_NUM . OPEN ,
3152+ statusNum : CONST . REPORT . STATUS_NUM . OPEN ,
3153+ policyName : fakePolicy . name ,
3154+ } ;
3155+
3156+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ fakePolicy . id } ` , fakePolicy ) ;
3157+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } ${ fakeReport . reportID } ` , fakeReport ) ;
3158+
3159+ Policy . deleteWorkspace ( {
3160+ policies : { [ `${ ONYXKEYS . COLLECTION . POLICY } ${ fakePolicy . id } ` ] : fakePolicy } ,
3161+ policyID : fakePolicy . id ,
3162+ personalPolicyID : undefined ,
3163+ activePolicyID : undefined ,
3164+ policyName : fakePolicy . name ,
3165+ lastAccessedWorkspacePolicyID : undefined ,
3166+ policyCardFeeds : undefined ,
3167+ reportsToArchive : [ fakeReport ] ,
3168+ transactionViolations : undefined ,
3169+ reimbursementAccountError : undefined ,
3170+ lastUsedPaymentMethods : undefined ,
3171+ localeCompare : TestHelper . localeCompare ,
3172+ currentUserAccountID : ESH_ACCOUNT_ID ,
3173+ accountIDToLogin : { } ,
3174+ } ) ;
3175+
3176+ await waitForBatchedUpdates ( ) ;
3177+
3178+ // Then the closed report action should use the fake owner email
3179+ const reportActions = await getOnyxValue ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ fakeReport . reportID } ` as const ) ;
3180+ const closedAction = Object . values ( reportActions ?? { } ) . find ( ( action ) => action && 'actionName' in action && action . actionName === CONST . REPORT . ACTIONS . TYPE . CLOSED ) ;
3181+ expect ( closedAction ) . toBeDefined ( ) ;
3182+ const message = closedAction && 'message' in closedAction && Array . isArray ( closedAction . message ) ? closedAction . message . at ( 0 ) : undefined ;
3183+ expect ( message ?. text ) . toBe ( CONST . POLICY . OWNER_EMAIL_FAKE ) ;
3184+ } ) ;
3185+
3186+ it ( 'should fall back to empty string when accountIDToLogin has no entry for ownerAccountID' , async ( ) => {
3187+ const ownerAccountID = 99 ;
3188+ const fakePolicy = createRandomPolicy ( 0 ) ;
3189+ const fakeReport = {
3190+ ...createRandomReport ( 0 , CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ) ,
3191+ ownerAccountID,
3192+ stateNum : CONST . REPORT . STATE_NUM . OPEN ,
3193+ statusNum : CONST . REPORT . STATUS_NUM . OPEN ,
3194+ policyName : fakePolicy . name ,
3195+ } ;
3196+
3197+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ fakePolicy . id } ` , fakePolicy ) ;
3198+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } ${ fakeReport . reportID } ` , fakeReport ) ;
3199+
3200+ Policy . deleteWorkspace ( {
3201+ policies : { [ `${ ONYXKEYS . COLLECTION . POLICY } ${ fakePolicy . id } ` ] : fakePolicy } ,
3202+ policyID : fakePolicy . id ,
3203+ personalPolicyID : undefined ,
3204+ activePolicyID : undefined ,
3205+ policyName : fakePolicy . name ,
3206+ lastAccessedWorkspacePolicyID : undefined ,
3207+ policyCardFeeds : undefined ,
3208+ reportsToArchive : [ fakeReport ] ,
3209+ transactionViolations : undefined ,
3210+ reimbursementAccountError : undefined ,
3211+ lastUsedPaymentMethods : undefined ,
3212+ localeCompare : TestHelper . localeCompare ,
3213+ currentUserAccountID : ESH_ACCOUNT_ID ,
3214+ accountIDToLogin : { } ,
3215+ } ) ;
3216+
3217+ await waitForBatchedUpdates ( ) ;
3218+
3219+ // Then the closed report action should have an empty string for the email
3220+ const reportActions = await getOnyxValue ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ fakeReport . reportID } ` as const ) ;
3221+ const closedAction = Object . values ( reportActions ?? { } ) . find ( ( action ) => action && 'actionName' in action && action . actionName === CONST . REPORT . ACTIONS . TYPE . CLOSED ) ;
3222+ expect ( closedAction ) . toBeDefined ( ) ;
3223+ const message = closedAction && 'message' in closedAction && Array . isArray ( closedAction . message ) ? closedAction . message . at ( 0 ) : undefined ;
3224+ expect ( message ?. text ) . toBe ( '' ) ;
3225+ } ) ;
30983226 } ) ;
30993227
31003228 describe ( 'leaveWorkspace' , ( ) => {
0 commit comments