Skip to content

Commit 58e17c5

Browse files
committed
feat(testing): add tests for RateLimiter
1 parent 4683d8a commit 58e17c5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/unit/routes/login.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { RateLimiter } from "../../../src/node/routes/login"
2+
3+
describe("login", () => {
4+
describe("RateLimiter", () => {
5+
it("should allow one try ", () => {
6+
const limiter = new RateLimiter()
7+
expect(limiter.try()).toBe(true)
8+
})
9+
10+
it("should not allow more than 14 tries in less than an hour", () => {
11+
const limiter = new RateLimiter()
12+
13+
// The limiter allows 2 tries per minute plus 12 per hour
14+
// so if we run it 15 times, 14 should return true and the last
15+
// should return false
16+
for (let i = 1; i <= 14; i++) {
17+
expect(limiter.try()).toBe(true)
18+
}
19+
20+
expect(limiter.try()).toBe(false)
21+
})
22+
})
23+
})

0 commit comments

Comments
 (0)