@@ -5,7 +5,7 @@ import { rateLimit } from "./index.js";
5
5
const mockRedis = {
6
6
get : vi . fn ( ) ,
7
7
expire : vi . fn ( ) ,
8
- incrBy : vi . fn ( ) ,
8
+ incrby : vi . fn ( ) ,
9
9
} ;
10
10
11
11
describe ( "rateLimit" , ( ) => {
@@ -14,7 +14,7 @@ describe("rateLimit", () => {
14
14
vi . clearAllMocks ( ) ;
15
15
mockRedis . get . mockReset ( ) ;
16
16
mockRedis . expire . mockReset ( ) ;
17
- mockRedis . incrBy . mockReset ( ) ;
17
+ mockRedis . incrby . mockReset ( ) ;
18
18
} ) ;
19
19
20
20
afterEach ( ( ) => {
@@ -52,7 +52,7 @@ describe("rateLimit", () => {
52
52
rateLimit : 50 ,
53
53
} ) ;
54
54
55
- expect ( mockRedis . incrBy ) . toHaveBeenCalledTimes ( 1 ) ;
55
+ expect ( mockRedis . incrby ) . toHaveBeenCalledTimes ( 1 ) ;
56
56
} ) ;
57
57
58
58
it ( "should rate limit if exceeded hard limit" , async ( ) => {
@@ -74,7 +74,7 @@ describe("rateLimit", () => {
74
74
errorCode : "RATE_LIMIT_EXCEEDED" ,
75
75
} ) ;
76
76
77
- expect ( mockRedis . incrBy ) . not . toHaveBeenCalled ( ) ;
77
+ expect ( mockRedis . incrby ) . not . toHaveBeenCalled ( ) ;
78
78
} ) ;
79
79
80
80
it ( "expires on the first incr request only" , async ( ) => {
@@ -92,7 +92,7 @@ describe("rateLimit", () => {
92
92
requestCount : 2 ,
93
93
rateLimit : 50 ,
94
94
} ) ;
95
- expect ( mockRedis . incrBy ) . toHaveBeenCalled ( ) ;
95
+ expect ( mockRedis . incrby ) . toHaveBeenCalled ( ) ;
96
96
} ) ;
97
97
98
98
it ( "enforces rate limit if sampled (hit)" , async ( ) => {
@@ -169,7 +169,7 @@ describe("rateLimit", () => {
169
169
requestCount : 1 ,
170
170
rateLimit : 50 ,
171
171
} ) ;
172
- expect ( mockRedis . incrBy ) . toHaveBeenCalledWith ( expect . any ( String ) , 1 ) ;
172
+ expect ( mockRedis . incrby ) . toHaveBeenCalledWith ( expect . any ( String ) , 1 ) ;
173
173
} ) ;
174
174
175
175
it ( "should handle null response from redis" , async ( ) => {
@@ -216,7 +216,7 @@ describe("rateLimit", () => {
216
216
mockRedis . get . mockResolvedValue ( "0" ) ;
217
217
218
218
// Mock redis.set to have 100ms delay
219
- mockRedis . incrBy . mockImplementation (
219
+ mockRedis . incrby . mockImplementation (
220
220
( ) =>
221
221
new Promise ( ( resolve ) => {
222
222
setTimeout ( ( ) => resolve ( 1 ) , 100 ) ;
@@ -256,13 +256,13 @@ describe("rateLimit", () => {
256
256
}
257
257
258
258
// Redis set should be called 3 times
259
- expect ( mockRedis . incrBy ) . toHaveBeenCalledTimes ( 3 ) ;
259
+ expect ( mockRedis . incrby ) . toHaveBeenCalledTimes ( 3 ) ;
260
260
} ) ;
261
261
262
262
it ( "should handle custom increment values" , async ( ) => {
263
263
// Mock initial state
264
264
mockRedis . get . mockResolvedValue ( "5" ) ;
265
- mockRedis . incrBy . mockResolvedValue ( 10 ) ;
265
+ mockRedis . incrby . mockResolvedValue ( 10 ) ;
266
266
267
267
const result = await rateLimit ( {
268
268
team : validTeamResponse ,
@@ -279,7 +279,7 @@ describe("rateLimit", () => {
279
279
} ) ;
280
280
281
281
// Verify redis was called with correct increment
282
- expect ( mockRedis . incrBy ) . toHaveBeenCalledWith (
282
+ expect ( mockRedis . incrby ) . toHaveBeenCalledWith (
283
283
expect . stringContaining ( "rate-limit" ) ,
284
284
5 ,
285
285
) ;
0 commit comments