feat: add forcedSlowMode rate limit to Team and Organization DELETE endpoints (#27258)

* feat: add forcedSlowMode rate limit to Team and Organization DELETE endpoints

Co-Authored-By: [email protected] <[email protected]>

* test: add NoOpThrottlerGuard to disable rate limiting in tests

- Create NoOpThrottlerGuard class that always allows requests through
- Create withNoThrottler helper function to override CustomThrottlerGuard
- Update teams.controller.e2e-spec.ts to use withNoThrottler
- Update organizations-teams.controller.e2e-spec.ts to use withNoThrottler
- Update organizations-organizations.controller.e2e-spec.ts to use withNoThrottler

This prevents race conditions when tests fire rapidly against rate-limited endpoints.

Co-Authored-By: [email protected] <[email protected]>

* fix: use jest.spyOn to mock throttler guard in tests

Changed approach from overrideGuard to jest.spyOn for mocking
CustomThrottlerGuard.handleRequest to always return true. This
properly disables rate limiting in tests for the DELETE endpoints.

Co-Authored-By: [email protected] <[email protected]>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Morgan <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-01-27 17:24:30 +02:00
1 parent 0bcb110d20
commit 7ce1ee5cea
7 files changed
+298 -273

No files matched your search

@@ -12,6 +12,7 @@ import { MembershipRepositoryFixture } from "test/fixtures/repository/membership
import { TeamRepositoryFixture } from "test/fixtures/repository/team.repository.fixture";
import { UserRepositoryFixture } from "test/fixtures/repository/users.repository.fixture";
import { randomString } from "test/utils/randomString";
import { mockThrottlerGuard } from "test/utils/withNoThrottler";
import { AppModule } from "@/app.module";
import { bootstrap } from "@/bootstrap";
import { StripeService } from "@/modules/stripe/stripe.service";
@@ -40,12 +41,14 @@ describe("Teams endpoint", () => {
let team1: TeamOutputDto;
let team2: TeamOutputDto;
beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
imports: [AppModule, TeamsModule],
}).compile();
beforeAll(async () => {
mockThrottlerGuard();
jest.spyOn(StripeService.prototype, "getStripe").mockImplementation(() => ({}) as unknown as Stripe);
const moduleRef = await Test.createTestingModule({
imports: [AppModule, TeamsModule],
}).compile();
jest.spyOn(StripeService.prototype, "getStripe").mockImplementation(() => ({}) as unknown as Stripe);
userRepositoryFixture = new UserRepositoryFixture(moduleRef);
teamRepositoryFixture = new TeamRepositoryFixture(moduleRef);
@@ -1,5 +1,11 @@
import { SUCCESS_STATUS } from "@calcom/platform-constants";
import { TeamOutputDto } from "@calcom/platform-types";
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post, UseGuards } from "@nestjs/common";
import { ApiHeader, ApiOperation, ApiTags as DocsTags } from "@nestjs/swagger";
import { plainToClass } from "class-transformer";
import { API_VERSIONS_VALUES } from "@/lib/api-versions";
import { API_KEY_HEADER } from "@/lib/docs/headers";
import { Throttle } from "@/lib/endpoint-throttler-decorator";
import { GetUser } from "@/modules/auth/decorators/get-user/get-user.decorator";
import { Roles } from "@/modules/auth/decorators/roles/roles.decorator";
import { ApiAuthGuard } from "@/modules/auth/guards/api-auth/api-auth.guard";
@@ -14,12 +20,6 @@ import { UpdateTeamOutput } from "@/modules/teams/teams/outputs/teams/update-tea
import { TeamsService } from "@/modules/teams/teams/services/teams.service";
import { TeamsRepository } from "@/modules/teams/teams/teams.repository";
import { UserWithProfile } from "@/modules/users/users.repository";
import { Controller, UseGuards, Get, Param, ParseIntPipe, Delete, Patch, Post, Body } from "@nestjs/common";
import { ApiHeader, ApiOperation, ApiTags as DocsTags } from "@nestjs/swagger";
import { plainToClass } from "class-transformer";
import { SUCCESS_STATUS } from "@calcom/platform-constants";
import { TeamOutputDto } from "@calcom/platform-types";
@Controller({
path: "/v2/teams",
@@ -29,7 +29,10 @@ import { TeamOutputDto } from "@calcom/platform-types";
@DocsTags("Teams")
@ApiHeader(API_KEY_HEADER)
export class TeamsController {
constructor(private teamsService: TeamsService, private teamsRepository: TeamsRepository) {}
constructor(
private teamsService: TeamsService,
private teamsRepository: TeamsRepository
) {}
@Post()
@ApiOperation({ summary: "Create a team" })
@@ -95,6 +98,7 @@ export class TeamsController {
@UseGuards(RolesGuard)
@Delete("/:teamId")
@Throttle({ limit: 1, ttl: 30000, blockDuration: 30000, name: "teams_delete" })
@ApiOperation({ summary: "Delete a team" })
@Roles("TEAM_OWNER")
async deleteTeam(@Param("teamId", ParseIntPipe) teamId: number): Promise<OrgTeamOutputResponseDto> {