@@ -4,20 +4,20 @@ describe("login", () => {
4
4
describe ( "RateLimiter" , ( ) => {
5
5
it ( "should allow one try " , ( ) => {
6
6
const limiter = new RateLimiter ( )
7
- expect ( limiter . try ( ) ) . toBe ( true )
7
+ expect ( limiter . removeToken ( ) ) . toBe ( true )
8
8
} )
9
9
10
10
it ( "should pull tokens from both limiters (minute & hour)" , ( ) => {
11
11
const limiter = new RateLimiter ( )
12
12
13
13
// Try twice, which pulls two from the minute bucket
14
- limiter . try ( )
15
- limiter . try ( )
14
+ limiter . removeToken ( )
15
+ limiter . removeToken ( )
16
16
17
17
// Check that we can still try
18
18
// which should be true since there are 12 remaining in the hour bucket
19
19
expect ( limiter . canTry ( ) ) . toBe ( true )
20
- expect ( limiter . try ( ) ) . toBe ( true )
20
+ expect ( limiter . removeToken ( ) ) . toBe ( true )
21
21
} )
22
22
23
23
it ( "should not allow more than 14 tries in less than an hour" , ( ) => {
@@ -27,10 +27,11 @@ describe("login", () => {
27
27
// so if we run it 15 times, 14 should return true and the last
28
28
// should return false
29
29
for ( let i = 1 ; i <= 14 ; i ++ ) {
30
- expect ( limiter . try ( ) ) . toBe ( true )
30
+ expect ( limiter . removeToken ( ) ) . toBe ( true )
31
31
}
32
32
33
- expect ( limiter . try ( ) ) . toBe ( false )
33
+ expect ( limiter . canTry ( ) ) . toBe ( false )
34
+ expect ( limiter . removeToken ( ) ) . toBe ( false )
34
35
} )
35
36
} )
36
37
} )
0 commit comments