3fff3cd2f8
apps/sito passa in radice, apps/platforms si toglie: vive in gitea:Adriano/InsanityLab-platforms, con la storia del repo comune. I piani e le specifiche di Longevity e Campus lasciano docs/ e seguono le piattaforme. README e compose: deploy da /opt/docker/insanitylab/src; al primo deploy .env va spostato da apps/sito/.env alla radice. Refs #20 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
24 lines
801 B
TypeScript
24 lines
801 B
TypeScript
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
import { rateLimit, _resetBuckets } from '../src/lib/rate-limit';
|
|
|
|
afterEach(() => { _resetBuckets(); vi.useRealTimers(); });
|
|
|
|
describe('rateLimit', () => {
|
|
it('consente fino a max richieste', () => {
|
|
expect(rateLimit('a', 2, 1000)).toBe(true);
|
|
expect(rateLimit('a', 2, 1000)).toBe(true);
|
|
expect(rateLimit('a', 2, 1000)).toBe(false);
|
|
});
|
|
it('chiavi indipendenti', () => {
|
|
expect(rateLimit('a', 1, 1000)).toBe(true);
|
|
expect(rateLimit('b', 1, 1000)).toBe(true);
|
|
});
|
|
it('la finestra scade', () => {
|
|
vi.useFakeTimers();
|
|
expect(rateLimit('a', 1, 1000)).toBe(true);
|
|
expect(rateLimit('a', 1, 1000)).toBe(false);
|
|
vi.advanceTimersByTime(1100);
|
|
expect(rateLimit('a', 1, 1000)).toBe(true);
|
|
});
|
|
});
|