Open History to see the last commit
1import { expect, it } from "vitest"
2import { refillQuota } from "../../../server/store"
3it("preserves the refill clock, caps a full bucket and allows the configured timing leeway", () => {
4 expect(refillQuota(undefined, 10000)).toEqual({ tokens: 8, lastRefillAt: 10000 })
5 expect(refillQuota({ tokens: 0, last_refill_at: "10000" }, 15900)).toEqual({
6 tokens: 1,
7 lastRefillAt: 13000,
8 })
9 expect(refillQuota({ tokens: 0, last_refill_at: "10000" }, 12500, 500)).toEqual({
10 tokens: 1,
11 lastRefillAt: 13000,
12 })
13 expect(refillQuota({ tokens: 7, last_refill_at: "10000" }, 20000)).toEqual({
14 tokens: 8,
15 lastRefillAt: 20000,
16 })
17})