2026-05-18 07:27:06 +07:00
|
|
|
// @ts-nocheck
|
2026-05-18 07:29:01 +07:00
|
|
|
import { afterEach, beforeEach, describe, expect, it, spyOn } from 'bun:test';
|
|
|
|
|
import logger from '../src/utils/logger';
|
|
|
|
|
import { checkRateLimit, cleanupRateLimitCache } from '../src/utils/rateLimit';
|
2026-05-18 07:01:32 +07:00
|
|
|
|
|
|
|
|
// Spy on logger.warn
|
2026-05-18 07:29:01 +07:00
|
|
|
const warnSpy = spyOn(logger, 'warn');
|
2026-05-18 07:01:32 +07:00
|
|
|
|
2026-05-18 07:29:01 +07:00
|
|
|
describe('Rate Limiter', () => {
|
2026-05-18 07:01:32 +07:00
|
|
|
beforeEach(() => {
|
|
|
|
|
warnSpy.mockClear();
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-18 21:02:38 +07:00
|
|
|
it('should always allow requests as rate limiter is disabled', () => {
|
2026-05-18 07:29:01 +07:00
|
|
|
const key = 'user-1';
|
2026-05-18 07:01:32 +07:00
|
|
|
expect(checkRateLimit(key)).toBe(true);
|
|
|
|
|
expect(checkRateLimit(key)).toBe(true);
|
|
|
|
|
expect(checkRateLimit(key)).toBe(true);
|
2026-05-18 21:02:38 +07:00
|
|
|
expect(checkRateLimit(key)).toBe(true);
|
2026-05-18 07:01:32 +07:00
|
|
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-18 21:02:38 +07:00
|
|
|
it('should no-op on cleanup', () => {
|
|
|
|
|
expect(() => cleanupRateLimitCache()).not.toThrow();
|
2026-05-18 07:01:32 +07:00
|
|
|
});
|
|
|
|
|
});
|