Skip to content

Commit

Permalink
feat: add test for limiter.canTry()
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjoeio committed Apr 16, 2021
1 parent b2a1efe commit fc85bf1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/unit/routes/login.test.ts
Expand Up @@ -7,6 +7,19 @@ describe("login", () => {
expect(limiter.try()).toBe(true)
})

it("should pull tokens from both limiters (minute & hour)", () => {
const limiter = new RateLimiter()

// Try twice, which pulls two from the minute bucket
limiter.try()
limiter.try()

// Check that we can still try
// which should be true since there are 12 remaining in the hour bucket
expect(limiter.canTry()).toBe(true)
expect(limiter.try()).toBe(true)
})

it("should not allow more than 14 tries in less than an hour", () => {
const limiter = new RateLimiter()

Expand Down

0 comments on commit fc85bf1

Please sign in to comment.