Skip to content

Commit

Permalink
test: add adjustment to also check tracker string
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-si authored and jmcdo29 committed Dec 8, 2023
1 parent 41b7482 commit b5f8240
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/function-overrides/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { APP_GUARD } from '@nestjs/core';
import { ThrottlerGuard, ThrottlerModule, seconds } from '../../src';
import { FunctionOverridesThrottlerController } from './funciton-overrides-throttler.controller';
import md5 = require('md5');
import assert = require('assert');

@Module({
imports: [
Expand All @@ -16,8 +17,10 @@ import md5 = require('md5');
name: 'custom',
ttl: seconds(3),
limit: 2,
getTracker: (req) => req.ip,
getTracker: () => 'customTrackerString',
generateKey: (context: ExecutionContext, trackerString: string, throttlerName: string) => {
// check if tracker string is passed correctly
assert(trackerString === 'customTrackerString');
// use the same key for all endpoints
return md5(`${throttlerName}-${trackerString}`);
},
Expand Down

0 comments on commit b5f8240

Please sign in to comment.