@@ -4,20 +4,20 @@ describe("login", () => {
44 describe ( "RateLimiter" , ( ) => {
55 it ( "should allow one try " , ( ) => {
66 const limiter = new RateLimiter ( )
7- expect ( limiter . try ( ) ) . toBe ( true )
7+ expect ( limiter . removeToken ( ) ) . toBe ( true )
88 } )
99
1010 it ( "should pull tokens from both limiters (minute & hour)" , ( ) => {
1111 const limiter = new RateLimiter ( )
1212
1313 // Try twice, which pulls two from the minute bucket
14- limiter . try ( )
15- limiter . try ( )
14+ limiter . removeToken ( )
15+ limiter . removeToken ( )
1616
1717 // Check that we can still try
1818 // which should be true since there are 12 remaining in the hour bucket
1919 expect ( limiter . canTry ( ) ) . toBe ( true )
20- expect ( limiter . try ( ) ) . toBe ( true )
20+ expect ( limiter . removeToken ( ) ) . toBe ( true )
2121 } )
2222
2323 it ( "should not allow more than 14 tries in less than an hour" , ( ) => {
@@ -27,10 +27,11 @@ describe("login", () => {
2727 // so if we run it 15 times, 14 should return true and the last
2828 // should return false
2929 for ( let i = 1 ; i <= 14 ; i ++ ) {
30- expect ( limiter . try ( ) ) . toBe ( true )
30+ expect ( limiter . removeToken ( ) ) . toBe ( true )
3131 }
3232
33- expect ( limiter . try ( ) ) . toBe ( false )
33+ expect ( limiter . canTry ( ) ) . toBe ( false )
34+ expect ( limiter . removeToken ( ) ) . toBe ( false )
3435 } )
3536 } )
3637} )
0 commit comments