-
Notifications
You must be signed in to change notification settings - Fork 11.1k
feat: Ensure teams with conflicting slugs owned by the user are migrated(handled in backend, frontend already had this restriction) #25291
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
33d43ed
feat: add backend validation for conflicting team slugs during org on…
hariombalhara 7494654
refactor: use TeamRepository in listOwnedTeamsHandler
hariombalhara 0c3d3c3
fix: update tests to use renamed buildTeamsAndInvites method
devin-ai-integration[bot] ca97202
fix: mock TeamRepository in tests to prevent database calls
devin-ai-integration[bot] 6098feb
refactor: improve readability of ensureConflictingSlugTeamIsMigrated
devin-ai-integration[bot] 1f453db
Merge branch 'main' into fix-conflicting-team-migration
Udit-takkar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,45 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import type { User } from "@calcom/prisma/client"; | ||
| import { UserPermissionRole } from "@calcom/prisma/enums"; | ||
|
|
||
| vi.mock("@calcom/features/ee/teams/repositories/TeamRepository", () => ({ | ||
| TeamRepository: class { | ||
| constructor() {} | ||
| findOwnedTeamsByUserId(_: { userId: number }) { | ||
| return Promise.resolve([]); | ||
| } | ||
| }, | ||
| })); | ||
|
|
||
| import { BaseOnboardingService } from "../BaseOnboardingService"; | ||
| import type { CreateOnboardingIntentInput } from "../types"; | ||
| import type { CreateOnboardingIntentInput, OnboardingIntentResult } from "../types"; | ||
|
|
||
| class TestableBaseOnboardingService extends BaseOnboardingService { | ||
| async createOnboardingIntent(input: CreateOnboardingIntentInput): Promise<any> { | ||
| async createOnboardingIntent(_input: CreateOnboardingIntentInput): Promise<OnboardingIntentResult> { | ||
| throw new Error("Not implemented"); | ||
| } | ||
|
|
||
| public testFilterTeamsAndInvites( | ||
| public async testBuildTeamsAndInvites( | ||
| orgSlug: string, | ||
| teams: CreateOnboardingIntentInput["teams"], | ||
| invitedMembers: CreateOnboardingIntentInput["invitedMembers"] | ||
| ) { | ||
| return this.filterTeamsAndInvites(teams, invitedMembers); | ||
| return this.buildTeamsAndInvites(orgSlug, teams, invitedMembers); | ||
| } | ||
| } | ||
|
|
||
| const mockUser = { | ||
| const mockUser: Pick<User, "id" | "email" | "role" | "name"> = { | ||
| id: 1, | ||
| email: "[email protected]", | ||
| role: UserPermissionRole.USER, | ||
| name: "Test User", | ||
| }; | ||
|
|
||
| describe("BaseOnboardingService", () => { | ||
| describe("filterTeamsAndInvites", () => { | ||
| it("should filter out invites with empty emails", () => { | ||
| const service = new TestableBaseOnboardingService(mockUser as any); | ||
| describe("buildTeamsAndInvites", () => { | ||
| it("should filter out invites with empty emails", async () => { | ||
| const service = new TestableBaseOnboardingService(mockUser); | ||
|
|
||
| const invites = [ | ||
| { email: "[email protected]", teamName: "Marketing", role: "MEMBER" }, | ||
|
|
@@ -37,7 +48,7 @@ describe("BaseOnboardingService", () => { | |
| { email: "[email protected]", teamName: "Design", role: "MEMBER" }, | ||
| ]; | ||
|
|
||
| const { invitedMembersData } = service.testFilterTeamsAndInvites([], invites); | ||
| const { invitedMembersData } = await service.testBuildTeamsAndInvites("test-org", [], invites); | ||
|
|
||
| expect(invitedMembersData).toHaveLength(2); | ||
| expect(invitedMembersData).toEqual([ | ||
|
|
@@ -58,8 +69,8 @@ describe("BaseOnboardingService", () => { | |
| ]); | ||
| }); | ||
|
|
||
| it("should preserve all fields from invites including role", () => { | ||
| const service = new TestableBaseOnboardingService(mockUser as any); | ||
| it("should preserve all fields from invites including role", async () => { | ||
| const service = new TestableBaseOnboardingService(mockUser); | ||
|
|
||
| const invites = [ | ||
| { | ||
|
|
@@ -78,7 +89,7 @@ describe("BaseOnboardingService", () => { | |
| }, | ||
| ]; | ||
|
|
||
| const { invitedMembersData } = service.testFilterTeamsAndInvites([], invites); | ||
| const { invitedMembersData } = await service.testBuildTeamsAndInvites("test-org", [], invites); | ||
|
|
||
| expect(invitedMembersData).toEqual([ | ||
| { | ||
|
|
@@ -98,15 +109,15 @@ describe("BaseOnboardingService", () => { | |
| ]); | ||
| }); | ||
|
|
||
| it("should handle invites without optional fields", () => { | ||
| const service = new TestableBaseOnboardingService(mockUser as any); | ||
| it("should handle invites without optional fields", async () => { | ||
| const service = new TestableBaseOnboardingService(mockUser); | ||
|
|
||
| const invites = [ | ||
| { email: "[email protected]" }, | ||
| { email: "[email protected]", teamName: "Sales" }, | ||
| ]; | ||
|
|
||
| const { invitedMembersData } = service.testFilterTeamsAndInvites([], invites); | ||
| const { invitedMembersData } = await service.testBuildTeamsAndInvites("test-org", [], invites); | ||
|
|
||
| expect(invitedMembersData).toEqual([ | ||
| { | ||
|
|
@@ -126,8 +137,8 @@ describe("BaseOnboardingService", () => { | |
| ]); | ||
| }); | ||
|
|
||
| it("should filter out teams with empty names", () => { | ||
| const service = new TestableBaseOnboardingService(mockUser as any); | ||
| it("should filter out teams with empty names", async () => { | ||
| const service = new TestableBaseOnboardingService(mockUser); | ||
|
|
||
| const teams = [ | ||
| { id: 1, name: "Marketing", isBeingMigrated: false, slug: null }, | ||
|
|
@@ -136,7 +147,7 @@ describe("BaseOnboardingService", () => { | |
| { id: 4, name: "Engineering", isBeingMigrated: true, slug: "eng" }, | ||
| ]; | ||
|
|
||
| const { teamsData } = service.testFilterTeamsAndInvites(teams, []); | ||
| const { teamsData } = await service.testBuildTeamsAndInvites("test-org", teams, []); | ||
|
|
||
| expect(teamsData).toHaveLength(2); | ||
| expect(teamsData).toEqual([ | ||
|
|
@@ -145,42 +156,42 @@ describe("BaseOnboardingService", () => { | |
| ]); | ||
| }); | ||
|
|
||
| it("should preserve team properties including migration status", () => { | ||
| const service = new TestableBaseOnboardingService(mockUser as any); | ||
| it("should preserve team properties including migration status", async () => { | ||
| const service = new TestableBaseOnboardingService(mockUser); | ||
|
|
||
| const teams = [ | ||
| { id: -1, name: "New Team", isBeingMigrated: false, slug: null }, | ||
| { id: 42, name: "Existing Team", isBeingMigrated: true, slug: "existing-team" }, | ||
| ]; | ||
|
|
||
| const { teamsData } = service.testFilterTeamsAndInvites(teams, []); | ||
| const { teamsData } = await service.testBuildTeamsAndInvites("test-org", teams, []); | ||
|
|
||
| expect(teamsData).toEqual([ | ||
| { id: -1, name: "New Team", isBeingMigrated: false, slug: null }, | ||
| { id: 42, name: "Existing Team", isBeingMigrated: true, slug: "existing-team" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("should handle empty teams and invites arrays", () => { | ||
| const service = new TestableBaseOnboardingService(mockUser as any); | ||
| it("should handle empty teams and invites arrays", async () => { | ||
| const service = new TestableBaseOnboardingService(mockUser); | ||
|
|
||
| const { teamsData, invitedMembersData } = service.testFilterTeamsAndInvites([], []); | ||
| const { teamsData, invitedMembersData } = await service.testBuildTeamsAndInvites("test-org", [], []); | ||
|
|
||
| expect(teamsData).toEqual([]); | ||
| expect(invitedMembersData).toEqual([]); | ||
| }); | ||
|
|
||
| it("should handle undefined teams and invites", () => { | ||
| const service = new TestableBaseOnboardingService(mockUser as any); | ||
| it("should handle undefined teams and invites", async () => { | ||
| const service = new TestableBaseOnboardingService(mockUser); | ||
|
|
||
| const { teamsData, invitedMembersData } = service.testFilterTeamsAndInvites(undefined, undefined); | ||
| const { teamsData, invitedMembersData } = await service.testBuildTeamsAndInvites("test-org", undefined, undefined); | ||
|
|
||
| expect(teamsData).toEqual([]); | ||
| expect(invitedMembersData).toEqual([]); | ||
| }); | ||
|
|
||
| it("should preserve invites with teamId=-1 for new teams", () => { | ||
| const service = new TestableBaseOnboardingService(mockUser as any); | ||
| it("should preserve invites with teamId=-1 for new teams", async () => { | ||
| const service = new TestableBaseOnboardingService(mockUser); | ||
|
|
||
| const teams = [ | ||
| { id: -1, name: "Marketing", isBeingMigrated: false, slug: null }, | ||
|
|
@@ -192,7 +203,7 @@ describe("BaseOnboardingService", () => { | |
| { email: "[email protected]", teamId: -1, teamName: "Sales", role: "ADMIN" }, | ||
| ]; | ||
|
|
||
| const { teamsData, invitedMembersData } = service.testFilterTeamsAndInvites(teams, invites); | ||
| const { teamsData, invitedMembersData } = await service.testBuildTeamsAndInvites("test-org", teams, invites); | ||
|
|
||
| expect(teamsData).toHaveLength(2); | ||
| expect(invitedMembersData).toHaveLength(2); | ||
|
|
@@ -202,8 +213,8 @@ describe("BaseOnboardingService", () => { | |
| expect(invitedMembersData[1].role).toBe("ADMIN"); | ||
| }); | ||
|
|
||
| it("should handle mixed scenarios with both org-level and team-specific invites", () => { | ||
| const service = new TestableBaseOnboardingService(mockUser as any); | ||
| it("should handle mixed scenarios with both org-level and team-specific invites", async () => { | ||
| const service = new TestableBaseOnboardingService(mockUser); | ||
|
|
||
| const teams = [ | ||
| { id: -1, name: "Marketing", isBeingMigrated: false, slug: null }, | ||
|
|
@@ -216,7 +227,7 @@ describe("BaseOnboardingService", () => { | |
| { email: "[email protected]", teamName: "Engineering", teamId: 42, role: "ADMIN" }, | ||
| ]; | ||
|
|
||
| const { teamsData, invitedMembersData } = service.testFilterTeamsAndInvites(teams, invites); | ||
| const { teamsData, invitedMembersData } = await service.testBuildTeamsAndInvites("test-org", teams, invites); | ||
|
|
||
| expect(teamsData).toHaveLength(2); | ||
| expect(invitedMembersData).toHaveLength(3); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed filterTeamsAndInvites -> buildTeamsAndInvites