Skip to content

fix: onboarding modal appears when we fail on creating a new workspace #58787

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

Merged
merged 2 commits into from
Mar 21, 2025
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
2 changes: 1 addition & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4213,7 +4213,7 @@ function prepareOnboardingOnyxData(
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.NVP_ONBOARDING,
value: {hasCompletedGuidedSetupFlow: false},
value: {hasCompletedGuidedSetupFlow: onboarding?.hasCompletedGuidedSetupFlow ?? null},
});
}

Expand Down
27 changes: 26 additions & 1 deletion tests/actions/PolicyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import CONST from '@src/CONST';
import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager';
import * as Policy from '@src/libs/actions/Policy/Policy';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy as PolicyType, Report, ReportAction, ReportActions, TransactionViolations} from '@src/types/onyx';
import type {Onboarding, Policy as PolicyType, Report, ReportAction, ReportActions, TransactionViolations} from '@src/types/onyx';
import type {Participant} from '@src/types/onyx/Report';
import createRandomPolicy from '../utils/collections/policies';
import createRandomReport from '../utils/collections/reports';
Expand Down Expand Up @@ -223,6 +223,31 @@ describe('actions/Policy', () => {
});
});

it('create a new workspace fails will reset hasCompletedGuidedSetupFlow to the correct value', async () => {
(fetch as MockFetch)?.pause?.();
await Onyx.set(ONYXKEYS.SESSION, {email: ESH_EMAIL, accountID: ESH_ACCOUNT_ID});
await Onyx.set(ONYXKEYS.NVP_ONBOARDING, {hasCompletedGuidedSetupFlow: true, chatReportID: '12345'});
await Onyx.set(ONYXKEYS.NVP_INTRO_SELECTED, {choice: CONST.ONBOARDING_CHOICES.LOOKING_AROUND});
await waitForBatchedUpdates();

(fetch as MockFetch)?.fail?.();
Policy.createWorkspace(ESH_EMAIL, true, WORKSPACE_NAME);
Copy link
Member

Choose a reason for hiding this comment

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

How are you mimicking failure here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@parasharrajat What do you mean? The fail function will make the API fails

mockFetch.fail = () => (shouldFail = true);

Copy link
Member

Choose a reason for hiding this comment

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

Ah, missed that.

await waitForBatchedUpdates();

(fetch as MockFetch)?.resume?.();
await waitForBatchedUpdates();

let onboarding: OnyxEntry<Onboarding>;
await TestHelper.getOnyxData({
key: ONYXKEYS.NVP_ONBOARDING,
waitForCollectionCallback: false,
callback: (val) => {
onboarding = val;
},
});
expect(onboarding?.hasCompletedGuidedSetupFlow).toBeTruthy();
});

it('create a new workspace with enabled workflows if the onboarding choice is newDotManageTeam or newDotLookingAround', async () => {
Onyx.merge(`${ONYXKEYS.NVP_INTRO_SELECTED}`, {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM});
await waitForBatchedUpdates();
Expand Down
Loading