@@ -2756,6 +2756,7 @@ describe('actions/Policy', () => {
27562756 lastUsedPaymentMethods : undefined ,
27572757 localeCompare : TestHelper . localeCompare ,
27582758 currentUserAccountID : ESH_ACCOUNT_ID ,
2759+ accountIDToLogin : { } ,
27592760 } ) ;
27602761
27612762 await waitForBatchedUpdates ( ) ;
@@ -2855,6 +2856,7 @@ describe('actions/Policy', () => {
28552856 lastUsedPaymentMethods : undefined ,
28562857 localeCompare : TestHelper . localeCompare ,
28572858 currentUserAccountID : ESH_ACCOUNT_ID ,
2859+ accountIDToLogin : { } ,
28582860 } ) ;
28592861
28602862 await waitForBatchedUpdates ( ) ;
@@ -2912,6 +2914,7 @@ describe('actions/Policy', () => {
29122914 lastUsedPaymentMethods : undefined ,
29132915 localeCompare : TestHelper . localeCompare ,
29142916 currentUserAccountID : ESH_ACCOUNT_ID ,
2917+ accountIDToLogin : { } ,
29152918 } ) ;
29162919 await waitForBatchedUpdates ( ) ;
29172920
@@ -2950,6 +2953,7 @@ describe('actions/Policy', () => {
29502953 lastUsedPaymentMethods : undefined ,
29512954 localeCompare : TestHelper . localeCompare ,
29522955 currentUserAccountID : ESH_ACCOUNT_ID ,
2956+ accountIDToLogin : { } ,
29532957 } ) ;
29542958 await waitForBatchedUpdates ( ) ;
29552959
@@ -2990,6 +2994,7 @@ describe('actions/Policy', () => {
29902994 lastUsedPaymentMethods : undefined ,
29912995 localeCompare : TestHelper . localeCompare ,
29922996 currentUserAccountID : ESH_ACCOUNT_ID ,
2997+ accountIDToLogin : { } ,
29932998 } ) ;
29942999 await waitForBatchedUpdates ( ) ;
29953000
@@ -3005,6 +3010,129 @@ describe('actions/Policy', () => {
30053010
30063011 expect ( lastAccessedWorkspacePolicyIDAfterDelete ) . toBe ( lastAccessedWorkspacePolicyID ) ;
30073012 } ) ;
3013+
3014+ it ( 'should use accountIDToLogin to resolve owner email in closed report action' , async ( ) => {
3015+ const ownerAccountID = 42 ;
3016+ const ownerLogin = 'owner@example.com' ;
3017+ const fakePolicy = createRandomPolicy ( 0 ) ;
3018+ const fakeReport = {
3019+ ...createRandomReport ( 0 , CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ) ,
3020+ ownerAccountID,
3021+ stateNum : CONST . REPORT . STATE_NUM . OPEN ,
3022+ statusNum : CONST . REPORT . STATUS_NUM . OPEN ,
3023+ policyName : fakePolicy . name ,
3024+ } ;
3025+
3026+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ fakePolicy . id } ` , fakePolicy ) ;
3027+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } ${ fakeReport . reportID } ` , fakeReport ) ;
3028+
3029+ Policy . deleteWorkspace ( {
3030+ policies : { [ `${ ONYXKEYS . COLLECTION . POLICY } ${ fakePolicy . id } ` ] : fakePolicy } ,
3031+ policyID : fakePolicy . id ,
3032+ personalPolicyID : undefined ,
3033+ activePolicyID : undefined ,
3034+ policyName : fakePolicy . name ,
3035+ lastAccessedWorkspacePolicyID : undefined ,
3036+ policyCardFeeds : undefined ,
3037+ reportsToArchive : [ fakeReport ] ,
3038+ transactionViolations : undefined ,
3039+ reimbursementAccountError : undefined ,
3040+ lastUsedPaymentMethods : undefined ,
3041+ localeCompare : TestHelper . localeCompare ,
3042+ currentUserAccountID : ESH_ACCOUNT_ID ,
3043+ accountIDToLogin : { [ ownerAccountID ] : ownerLogin } ,
3044+ } ) ;
3045+
3046+ await waitForBatchedUpdates ( ) ;
3047+
3048+ // Then the closed report action should contain the owner's login from accountIDToLogin
3049+ const reportActions = await getOnyxValue ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ fakeReport . reportID } ` as const ) ;
3050+ const closedAction = Object . values ( reportActions ?? { } ) . find ( ( action ) => action && 'actionName' in action && action . actionName === CONST . REPORT . ACTIONS . TYPE . CLOSED ) ;
3051+ expect ( closedAction ) . toBeDefined ( ) ;
3052+ const message = closedAction && 'message' in closedAction && Array . isArray ( closedAction . message ) ? closedAction . message . at ( 0 ) : undefined ;
3053+ expect ( message ?. text ) . toBe ( ownerLogin ) ;
3054+ } ) ;
3055+
3056+ it ( 'should use fake owner email when ownerAccountID is fake' , async ( ) => {
3057+ const fakePolicy = createRandomPolicy ( 0 ) ;
3058+ const fakeReport = {
3059+ ...createRandomReport ( 0 , CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ) ,
3060+ ownerAccountID : CONST . POLICY . OWNER_ACCOUNT_ID_FAKE ,
3061+ stateNum : CONST . REPORT . STATE_NUM . OPEN ,
3062+ statusNum : CONST . REPORT . STATUS_NUM . OPEN ,
3063+ policyName : fakePolicy . name ,
3064+ } ;
3065+
3066+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ fakePolicy . id } ` , fakePolicy ) ;
3067+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } ${ fakeReport . reportID } ` , fakeReport ) ;
3068+
3069+ Policy . deleteWorkspace ( {
3070+ policies : { [ `${ ONYXKEYS . COLLECTION . POLICY } ${ fakePolicy . id } ` ] : fakePolicy } ,
3071+ policyID : fakePolicy . id ,
3072+ personalPolicyID : undefined ,
3073+ activePolicyID : undefined ,
3074+ policyName : fakePolicy . name ,
3075+ lastAccessedWorkspacePolicyID : undefined ,
3076+ policyCardFeeds : undefined ,
3077+ reportsToArchive : [ fakeReport ] ,
3078+ transactionViolations : undefined ,
3079+ reimbursementAccountError : undefined ,
3080+ lastUsedPaymentMethods : undefined ,
3081+ localeCompare : TestHelper . localeCompare ,
3082+ currentUserAccountID : ESH_ACCOUNT_ID ,
3083+ accountIDToLogin : { } ,
3084+ } ) ;
3085+
3086+ await waitForBatchedUpdates ( ) ;
3087+
3088+ // Then the closed report action should use the fake owner email
3089+ const reportActions = await getOnyxValue ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ fakeReport . reportID } ` as const ) ;
3090+ const closedAction = Object . values ( reportActions ?? { } ) . find ( ( action ) => action && 'actionName' in action && action . actionName === CONST . REPORT . ACTIONS . TYPE . CLOSED ) ;
3091+ expect ( closedAction ) . toBeDefined ( ) ;
3092+ const message = closedAction && 'message' in closedAction && Array . isArray ( closedAction . message ) ? closedAction . message . at ( 0 ) : undefined ;
3093+ expect ( message ?. text ) . toBe ( CONST . POLICY . OWNER_EMAIL_FAKE ) ;
3094+ } ) ;
3095+
3096+ it ( 'should fall back to empty string when accountIDToLogin has no entry for ownerAccountID' , async ( ) => {
3097+ const ownerAccountID = 99 ;
3098+ const fakePolicy = createRandomPolicy ( 0 ) ;
3099+ const fakeReport = {
3100+ ...createRandomReport ( 0 , CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ) ,
3101+ ownerAccountID,
3102+ stateNum : CONST . REPORT . STATE_NUM . OPEN ,
3103+ statusNum : CONST . REPORT . STATUS_NUM . OPEN ,
3104+ policyName : fakePolicy . name ,
3105+ } ;
3106+
3107+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ fakePolicy . id } ` , fakePolicy ) ;
3108+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } ${ fakeReport . reportID } ` , fakeReport ) ;
3109+
3110+ Policy . deleteWorkspace ( {
3111+ policies : { [ `${ ONYXKEYS . COLLECTION . POLICY } ${ fakePolicy . id } ` ] : fakePolicy } ,
3112+ policyID : fakePolicy . id ,
3113+ personalPolicyID : undefined ,
3114+ activePolicyID : undefined ,
3115+ policyName : fakePolicy . name ,
3116+ lastAccessedWorkspacePolicyID : undefined ,
3117+ policyCardFeeds : undefined ,
3118+ reportsToArchive : [ fakeReport ] ,
3119+ transactionViolations : undefined ,
3120+ reimbursementAccountError : undefined ,
3121+ lastUsedPaymentMethods : undefined ,
3122+ localeCompare : TestHelper . localeCompare ,
3123+ currentUserAccountID : ESH_ACCOUNT_ID ,
3124+ accountIDToLogin : { } ,
3125+ } ) ;
3126+
3127+ await waitForBatchedUpdates ( ) ;
3128+
3129+ // Then the closed report action should have an empty string for the email
3130+ const reportActions = await getOnyxValue ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ fakeReport . reportID } ` as const ) ;
3131+ const closedAction = Object . values ( reportActions ?? { } ) . find ( ( action ) => action && 'actionName' in action && action . actionName === CONST . REPORT . ACTIONS . TYPE . CLOSED ) ;
3132+ expect ( closedAction ) . toBeDefined ( ) ;
3133+ const message = closedAction && 'message' in closedAction && Array . isArray ( closedAction . message ) ? closedAction . message . at ( 0 ) : undefined ;
3134+ expect ( message ?. text ) . toBe ( '' ) ;
3135+ } ) ;
30083136 } ) ;
30093137
30103138 describe ( 'leaveWorkspace' , ( ) => {
0 commit comments