Archived
1
0

feat: add test for limiter.canTry()

This commit is contained in:
Joe Previte 2021-04-16 14:23:46 -07:00
parent d8e45057c7
commit 7928dc2bff
No known key found for this signature in database
GPG Key ID: 2C91590C6B742C24

View File

@ -7,6 +7,19 @@ describe("login", () => {
expect(limiter.try()).toBe(true) 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", () => { it("should not allow more than 14 tries in less than an hour", () => {
const limiter = new RateLimiter() const limiter = new RateLimiter()