Skip to content

Commit fc85bf1

Browse files
committed
feat: add test for limiter.canTry()
1 parent b2a1efe commit fc85bf1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/unit/routes/login.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ describe("login", () => {
77
expect(limiter.try()).toBe(true)
88
})
99

10+
it("should pull tokens from both limiters (minute & hour)", () => {
11+
const limiter = new RateLimiter()
12+
13+
// Try twice, which pulls two from the minute bucket
14+
limiter.try()
15+
limiter.try()
16+
17+
// Check that we can still try
18+
// which should be true since there are 12 remaining in the hour bucket
19+
expect(limiter.canTry()).toBe(true)
20+
expect(limiter.try()).toBe(true)
21+
})
22+
1023
it("should not allow more than 14 tries in less than an hour", () => {
1124
const limiter = new RateLimiter()
1225

0 commit comments

Comments
 (0)