@@ -467,7 +467,7 @@ describe('SlidingWindowLog Rate Limiter', () => {
467467 expect ( retryAfter ) . toBe ( timestamp + 100 + WINDOW_SIZE ) ;
468468 } ) ;
469469 } ) ;
470- xtest ( 'users have their own logs' , async ( ) => {
470+ test ( 'users have their own logs' , async ( ) => {
471471 const requested = 6 ;
472472 const user3Tokens = 8 ;
473473 // // Add log for user 3 so we have both a user that exists in the store (3) and one that doesn't (2)
@@ -477,12 +477,14 @@ describe('SlidingWindowLog Rate Limiter', () => {
477477 await limiter . processRequest ( user1 , timestamp + 100 , requested ) ;
478478
479479 // // Check that each user has the expected log
480- expect ( await getLogFromClient ( client , user1 ) ) . toEqual ( {
481- timestamp : timestamp + 100 ,
482- tokens : requested ,
483- } ) ;
480+ expect ( await getLogFromClient ( client , user1 ) ) . toEqual ( [
481+ {
482+ timestamp : timestamp + 100 ,
483+ tokens : requested ,
484+ } ,
485+ ] ) ;
484486 expect ( await getLogFromClient ( client , user2 ) ) . toEqual ( [ ] ) ;
485- expect ( await getLogFromClient ( client , user3 ) ) . toEqual ( [ { timestamp, tokens : requested } ] ) ;
487+ expect ( await getLogFromClient ( client , user3 ) ) . toEqual ( [ { timestamp, tokens : user3Tokens } ] ) ;
486488
487489 await limiter . processRequest ( user2 , timestamp + 200 , 1 ) ;
488490 expect ( await getLogFromClient ( client , user1 ) ) . toEqual ( [
@@ -497,7 +499,7 @@ describe('SlidingWindowLog Rate Limiter', () => {
497499 tokens : 1 ,
498500 } ,
499501 ] ) ;
500- expect ( await getLogFromClient ( client , user3 ) ) . toEqual ( [ { timestamp, tokens : requested } ] ) ;
502+ expect ( await getLogFromClient ( client , user3 ) ) . toEqual ( [ { timestamp, tokens : user3Tokens } ] ) ;
501503 } ) ;
502504
503505 test ( 'is able to be reset' , async ( ) => {
@@ -533,7 +535,7 @@ describe('SlidingWindowLog Rate Limiter', () => {
533535 ) ;
534536 } ) ;
535537
536- xtest ( '...allows custom window size and capacity' , async ( ) => {
538+ test ( '...allows custom window size and capacity' , async ( ) => {
537539 const customWindow = 500 ;
538540 const customSizelimiter = new SlidingWindowLog ( customWindow , CAPACITY , client ) ;
539541
@@ -551,18 +553,21 @@ describe('SlidingWindowLog Rate Limiter', () => {
551553 . processRequest ( user1 , timestamp + customWindow , CAPACITY )
552554 . then ( ( res ) => res . success ) ;
553555
554- const customCapacitylimiter = new SlidingWindowLog ( WINDOW_SIZE , 5 , client ) ;
556+ // Reset the redis store
557+ customSizelimiter . reset ( ) ;
558+
555559 const customCapacity = 5 ;
560+ const customCapacitylimiter = new SlidingWindowLog ( WINDOW_SIZE , customCapacity , client ) ;
556561
557- let customWindowSuccess = await customCapacitylimiter
562+ let customCapacitySuccess = await customCapacitylimiter
558563 . processRequest ( user1 , timestamp , customCapacity + 1 )
559564 . then ( ( res ) => res . success ) ;
560- expect ( customSizeSuccess ) . toBe ( false ) ;
565+ expect ( customCapacitySuccess ) . toBe ( false ) ;
561566
562- customWindowSuccess = await customCapacitylimiter
567+ customCapacitySuccess = await customCapacitylimiter
563568 . processRequest ( user1 , timestamp + 100 , customCapacity )
564569 . then ( ( res ) => res . success ) ;
565- expect ( customWindowSuccess ) . toBe ( true ) ;
570+ expect ( customCapacitySuccess ) . toBe ( true ) ;
566571 } ) ;
567572 } ) ;
568573} ) ;
0 commit comments