Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix new member added while offline doesn't show in approval flow list #54105

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion src/libs/actions/Policy/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import enhanceParameters from '@libs/Network/enhanceParameters';
import Parser from '@libs/Parser';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import * as PhoneNumber from '@libs/PhoneNumber';
import {getDefaultApprover} from '@libs/PolicyUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -627,7 +628,12 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: InvitedEmailsToAccount
const successMembersState: OnyxCollectionInputValue<PolicyEmployee> = {};
const failureMembersState: OnyxCollectionInputValue<PolicyEmployee> = {};
logins.forEach((email) => {
optimisticMembersState[email] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, role: CONST.POLICY.ROLE.USER};
optimisticMembersState[email] = {
email,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
role: CONST.POLICY.ROLE.USER,
submitsTo: getDefaultApprover(allPolicies?.[policyKey]),
};
successMembersState[email] = {pendingAction: null};
failureMembersState[email] = {
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.people.error.genericAdd'),
Expand Down
36 changes: 36 additions & 0 deletions tests/actions/PolicyMemberTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,40 @@ describe('actions/PolicyMember', () => {
});
});
});

describe('addMembersToWorkspace', () => {
it('Add new member to a workspace', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('Add new member to a workspace', async () => {
it('Add a new member to a workspace whilst offline', async () => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add the offline word because optimistic data is not specific to offline test

const policyID = '1';
const defaultApprover = '[email protected]';
const newUserEmail = '[email protected]';

await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {
...createRandomPolicy(Number(policyID)),
approver: defaultApprover,
});

mockFetch?.pause?.();
Member.addMembersToWorkspace({[newUserEmail]: 1234}, 'Welcome', policyID, []);

await waitForBatchedUpdates();

await new Promise<void>((resolve) => {
const connection = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
waitForCollectionCallback: false,
callback: (policy) => {
Onyx.disconnect(connection);
const newEmployee = policy?.employeeList?.[newUserEmail];
expect(newEmployee).not.toBeUndefined();
expect(newEmployee?.email).toBe(newUserEmail);
expect(newEmployee?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
expect(newEmployee?.role).toBe(CONST.POLICY.ROLE.USER);
expect(newEmployee?.submitsTo).toBe(defaultApprover);
resolve();
},
});
});
await mockFetch?.resume?.();
});
});
});
Loading