Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,10 @@ function getDefaultNotificationPreferenceForReport(report: OnyxEntry<Report>): V
*/
function getReportNotificationPreference(report: OnyxEntry<Report>): ValueOf<typeof CONST.REPORT.NOTIFICATION_PREFERENCE> {
const participant = currentUserAccountID ? report?.participants?.[currentUserAccountID] : undefined;
return participant?.notificationPreference ?? CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;

// Empty notification preference should return `hidden`
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return participant?.notificationPreference || CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
}

/**
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
getReportActionActorAccountID,
getReportIDFromLink,
getReportName as getReportNameDeprecated,
getReportNotificationPreference,
getReportOrDraftReport,
getReportPreviewMessage,
getReportStatusTranslation,
Expand Down Expand Up @@ -136,7 +137,7 @@ import type {
import type {ErrorFields, Errors, OnyxValueWithOfflineFeedback} from '@src/types/onyx/OnyxCommon';
import type {JoinWorkspaceResolution} from '@src/types/onyx/OriginalMessage';
import type {ACHAccount, PolicyReportField} from '@src/types/onyx/Policy';
import type {Participant, Participants} from '@src/types/onyx/Report';
import type {NotificationPreference, Participant, Participants} from '@src/types/onyx/Report';
import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet';
import {actionR14932 as mockIOUAction} from '../../__mocks__/reportData/actions';
import {chatReportR14932 as mockedChatReport, iouReportR14932 as mockIOUReport} from '../../__mocks__/reportData/reports';
Expand Down Expand Up @@ -10731,4 +10732,16 @@ describe('ReportUtils', () => {
await Onyx.clear();
});
});

describe('getReportNotificationPreference', () => {
it('should return hidden if notification preference is empty', () => {
const report: Report = {
...LHNTestUtils.getFakeReport([currentUserAccountID]),
participants: {
[currentUserAccountID]: {notificationPreference: '' as NotificationPreference},
},
};
expect(getReportNotificationPreference(report)).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);
});
});
});
Loading