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
5 changes: 4 additions & 1 deletion src/libs/actions/Policy/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,10 @@ function removeMembers(policyID: string, selectedMemberEmails: string[], policyM
selectedMemberEmails.forEach((email) => {
optimisticMembersState[email] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE};
successMembersState[email] = null;
failureMembersState[email] = {errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.people.error.genericRemove')};
failureMembersState[email] = {
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.people.error.genericRemove'),
};
});

Object.keys(policy?.employeeList ?? {}).forEach((employeeEmail) => {
Expand Down
46 changes: 46 additions & 0 deletions tests/actions/PolicyMemberTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,52 @@ describe('actions/PolicyMember', () => {
expect(isWorkspaceChatArchived && isExpenseReportArchived).toBe(true);
await mockFetch?.resume?.();
});

it('should preserve pendingAction DELETE when member removal fails', async () => {
// Given a workspace with a member
const policyID = 'ABCD12345';
const userAccountID = 1236;
const userEmail = 'user@example.com';
const ownerEmail = 'owner@gmail.com';

await Onyx.set(`${ONYXKEYS.PERSONAL_DETAILS_LIST}`, {
[userAccountID]: {login: userEmail},
});
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {
...createRandomPolicy(Number(policyID)),
owner: ownerEmail,
employeeList: {
[ownerEmail]: {role: CONST.POLICY.ROLE.ADMIN},
[userEmail]: {role: CONST.POLICY.ROLE.USER},
},
});

// When removing a member and the request fails
mockFetch?.fail?.();
Member.removeMembers(policyID, [userEmail], {[userEmail]: userAccountID});

await waitForBatchedUpdates();

// Then the member should have pendingAction DELETE and errors
const policy = await new Promise<OnyxEntry<PolicyType>>((resolve, reject) => {
const connection = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
callback: (policyData) => {
Onyx.disconnect(connection);
if (policyData) {
resolve(policyData);
} else {
reject(new Error('Policy not found'));
}
},
});
});

const failedMember = policy?.employeeList?.[userEmail];
expect(failedMember?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);
expect(failedMember?.errors).toBeTruthy();
expect(Object.keys(failedMember?.errors ?? {}).length).toBeGreaterThan(0);
});
});

describe('importPolicyMembers', () => {
Expand Down