Files
calendar/apps/api/v2/test/fixtures/repository/rate-limit.repository.fixture.ts
Lauris SkraucisandGitHub 4b6a389212 feat: v2 rate limiting (#16882)
* refactor: pass redis storage to throttler guard

* chore: upgrade throttler to latest

* feat: ApiKey RateLimit table

* chore: upgrade redis storage throttler

* feat: rate limit by api key

* refactor: on delete api key cascade rate limit

* fix: permissions guard work with oauth credentials

* chore: set rate limit in env

* tests: throttler

* feat: include rate limit name in response

* fix: correctly handle multiple rate limits

* chore: remove unused import

* delete migrations

* chore: prisma migration

* doc

* dummy

* fix: permissions guard unit test

* refactor: remove route specific @Throttles

* fix: permissions guard
2024-10-01 12:01:56 +00:00

23 lines
615 B
TypeScript

import { PrismaWriteService } from "@/modules/prisma/prisma-write.service";
import { TestingModule } from "@nestjs/testing";
export class RateLimitRepositoryFixture {
private dbWrite: PrismaWriteService["prisma"];
constructor(private readonly module: TestingModule) {
this.dbWrite = module.get(PrismaWriteService).prisma;
}
async createRateLimit(name: string, apiKeyId: string, ttl: number, limit: number, blockDuration: number) {
return await this.dbWrite.rateLimit.create({
data: {
name,
apiKeyId,
ttl,
limit,
blockDuration,
},
});
}
}