Skip to content

Commit

Permalink
Fix onboarding status (#4019)
Browse files Browse the repository at this point in the history
* Fix onboarding status

* Add comment

* Fix jest tests
  • Loading branch information
martmull authored Feb 16, 2024
1 parent 0ee512a commit f2ff3e7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const billing = {
isBillingEnabled: true,
};
const currentWorkspace = {
displayName: 'testing',
activationStatus: 'active',
id: '1',
allowImpersonation: true,
};
Expand Down Expand Up @@ -119,25 +119,7 @@ describe('useOnboardingStatus', () => {
setBilling(billing);
setCurrentWorkspace({
...currentWorkspace,
displayName: '',
subscriptionStatus: 'active',
});
});

expect(result.current.onboardingStatus).toBe(
'ongoing_workspace_activation',
);
});

it('should return "ongoing_workspace_activation"', async () => {
const { result } = renderHooks();
const { setTokenPair, setBilling, setCurrentWorkspace } = result.current;

act(() => {
setTokenPair(tokenPair);
setBilling(billing);
setCurrentWorkspace({
...currentWorkspace,
activationStatus: 'inactive',
subscriptionStatus: 'active',
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,7 @@ describe('getOnboardingStatus', () => {
currentWorkspaceMember: null,
currentWorkspace: {
id: '1',
displayName: null,
} as CurrentWorkspace,
});

const ongoingWorkspaceActivationPreviouslyActive = getOnboardingStatus({
isLoggedIn: true,
currentWorkspaceMember: null,
currentWorkspace: {
id: '1',
displayName: 'My Workspace',
activationStatus: 'inactive',
} as CurrentWorkspace,
});

Expand All @@ -37,7 +28,7 @@ describe('getOnboardingStatus', () => {
} as WorkspaceMember,
currentWorkspace: {
id: '1',
displayName: 'My Workspace',
activationStatus: 'active',
} as CurrentWorkspace,
});

Expand All @@ -52,7 +43,7 @@ describe('getOnboardingStatus', () => {
} as WorkspaceMember,
currentWorkspace: {
id: '1',
displayName: 'My Workspace',
activationStatus: 'active',
} as CurrentWorkspace,
});

Expand All @@ -67,7 +58,7 @@ describe('getOnboardingStatus', () => {
} as WorkspaceMember,
currentWorkspace: {
id: '1',
displayName: 'My Workspace',
activationStatus: 'active',
subscriptionStatus: 'incomplete',
} as CurrentWorkspace,
isBillingEnabled: true,
Expand All @@ -84,7 +75,7 @@ describe('getOnboardingStatus', () => {
} as WorkspaceMember,
currentWorkspace: {
id: '1',
displayName: 'My Workspace',
activationStatus: 'active',
subscriptionStatus: 'incomplete',
} as CurrentWorkspace,
});
Expand All @@ -100,17 +91,14 @@ describe('getOnboardingStatus', () => {
} as WorkspaceMember,
currentWorkspace: {
id: '1',
displayName: 'My Workspace',
activationStatus: 'active',
subscriptionStatus: 'canceled',
} as CurrentWorkspace,
isBillingEnabled: true,
});

expect(ongoingUserCreation).toBe('ongoing_user_creation');
expect(ongoingWorkspaceActivation).toBe('ongoing_workspace_activation');
expect(ongoingWorkspaceActivationPreviouslyActive).toBe(
'ongoing_workspace_activation',
);
expect(ongoingProfileCreation).toBe('ongoing_profile_creation');
expect(completed).toBe('completed');
expect(incomplete).toBe('incomplete');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,24 @@ export const getOnboardingStatus = ({
return OnboardingStatus.OngoingUserCreation;
}

// After SignInUp, the user should have a current workspace assigned.
// If not, it indicates that the data is still being requested.
if (!currentWorkspace) {
return undefined;
}

if (
isBillingEnabled &&
currentWorkspace?.subscriptionStatus === 'incomplete'
currentWorkspace.subscriptionStatus === 'incomplete'
) {
return OnboardingStatus.Incomplete;
}

if (isBillingEnabled && currentWorkspace?.subscriptionStatus === 'canceled') {
if (isBillingEnabled && currentWorkspace.subscriptionStatus === 'canceled') {
return OnboardingStatus.Canceled;
}

if (currentWorkspace?.activationStatus !== 'active') {
if (currentWorkspace.activationStatus !== 'active') {
return OnboardingStatus.OngoingWorkspaceActivation;
}

Expand Down

0 comments on commit f2ff3e7

Please sign in to comment.