Skip to content
Merged
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
28 changes: 22 additions & 6 deletions src/libs/actions/Policy/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,13 @@ function removeMembers(accountIDs: number[], policyID: string) {
pendingChatMembers,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`,
value: {
private_isArchived: true,
},
},
);
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -458,13 +465,22 @@ function removeMembers(accountIDs: number[], policyID: string) {
pendingChatMembers: null,
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID}`,
value: {
pendingChatMembers: null,
failureData.push(
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID}`,
value: {
pendingChatMembers: null,
},
},
});
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`,
value: {
private_isArchived: false,
},
},
);
});
// comment out for time this issue would be resolved https://github.com/Expensify/App/issues/35952
// optimisticClosedReportActions.forEach((reportAction, index) => {
Expand Down
7 changes: 7 additions & 0 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,13 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: I
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
},
});
workspaceMembersChats.onyxOptimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${oldChat.reportID}`,
value: {
private_isArchived: false,
},
});
return;
}
const optimisticReport = ReportUtils.buildOptimisticChatReport([sessionAccountID, cleanAccountID], undefined, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, policyID, cleanAccountID);
Expand Down
68 changes: 68 additions & 0 deletions tests/actions/PolicyMemberTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Onyx from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import DateUtils from '@libs/DateUtils';
import CONST from '@src/CONST';
import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager';
import * as Member from '@src/libs/actions/Policy/Member';
Expand Down Expand Up @@ -355,6 +356,41 @@ describe('actions/PolicyMember', () => {
expect(adminRoom?.participants?.[auditorAccountID]).toBeTruthy();
expect(adminRoom?.participants?.[userAccountID]).toBeUndefined();
});

it('should unarchive existing workspace chat when adding back a member', async () => {
// Given an archived workspace chat
const policyID = '1';
const workspaceReportID = '1';
const userAccountID = 1236;
const userEmail = 'user@example.com';

await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${workspaceReportID}`, {
...createRandomReport(Number(workspaceReportID)),
policyID,
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
ownerAccountID: userAccountID,
});
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${workspaceReportID}`, {
private_isArchived: DateUtils.getDBTime(),
});

// When adding the user to the workspace
Member.addMembersToWorkspace({[userEmail]: userAccountID}, 'Welcome', policyID, [], CONST.POLICY.ROLE.USER);

await waitForBatchedUpdates();

// Then the member workspace chat should be unarchived optimistically
const isArchived = await new Promise<boolean>((resolve) => {
const connection = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${workspaceReportID}`,
callback: (nvp) => {
Onyx.disconnect(connection);
resolve(!!nvp?.private_isArchived);
},
});
});
expect(isArchived).toBe(false);
});
});

describe('removeMembers', () => {
Expand Down Expand Up @@ -435,5 +471,37 @@ describe('actions/PolicyMember', () => {
});
expect(successAdminRoomMetadata?.pendingChatMembers).toBeUndefined();
});

it('should archive the member workspace chat', async () => {
// Given a workspace chat
const policyID = '1';
const workspaceReportID = '1';
const userAccountID = 1236;

await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${workspaceReportID}`, {
...createRandomReport(Number(workspaceReportID)),
policyID,
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
ownerAccountID: userAccountID,
});

// When removing a member from the workspace
mockFetch?.pause?.();
Member.removeMembers([userAccountID], policyID);

await waitForBatchedUpdates();

// Then the member workspace chat should be archived optimistically
const isArchived = await new Promise<boolean>((resolve) => {
const connection = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${workspaceReportID}`,
callback: (nvp) => {
Onyx.disconnect(connection);
resolve(!!nvp?.private_isArchived);
},
});
});
expect(isArchived).toBe(true);
});
});
});