@@ -36,6 +36,7 @@ import {
3636 buildOptimisticCancelPaymentReportAction,
3737 buildOptimisticCardAssignedReportAction,
3838 buildOptimisticChatReport,
39+ buildOptimisticClosedReportAction,
3940 buildOptimisticCreatedReportAction,
4041 buildOptimisticCreatedReportForUnapprovedAction,
4142 buildOptimisticEmptyReport,
@@ -15188,4 +15189,70 @@ describe('ReportUtils', () => {
1518815189 expect(action.reportActionID).toBeTruthy();
1518915190 });
1519015191 });
15192+
15193+ describe('buildOptimisticClosedReportAction', () => {
15194+ it('should set actorAccountID to the provided currentUserAccountID', () => {
15195+ const customAccountID = 99;
15196+ const action = buildOptimisticClosedReportAction('user@example.com', 'Test Policy', customAccountID);
15197+
15198+ expect(action.actorAccountID).toBe(customAccountID);
15199+ });
15200+
15201+ it('should set actionName to CLOSED', () => {
15202+ const action = buildOptimisticClosedReportAction('user@example.com', 'Test Policy', currentUserAccountID);
15203+
15204+ expect(action.actionName).toBe(CONST.REPORT.ACTIONS.TYPE.CLOSED);
15205+ });
15206+
15207+ it('should set originalMessage with the provided policyName and default reason', () => {
15208+ const policyName = 'My Workspace';
15209+ const action = buildOptimisticClosedReportAction('user@example.com', policyName, currentUserAccountID);
15210+
15211+ expect(getOriginalMessage(action as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.CLOSED>)).toMatchObject({
15212+ policyName,
15213+ reason: CONST.REPORT.ARCHIVE_REASON.DEFAULT,
15214+ });
15215+ });
15216+
15217+ it('should set originalMessage with the provided reason when specified', () => {
15218+ const policyName = 'My Workspace';
15219+ const reason = CONST.REPORT.ARCHIVE_REASON.POLICY_DELETED;
15220+ const action = buildOptimisticClosedReportAction('user@example.com', policyName, currentUserAccountID, reason);
15221+
15222+ expect(getOriginalMessage(action as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.CLOSED>)).toMatchObject({
15223+ policyName,
15224+ reason,
15225+ });
15226+ });
15227+
15228+ it('should set message with the emailClosingReport as the first text', () => {
15229+ const emailClosingReport = 'admin@company.com';
15230+ const action = buildOptimisticClosedReportAction(emailClosingReport, 'Test Policy', currentUserAccountID);
15231+ const messages = action.message as Array<{type: string; style: string; text: string}>;
15232+
15233+ expect(messages.at(0)).toMatchObject({
15234+ type: CONST.REPORT.MESSAGE.TYPE.TEXT,
15235+ style: 'strong',
15236+ text: emailClosingReport,
15237+ });
15238+ });
15239+
15240+ it('should set pendingAction to ADD', () => {
15241+ const action = buildOptimisticClosedReportAction('user@example.com', 'Test Policy', currentUserAccountID);
15242+
15243+ expect(action.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
15244+ });
15245+
15246+ it('should set shouldShow to true', () => {
15247+ const action = buildOptimisticClosedReportAction('user@example.com', 'Test Policy', currentUserAccountID);
15248+
15249+ expect(action.shouldShow).toBe(true);
15250+ });
15251+
15252+ it('should generate a non-empty reportActionID', () => {
15253+ const action = buildOptimisticClosedReportAction('user@example.com', 'Test Policy', currentUserAccountID);
15254+
15255+ expect(action.reportActionID).toBeTruthy();
15256+ });
15257+ });
1519115258});
0 commit comments