Archived
1
0

feat(testing): add tests for RateLimiter

This commit is contained in:
Joe Previte 2021-04-15 15:12:07 -07:00
parent 4683d8a077
commit 58e17c5e50
No known key found for this signature in database
GPG Key ID: 2C91590C6B742C24

View File

@ -0,0 +1,23 @@
import { RateLimiter } from "../../../src/node/routes/login"
describe("login", () => {
describe("RateLimiter", () => {
it("should allow one try ", () => {
const limiter = new RateLimiter()
expect(limiter.try()).toBe(true)
})
it("should not allow more than 14 tries in less than an hour", () => {
const limiter = new RateLimiter()
// The limiter allows 2 tries per minute plus 12 per hour
// so if we run it 15 times, 14 should return true and the last
// should return false
for (let i = 1; i <= 14; i++) {
expect(limiter.try()).toBe(true)
}
expect(limiter.try()).toBe(false)
})
})
})