Skip to content

Commit

Permalink
Merge pull request #4 from ishpaul777/fix/ioutest
Browse files Browse the repository at this point in the history
Fix/ioutest
  • Loading branch information
shubham1206agra authored Aug 19, 2024
2 parents 4c41990 + 4d34462 commit 49b79ca
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ function isSystemChat(report: OnyxEntry<Report>): boolean {
return getChatType(report) === CONST.REPORT.CHAT_TYPE.SYSTEM;
}

function getDefaultNotificationPreferenceForReport(report: OnyxEntry<Report>) {
function getDefaultNotificationPreferenceForReport(report: OnyxEntry<Report>): ValueOf<typeof CONST.REPORT.NOTIFICATION_PREFERENCE> {
if (isAnnounceRoom(report)) {
return CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS;
}
Expand All @@ -1172,7 +1172,7 @@ function getDefaultNotificationPreferenceForReport(report: OnyxEntry<Report>) {
/**
* Get the notification preference given a report
*/
function getReportNotificationPreference(report: OnyxEntry<Report>) {
function getReportNotificationPreference(report: OnyxEntry<Report>): ValueOf<typeof CONST.REPORT.NOTIFICATION_PREFERENCE> {
return report?.participants?.[currentUserAccountID ?? -1]?.notificationPreference ?? getDefaultNotificationPreferenceForReport(report);
}

Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3009,8 +3009,8 @@ function clearAddRoomMemberError(reportID: string, invitedAccountID: string) {

function updateGroupChatMemberRoles(reportID: string, accountIDList: number[], role: ValueOf<typeof CONST.REPORT.ROLE>) {
const memberRoles: Record<number, string> = {};
const optimisticParticipants: Record<number, Partial<Participant>> = {};
const successParticipants: Record<number, Partial<Participant>> = {};
const optimisticParticipants: Record<number, Partial<ReportParticipant>> = {};
const successParticipants: Record<number, Partial<ReportParticipant>> = {};

accountIDList.forEach((accountID) => {
memberRoles[accountID] = role;
Expand Down
26 changes: 13 additions & 13 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ describe('actions/IOU', () => {
iouReportID = iouReport?.reportID;
transactionThread = transactionThreadReport;

expect(iouReport?.participants).toBe({
[RORY_ACCOUNT_ID]: {notification: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN},
[CARLOS_ACCOUNT_ID]: {notification: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN},
expect(iouReport?.participants).toEqual({
[RORY_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN},
[CARLOS_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN},
});

// They should be linked together
Expand Down Expand Up @@ -296,9 +296,9 @@ describe('actions/IOU', () => {
const iouReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU);
iouReportID = iouReport?.reportID;

expect(iouReport?.participants).toBe({
[RORY_ACCOUNT_ID]: {notification: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN},
[CARLOS_ACCOUNT_ID]: {notification: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN},
expect(iouReport?.participants).toEqual({
[RORY_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN},
[CARLOS_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN},
});

// They should be linked together
Expand Down Expand Up @@ -644,10 +644,10 @@ describe('actions/IOU', () => {
const iouReport = iouReports[0];
iouReportID = iouReport?.reportID;

expect(chatReport?.participants).toEqual({[RORY_ACCOUNT_ID]: RORY_PARTICIPANT, [CARLOS_ACCOUNT_ID]: CARLOS_PARTICIPANT});
expect(chatReport?.participants).toStrictEqual({[RORY_ACCOUNT_ID]: RORY_PARTICIPANT, [CARLOS_ACCOUNT_ID]: CARLOS_PARTICIPANT});

// They should be linked together
expect(chatReport?.participants).toEqual({[RORY_ACCOUNT_ID]: RORY_PARTICIPANT, [CARLOS_ACCOUNT_ID]: CARLOS_PARTICIPANT});
expect(chatReport?.participants).toStrictEqual({[RORY_ACCOUNT_ID]: RORY_PARTICIPANT, [CARLOS_ACCOUNT_ID]: CARLOS_PARTICIPANT});
expect(chatReport?.iouReportID).toBe(iouReport?.reportID);

resolve();
Expand Down Expand Up @@ -1165,7 +1165,7 @@ describe('actions/IOU', () => {
// The 1:1 chat reports and the IOU reports should be linked together
expect(carlosChatReport?.iouReportID).toBe(carlosIOUReport?.reportID);
expect(carlosIOUReport?.chatReportID).toBe(carlosChatReport?.reportID);
expect(carlosIOUReport?.participants).toBe({[CARLOS_ACCOUNT_ID]: CARLOS_PARTICIPANT});
expect(carlosIOUReport?.participants).toStrictEqual({[CARLOS_ACCOUNT_ID]: CARLOS_PARTICIPANT});

expect(julesChatReport?.iouReportID).toBe(julesIOUReport?.reportID);
expect(julesIOUReport?.chatReportID).toBe(julesChatReport?.reportID);
Expand Down Expand Up @@ -2442,7 +2442,7 @@ describe('actions/IOU', () => {
// Given a transaction thread
thread = ReportUtils.buildTransactionThread(createIOUAction, iouReport);

expect(thread.participants).toBe({[RORY_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, role: CONST.REPORT.ROLE.ADMIN}});
expect(thread.participants).toStrictEqual({[RORY_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, role: CONST.REPORT.ROLE.ADMIN}});

Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`,
Expand Down Expand Up @@ -2631,7 +2631,7 @@ describe('actions/IOU', () => {
// Given a transaction thread
thread = ReportUtils.buildTransactionThread(createIOUAction, iouReport);

expect(thread.participants).toBe({[RORY_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, role: CONST.REPORT.ROLE.ADMIN}});
expect(thread.participants).toEqual({[RORY_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, role: CONST.REPORT.ROLE.ADMIN}});

const participantAccountIDs = Object.keys(thread.participants ?? {}).map(Number);
const userLogins = PersonalDetailsUtils.getLoginsByAccountIDs(participantAccountIDs);
Expand Down Expand Up @@ -2719,7 +2719,7 @@ describe('actions/IOU', () => {
jest.advanceTimersByTime(10);
thread = ReportUtils.buildTransactionThread(createIOUAction, iouReport);

expect(thread.participants).toBe({[RORY_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, role: CONST.REPORT.ROLE.ADMIN}});
expect(thread.participants).toStrictEqual({[RORY_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, role: CONST.REPORT.ROLE.ADMIN}});

Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`,
Expand Down Expand Up @@ -2959,7 +2959,7 @@ describe('actions/IOU', () => {
jest.advanceTimersByTime(10);
thread = ReportUtils.buildTransactionThread(createIOUAction, iouReport);

expect(thread.participants).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);
expect(thread.participants).toStrictEqual({[RORY_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, role: CONST.REPORT.ROLE.ADMIN}});

Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`,
Expand Down
8 changes: 6 additions & 2 deletions tests/actions/PolicyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

const ESH_EMAIL = 'eshgupta1217@gmail.com';
const ESH_ACCOUNT_ID = 1;
const ESH_PARTICIPANT: Participant = {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.DAILY, role: 'admin'};
const ESH_PARTICIPANT_ANNOUNCE_ROOM: Participant = {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.DAILY, role: 'admin'};
const ESH_PARTICIPANT_ADMINS_ROOM: Participant = {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, role: 'admin'};
const ESH_PARTICIPANT_EXPENSE_CHAT = {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, role: 'admin'}
const WORKSPACE_NAME = "Esh's Workspace";

OnyxUpdateManager();
Expand Down Expand Up @@ -78,17 +80,19 @@ describe('actions/Policy', () => {
expect(workspaceReports.length).toBe(3);
workspaceReports.forEach((report) => {
expect(report?.pendingFields?.addWorkspaceRoom).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
expect(report?.participants).toEqual({[ESH_ACCOUNT_ID]: ESH_PARTICIPANT});
switch (report?.chatType) {
case CONST.REPORT.CHAT_TYPE.POLICY_ADMINS: {
expect(report?.participants).toEqual({ [ESH_ACCOUNT_ID]: ESH_PARTICIPANT_ADMINS_ROOM });
adminReportID = report.reportID;
break;
}
case CONST.REPORT.CHAT_TYPE.POLICY_ANNOUNCE: {
expect(report?.participants).toEqual({ [ESH_ACCOUNT_ID]: ESH_PARTICIPANT_ANNOUNCE_ROOM });
announceReportID = report.reportID;
break;
}
case CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT: {
expect(report?.participants).toEqual({ [ESH_ACCOUNT_ID]: ESH_PARTICIPANT_EXPENSE_CHAT });
expenseReportID = report.reportID;
break;
}
Expand Down

0 comments on commit 49b79ca

Please sign in to comment.