fix: allow team with same slug for diff cases (#24029)
* fix: aalow team with slug for diff cases * addressed review * fix type error * update test * addressed review * fix test * Update team.ts --------- Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
6 files changed
+201
-27
No files matched your search
@@ -160,6 +160,7 @@ const createTeamAndAddUser = async (
|
||||
orgRequestedSlug,
|
||||
schedulingType,
|
||||
assignAllTeamMembersForSubTeamEvents,
|
||||
teamSlug,
|
||||
}: {
|
||||
user: { id: number; email: string; username: string | null; role?: MembershipRole };
|
||||
isUnpublished?: boolean;
|
||||
@@ -172,12 +173,15 @@ const createTeamAndAddUser = async (
|
||||
orgRequestedSlug?: string;
|
||||
schedulingType?: SchedulingType;
|
||||
assignAllTeamMembersForSubTeamEvents?: boolean;
|
||||
teamSlug?: string;
|
||||
},
|
||||
workerInfo: WorkerInfo
|
||||
) => {
|
||||
const slugIndex = index ? `-count-${index}` : "";
|
||||
const slug =
|
||||
orgRequestedSlug ?? `${isOrg ? "org" : "team"}-${workerInfo.workerIndex}-${Date.now()}${slugIndex}`;
|
||||
teamSlug ??
|
||||
orgRequestedSlug ??
|
||||
`${isOrg ? "org" : "team"}-${workerInfo.workerIndex}-${Date.now()}${slugIndex}`;
|
||||
const data: PrismaType.TeamCreateInput = {
|
||||
name: `user-id-${user.id}'s ${isOrg ? "Org" : "Team"}`,
|
||||
isOrganization: isOrg,
|
||||
@@ -283,6 +287,7 @@ export const createUsersFixture = (
|
||||
schedulingType?: SchedulingType;
|
||||
teamEventTitle?: string;
|
||||
teamEventSlug?: string;
|
||||
teamSlug?: string;
|
||||
teamEventLength?: number;
|
||||
isOrg?: boolean;
|
||||
isOrgVerified?: boolean;
|
||||
@@ -367,6 +372,7 @@ export const createUsersFixture = (
|
||||
orgRequestedSlug: scenario.orgRequestedSlug,
|
||||
schedulingType: scenario.schedulingType,
|
||||
assignAllTeamMembersForSubTeamEvents: scenario.assignAllTeamMembersForSubTeamEvents,
|
||||
teamSlug: scenario?.teamSlug,
|
||||
},
|
||||
workerInfo
|
||||
);
|
||||
@@ -465,7 +471,7 @@ export const createUsersFixture = (
|
||||
},
|
||||
data: {
|
||||
orgProfiles: _user.profiles.length
|
||||
? {
|
||||
? {
|
||||
connect: _user.profiles.map((profile) => ({ id: profile.id })),
|
||||
}
|
||||
: {
|
||||
@@ -711,6 +717,31 @@ const createUserFixture = (user: UserWithIncludes, page: Page) => {
|
||||
}
|
||||
return membership;
|
||||
},
|
||||
getAllTeamMembership: async () => {
|
||||
const memberships = await prisma.membership.findMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
team: {
|
||||
isOrganization: false,
|
||||
},
|
||||
},
|
||||
include: { team: true, user: true },
|
||||
});
|
||||
|
||||
const filteredMemberships = memberships.map((membership) => ({
|
||||
...membership,
|
||||
team: {
|
||||
...membership.team,
|
||||
metadata: teamMetadataSchema.parse(membership.team.metadata),
|
||||
},
|
||||
}));
|
||||
|
||||
if (filteredMemberships.length === 0) {
|
||||
throw new Error("No team memberships found for user");
|
||||
}
|
||||
|
||||
return filteredMemberships;
|
||||
},
|
||||
getOrgMembership: async () => {
|
||||
const membership = await prisma.membership.findFirstOrThrow({
|
||||
where: {
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
confirmReschedule,
|
||||
fillStripeTestCheckout,
|
||||
selectFirstAvailableTimeSlotNextMonth,
|
||||
submitAndWaitForResponse,
|
||||
testName,
|
||||
} from "./lib/testUtils";
|
||||
|
||||
@@ -301,3 +302,108 @@ test.describe("Teams - NonOrg", () => {
|
||||
});
|
||||
todo("Reschedule a Round Robin EventType booking");
|
||||
});
|
||||
|
||||
test.describe("Team Slug Validation", () => {
|
||||
test.afterEach(({ users, orgs }) => {
|
||||
users.deleteAll();
|
||||
orgs.deleteAll();
|
||||
});
|
||||
|
||||
test("Teams in different organizations can have the same slug", async ({ page, users, orgs }) => {
|
||||
const org1 = await orgs.create({ name: "Organization 1" });
|
||||
const org2 = await orgs.create({ name: "Organization 2" });
|
||||
|
||||
const owner1 = await users.create(
|
||||
{
|
||||
organizationId: org1.id,
|
||||
roleInOrganization: "OWNER",
|
||||
},
|
||||
{
|
||||
hasTeam: true,
|
||||
teamSlug: "cal",
|
||||
teamRole: "OWNER",
|
||||
}
|
||||
);
|
||||
|
||||
const owner2 = await users.create(
|
||||
{
|
||||
organizationId: org2.id,
|
||||
roleInOrganization: "OWNER",
|
||||
},
|
||||
{
|
||||
hasTeam: true,
|
||||
teamSlug: "calCom",
|
||||
teamRole: "OWNER",
|
||||
}
|
||||
);
|
||||
const { team: team1 } = await owner1.getFirstTeamMembership();
|
||||
|
||||
await owner1.apiLogin();
|
||||
await page.goto(`/settings/teams/${team1.id}/profile`);
|
||||
await page.locator('input[name="slug"]').fill("calCom");
|
||||
await submitAndWaitForResponse(page, "/api/trpc/teams/update?batch=1", {
|
||||
action: () => page.locator("[data-testid=update-team-profile]").click(),
|
||||
});
|
||||
});
|
||||
|
||||
test("Teams within same organization cannot have duplicate slugs", async ({ page, users, orgs }) => {
|
||||
const org = await orgs.create({ name: "Organization 1" });
|
||||
|
||||
const owner = await users.create(
|
||||
{
|
||||
organizationId: org.id,
|
||||
roleInOrganization: "OWNER",
|
||||
},
|
||||
{
|
||||
hasTeam: true,
|
||||
numberOfTeams: 2,
|
||||
teamRole: "OWNER",
|
||||
}
|
||||
);
|
||||
|
||||
const teams = await owner.getAllTeamMembership();
|
||||
await owner.apiLogin();
|
||||
await page.goto(`/settings/teams/${teams[0].team.id}/profile`);
|
||||
if (!teams[1].team.slug) throw new Error("Slug not found for team 2");
|
||||
await page.locator('input[name="slug"]').fill(teams[1].team.slug);
|
||||
await submitAndWaitForResponse(page, "/api/trpc/teams/update?batch=1", {
|
||||
action: () => page.locator("[data-testid=update-team-profile]").click(),
|
||||
expectedStatusCode: 409,
|
||||
});
|
||||
});
|
||||
|
||||
test("Teams without organization can have same slug as teams in organizations", async ({
|
||||
page,
|
||||
users,
|
||||
orgs,
|
||||
}) => {
|
||||
const org = await orgs.create({ name: "Organization 1" });
|
||||
|
||||
const orgOwner = await users.create(
|
||||
{
|
||||
organizationId: org.id,
|
||||
roleInOrganization: "OWNER",
|
||||
},
|
||||
{
|
||||
hasTeam: true,
|
||||
teamSlug: "calCom",
|
||||
teamRole: "OWNER",
|
||||
}
|
||||
);
|
||||
|
||||
const teamOwner = await users.create(
|
||||
{ username: "pro-user", name: "pro-user" },
|
||||
{
|
||||
hasTeam: true,
|
||||
}
|
||||
);
|
||||
|
||||
const { team } = await teamOwner.getFirstTeamMembership();
|
||||
await teamOwner.apiLogin();
|
||||
await page.goto(`/settings/teams/${team.id}/profile`);
|
||||
await page.locator('input[name="slug"]').fill("calCom");
|
||||
await submitAndWaitForResponse(page, "/api/trpc/teams/update?batch=1", {
|
||||
action: () => page.locator("[data-testid=update-team-profile]").click(),
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user