Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7928dc2

Browse files
committed
feat: add test for limiter.canTry()
1 parent d8e4505 commit 7928dc2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎test/unit/routes/login.test.ts‎

Lines changed: 13 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /