Skip to content

Commit 2e7fe03

Browse files
committed
add test
1 parent 09cb556 commit 2e7fe03

1 file changed

Lines changed: 55 additions & 1 deletion

File tree

tests/unit/ReportActionsUtilsTest.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ROUTES from '@src/ROUTES';
1111
import Onyx from 'react-native-onyx';
1212

1313
import type {CompanyAddressOriginalMessage, UpdateACHAccountOriginalMessage} from '../../src/libs/ReportActionsUtils';
14-
import type {Card, DecisionName, PersonalDetailsList, Report, ReportAction, ReportActions} from '../../src/types/onyx';
14+
import type {Card, DecisionName, PersonalDetails, PersonalDetailsList, Report, ReportAction, ReportActions} from '../../src/types/onyx';
1515
import type {OriginalMessageExportIntegration} from '../../src/types/onyx/OriginalMessage';
1616
import type {ReportCollectionDataSet} from '../../src/types/onyx/Report';
1717
import type {ReportActionsCollectionDataSet} from '../../src/types/onyx/ReportAction';
@@ -38,6 +38,7 @@ import {
3838
getIntegrationSyncFailedMessage,
3939
getInvoiceCompanyNameUpdateMessage,
4040
getInvoiceCompanyWebsiteUpdateMessage,
41+
getJoinRequestMessage,
4142
getMccGroupCategoryMessage,
4243
getModerationFlagState,
4344
getOneTransactionThreadReportID,
@@ -2198,6 +2199,59 @@ describe('ReportActionsUtils', () => {
21982199
expect(ReportActionsUtils.getRenamedAction(translateLocal, reportAction, isExpenseReport(report), 'John')).toBe('John renamed to "New name" (previously "Old name")');
21992200
});
22002201
});
2202+
2203+
describe('getJoinRequestMessage', () => {
2204+
const joinRequestAction: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_JOIN_REQUEST> = {
2205+
actionName: CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_JOIN_REQUEST,
2206+
reportActionID: 'join-request-1',
2207+
created: '2024-10-01 10:00:00.000',
2208+
originalMessage: {
2209+
choice: CONST.REPORT.ACTIONABLE_MENTION_JOIN_WORKSPACE_RESOLUTION.ACCEPT,
2210+
policyID: '1',
2211+
accountID: 2,
2212+
email: 'requester@expensify.com',
2213+
},
2214+
};
2215+
2216+
it('should use the display name and login when the requester has a first name', () => {
2217+
const userDetail: PersonalDetails = {
2218+
accountID: 2,
2219+
firstName: 'John',
2220+
displayName: 'John Doe',
2221+
login: 'john.doe@expensify.com',
2222+
};
2223+
2224+
expect(getJoinRequestMessage(translateLocal, 'Expensify', joinRequestAction, userDetail)).toBe('John Doe (john.doe@expensify.com) requested to join Expensify');
2225+
});
2226+
2227+
it('should use only the login when the requester has no first name', () => {
2228+
const userDetail: PersonalDetails = {
2229+
accountID: 2,
2230+
displayName: 'John Doe',
2231+
login: 'john.doe@expensify.com',
2232+
};
2233+
2234+
expect(getJoinRequestMessage(translateLocal, 'Expensify', joinRequestAction, userDetail)).toBe('john.doe@expensify.com requested to join Expensify');
2235+
});
2236+
2237+
it('should fall back to the email from the original message when the personal details are missing', () => {
2238+
expect(getJoinRequestMessage(translateLocal, 'Expensify', joinRequestAction, undefined)).toBe('requester@expensify.com requested to join Expensify');
2239+
});
2240+
2241+
it('should fall back to an empty user when there are neither personal details nor an email', () => {
2242+
const actionWithoutEmail: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_JOIN_REQUEST> = {
2243+
...joinRequestAction,
2244+
originalMessage: {
2245+
choice: CONST.REPORT.ACTIONABLE_MENTION_JOIN_WORKSPACE_RESOLUTION.ACCEPT,
2246+
policyID: '1',
2247+
accountID: 2,
2248+
},
2249+
};
2250+
2251+
expect(getJoinRequestMessage(translateLocal, 'Expensify', actionWithoutEmail, undefined)).toBe(' requested to join Expensify');
2252+
});
2253+
});
2254+
22012255
describe('getCardIssuedMessage', () => {
22022256
const mockVirtualCardIssuedAction: ReportAction = {
22032257
actionName: CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED_VIRTUAL,

0 commit comments

Comments
 (0)