fix: Errors in org onboarding in some edge cases (#22711)
* Automatically enable migration of a team that conflicts with Orgs slug * Allow changing the orgs slug and name if user goes back and changes it * avoid crashing on some scenarios * Revert "Allow changing the orgs slug and name if user goes back and changes it" This reverts commit f8872b0116868d59757ef911c4940df79f93c6e0. * fix: handle unpublished teams gracefully in org migration - Change 'No oldSlug for team' from error to warning for unpublished teams - Keep 'No slug for team' as error since org onboarding ensures teams have names - Add test for migrating unpublished teams without oldSlug - Add clarifying comments about when each condition can occur
This commit is contained in:
1 parent
704bbf2757
commit
5360cb511d
6 files changed
+314
-18
No files matched your search
+28
@@ -348,6 +348,34 @@ describe("createOrganizationFromOnboarding", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("should invite members with isDirectUserAction set to false", async () => {
|
||||
const { organizationOnboarding } = await createOnboardingEligibleUserAndOnboarding({
|
||||
user: {
|
||||
username: "org-owner",
|
||||
email: "[email protected]",
|
||||
},
|
||||
});
|
||||
|
||||
// Call createOrganizationFromOnboarding
|
||||
const result = await createOrganizationFromOnboarding({
|
||||
organizationOnboarding,
|
||||
paymentSubscriptionId: "sub_123",
|
||||
paymentSubscriptionItemId: "si_123",
|
||||
});
|
||||
|
||||
// Verify inviteMembersWithNoInviterPermissionCheck was called with isDirectUserAction: false
|
||||
expect(inviteMembersWithNoInviterPermissionCheck).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
teamId: result.organization.id,
|
||||
invitations: [
|
||||
{ usernameOrEmail: "[email protected]", role: MembershipRole.MEMBER },
|
||||
{ usernameOrEmail: "[email protected]", role: MembershipRole.MEMBER },
|
||||
],
|
||||
isDirectUserAction: false,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("should update stripe customer ID for existing user", async () => {
|
||||
const { user: existingUser, organizationOnboarding } = await createOnboardingEligibleUserAndOnboarding({
|
||||
user: {
|
||||
|
||||
@@ -305,6 +305,7 @@ async function inviteMembers(invitedMembers: InvitedMember[], organization: Team
|
||||
usernameOrEmail: member.email,
|
||||
role: MembershipRole.MEMBER,
|
||||
})),
|
||||
isDirectUserAction: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -548,8 +549,17 @@ export const createOrganizationFromOnboarding = async ({
|
||||
} catch (error) {
|
||||
// Almost always the reason would be that the organization's slug conflicts with a team's slug
|
||||
// The owner might not have chosen the conflicting team for migration - Can be confirmed by checking `teams` column in the database.
|
||||
log.error("RecoverableError: Error while setting slug for organization", safeStringify(error));
|
||||
throw new Error("Unable to set slug for organization");
|
||||
log.error(
|
||||
"RecoverableError: Error while setting slug for organization",
|
||||
safeStringify(error),
|
||||
safeStringify({
|
||||
attemptedSlug: organizationOnboarding.slug,
|
||||
organizationId: organization.id,
|
||||
})
|
||||
);
|
||||
throw new Error(
|
||||
`Unable to set slug '${organizationOnboarding.slug}' for organization ${organization.id}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user