cloudaxe-opencode/packages/console/app/test/rateLimiter.test.ts

20 lines
650 B
TypeScript
Raw Permalink Normal View History

2026-02-10 21:54:19 +00:00
import { describe, expect, test } from "bun:test"
2026-04-15 00:29:21 +00:00
import { getRetryAfterDay } from "../src/routes/zen/util/ipRateLimiter"
2026-02-10 21:54:19 +00:00
describe("getRetryAfterDay", () => {
test("returns full day at midnight UTC", () => {
const midnight = Date.UTC(2026, 0, 15, 0, 0, 0, 0)
expect(getRetryAfterDay(midnight)).toBe(86_400)
})
test("returns remaining seconds until next UTC day", () => {
const noon = Date.UTC(2026, 0, 15, 12, 0, 0, 0)
expect(getRetryAfterDay(noon)).toBe(43_200)
})
test("rounds up to nearest second", () => {
const almost = Date.UTC(2026, 0, 15, 23, 59, 59, 500)
expect(getRetryAfterDay(almost)).toBe(1)
})
})