Skip to content

Commit 1d2dda7

Browse files
authored
Merge pull request Expensify#59582 from callstack-internal/fix/59047-workflows-is-turned-off
fix: workflows enabled by default for old accounts
2 parents c618014 + d2e9506 commit 1d2dda7

2 files changed

Lines changed: 89 additions & 21 deletions

File tree

src/libs/actions/Policy/Policy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,7 @@ function buildPolicyData(
20862086
companySize,
20872087
};
20882088

2089-
if (!introSelected?.createWorkspace && engagementChoice && shouldAddOnboardingTasks) {
2089+
if (introSelected !== undefined && !introSelected?.createWorkspace && engagementChoice && shouldAddOnboardingTasks) {
20902090
const onboardingData = prepareOnboardingOnyxData(introSelected, engagementChoice, CONST.ONBOARDING_MESSAGES[engagementChoice], adminsChatReportID, policyID);
20912091
if (!onboardingData) {
20922092
return {successData, optimisticData, failureData, params};

tests/actions/PolicyTest.ts

Lines changed: 88 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ describe('actions/Policy', () => {
3939
});
4040

4141
describe('createWorkspace', () => {
42+
afterEach(() => {
43+
mockFetch?.resume?.();
44+
});
45+
4246
it('creates a new workspace', async () => {
4347
(fetch as MockFetch)?.pause?.();
44-
Onyx.set(ONYXKEYS.SESSION, {email: ESH_EMAIL, accountID: ESH_ACCOUNT_ID});
48+
await Onyx.set(ONYXKEYS.SESSION, {email: ESH_EMAIL, accountID: ESH_ACCOUNT_ID});
4549
const fakePolicy = createRandomPolicy(0, CONST.POLICY.TYPE.PERSONAL);
46-
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
47-
Onyx.set(`${ONYXKEYS.NVP_ACTIVE_POLICY_ID}`, fakePolicy.id);
50+
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
51+
await Onyx.set(`${ONYXKEYS.NVP_ACTIVE_POLICY_ID}`, fakePolicy.id);
52+
await Onyx.set(`${ONYXKEYS.NVP_INTRO_SELECTED}`, {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM});
4853
await waitForBatchedUpdates();
4954

5055
let adminReportID;
@@ -137,7 +142,7 @@ describe('actions/Policy', () => {
137142
});
138143
});
139144

140-
// Each of the three reports should have a a `CREATED` action.
145+
// Each of the three reports should have a `CREATED` action.
141146
let adminReportActions: ReportAction[] = Object.values(reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminReportID}`] ?? {});
142147
let expenseReportActions: ReportAction[] = Object.values(reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReportID}`] ?? {});
143148
let workspaceReportActions: ReportAction[] = adminReportActions.concat(expenseReportActions);
@@ -147,30 +152,36 @@ describe('actions/Policy', () => {
147152
expect(reportAction.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
148153
expect(reportAction.actorAccountID).toBe(ESH_ACCOUNT_ID);
149154
});
150-
// Created Report Action, MANAGE_TEAM tasks (minus tasks that requires integrations to be enabled) and signoff message
151-
const manageTeamDefaultTaskCount = CONST.ONBOARDING_MESSAGES[CONST.ONBOARDING_CHOICES.MANAGE_TEAM].tasks.length - 2;
152-
expect(adminReportActions.length).toBe(2 + manageTeamDefaultTaskCount);
153-
let createdTaskReportActions = 0;
154-
let signingOffMessage = 0;
155-
let taskReportActions = 0;
155+
156+
// Following tasks are filtered in prepareOnboardingOnyxData: 'viewTour', 'addAccountingIntegration' and 'setupCategoriesAndTags' (-3)
157+
const expectedManageTeamDefaultTasksCount = CONST.ONBOARDING_MESSAGES[CONST.ONBOARDING_CHOICES.MANAGE_TEAM].tasks.length - 3;
158+
159+
// After filtering, two actions are added to the list =- signoff message (+1) and default create action (+1)
160+
const expectedReportActionsOfTypeCreatedCount = 1;
161+
const expectedSignOffMessagesCount = 1;
162+
expect(adminReportActions.length).toBe(expectedManageTeamDefaultTasksCount + expectedReportActionsOfTypeCreatedCount + expectedSignOffMessagesCount);
163+
164+
let reportActionsOfTypeCreatedCount = 0;
165+
let signOffMessagesCount = 0;
166+
let manageTeamTasksCount = 0;
156167
adminReportActions.forEach((reportAction) => {
157168
if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) {
158-
createdTaskReportActions++;
169+
reportActionsOfTypeCreatedCount++;
159170
expect(reportAction.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
160171
expect(reportAction.actorAccountID).toBe(ESH_ACCOUNT_ID);
161172
return;
162173
}
163174
if (reportAction.childType === CONST.REPORT.TYPE.TASK) {
164-
taskReportActions++;
175+
manageTeamTasksCount++;
165176
expect(reportAction.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
166177
// we dont check actorAccountID as it will be a random account id for the guide
167178
return;
168179
}
169-
signingOffMessage++;
180+
signOffMessagesCount++;
170181
});
171-
expect(createdTaskReportActions).toBe(1);
172-
expect(signingOffMessage).toBe(1);
173-
expect(taskReportActions).toBe(manageTeamDefaultTaskCount);
182+
expect(reportActionsOfTypeCreatedCount).toBe(expectedReportActionsOfTypeCreatedCount);
183+
expect(signOffMessagesCount).toBe(expectedSignOffMessagesCount);
184+
expect(manageTeamTasksCount).toBe(expectedManageTeamDefaultTasksCount);
174185

175186
// Check for success data
176187
(fetch as MockFetch)?.resume?.();
@@ -339,7 +350,7 @@ describe('actions/Policy', () => {
339350
});
340351
});
341352

342-
it('create a new workspace with enabled workflows if the onboarding choice is newDotManageTeam or newDotLookingAround', async () => {
353+
it('create a new workspace with enabled workflows if the onboarding choice is newDotManageTeam', async () => {
343354
Onyx.merge(`${ONYXKEYS.NVP_INTRO_SELECTED}`, {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM});
344355
await waitForBatchedUpdates();
345356

@@ -358,12 +369,69 @@ describe('actions/Policy', () => {
358369
});
359370
});
360371

361-
it('create a new workspace with disabled workflows if the onboarding choice is not newDotManageTeam or newDotLookingAround', async () => {
362-
Onyx.merge(`${ONYXKEYS.NVP_INTRO_SELECTED}`, {choice: CONST.ONBOARDING_CHOICES.PERSONAL_SPEND});
372+
it('create a new workspace with enabled workflows if the onboarding choice is newDotLookingAround', async () => {
373+
Onyx.merge(`${ONYXKEYS.NVP_INTRO_SELECTED}`, {choice: CONST.ONBOARDING_CHOICES.LOOKING_AROUND});
374+
await waitForBatchedUpdates();
375+
376+
const policyID = Policy.generatePolicyID();
377+
// When a new workspace is created with introSelected set to LOOKING_AROUND
378+
Policy.createWorkspace(ESH_EMAIL, true, WORKSPACE_NAME, policyID);
379+
await waitForBatchedUpdates();
380+
381+
await TestHelper.getOnyxData({
382+
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
383+
waitForCollectionCallback: false,
384+
callback: (policy) => {
385+
// Then the workflows feature is enabled
386+
expect(policy?.areWorkflowsEnabled).toBeTruthy();
387+
},
388+
});
389+
});
390+
391+
it('create a new workspace with disabled workflows if the onboarding choice is newDotTrackWorkspace', async () => {
392+
Onyx.merge(`${ONYXKEYS.NVP_INTRO_SELECTED}`, {choice: CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE});
393+
await waitForBatchedUpdates();
394+
395+
const policyID = Policy.generatePolicyID();
396+
// When a new workspace is created with introSelected set to TRACK_WORKSPACE
397+
Policy.createWorkspace(ESH_EMAIL, true, WORKSPACE_NAME, policyID);
398+
await waitForBatchedUpdates();
399+
400+
await TestHelper.getOnyxData({
401+
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
402+
waitForCollectionCallback: false,
403+
callback: (policy) => {
404+
// Then workflows are not enabled
405+
expect(policy?.areWorkflowsEnabled).toBeFalsy();
406+
},
407+
});
408+
});
409+
410+
it('create a new workspace with disabled workflows if the onboarding choice is newDotEmployer', async () => {
411+
Onyx.merge(`${ONYXKEYS.NVP_INTRO_SELECTED}`, {choice: CONST.ONBOARDING_CHOICES.EMPLOYER});
412+
await waitForBatchedUpdates();
413+
414+
const policyID = Policy.generatePolicyID();
415+
// When a new workspace is created with introSelected set to EMPLOYER
416+
Policy.createWorkspace(ESH_EMAIL, true, WORKSPACE_NAME, policyID);
417+
await waitForBatchedUpdates();
418+
419+
await TestHelper.getOnyxData({
420+
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
421+
waitForCollectionCallback: false,
422+
callback: (policy) => {
423+
// Then workflows are not enabled
424+
expect(policy?.areWorkflowsEnabled).toBeFalsy();
425+
},
426+
});
427+
});
428+
429+
it('create a new workspace with disabled workflows if the onboarding choice is newDotSplitChat', async () => {
430+
Onyx.merge(`${ONYXKEYS.NVP_INTRO_SELECTED}`, {choice: CONST.ONBOARDING_CHOICES.CHAT_SPLIT});
363431
await waitForBatchedUpdates();
364432

365433
const policyID = Policy.generatePolicyID();
366-
// When a new workspace is created with introSelected set to PERSONAL_SPEND
434+
// When a new workspace is created with introSelected set to CHAT_SPLIT
367435
Policy.createWorkspace(ESH_EMAIL, true, WORKSPACE_NAME, policyID);
368436
await waitForBatchedUpdates();
369437

0 commit comments

Comments
 (0)