diff --git a/lib/rate-limit.accessibility.test.ts b/lib/rate-limit.accessibility.test.ts index ec8563889..f4d95a86e 100644 --- a/lib/rate-limit.accessibility.test.ts +++ b/lib/rate-limit.accessibility.test.ts @@ -1,9 +1,9 @@ -import { describe, expect, it } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; import { RateLimiter, rateLimit } from './rate-limit'; -describe('rate-limit accessibility compliance', () => { - it('should return a complete result structure for screen-reader consumers', async () => { - const limiter = new RateLimiter(5, 60000); +describe('RateLimiter accessibility standards', () => { + it('should expose rate limit result with accessible status information', async () => { + const limiter = new RateLimiter(2, 60000); const result = await limiter.checkWithResult('127.0.0.1'); @@ -13,28 +13,28 @@ describe('rate-limit accessibility compliance', () => { expect(result).toHaveProperty('reset'); }); - it('should expose numeric metadata suitable for accessibility announcements', async () => { - const limiter = new RateLimiter(5, 60000); + it('should allow keyboard-focus compatible interactive states', async () => { + const limiter = new RateLimiter(1, 60000); - const result = await limiter.checkWithResult('127.0.0.2'); + const first = await limiter.check('test-ip'); + const second = await limiter.check('test-ip'); - expect(typeof result.limit).toBe('number'); - expect(typeof result.remaining).toBe('number'); - expect(typeof result.reset).toBe('number'); + expect(first).toBe(true); + expect(second).toBe(false); }); - it('should provide consistent feedback for allowlisted users', async () => { - const limiter = new RateLimiter(5, 60000); + it('should support allowlist accessibility bypass behavior', async () => { + const limiter = new RateLimiter(1, 60000); - limiter.allow('allow-ip'); + limiter.allow('allowed-ip'); - const result = await limiter.checkWithResult('allow-ip'); + const result = await limiter.checkWithResult('allowed-ip'); expect(result.success).toBe(true); - expect(result.remaining).toBe(result.limit); + expect(result.remaining).toBe(1); }); - it('should provide consistent feedback for blocklisted users', async () => { + it('should support blocked state announcement behavior', async () => { const limiter = new RateLimiter(5, 60000); limiter.block('blocked-ip'); @@ -45,14 +45,15 @@ describe('rate-limit accessibility compliance', () => { expect(result.remaining).toBe(0); }); - it('should return accessible rate-limit information from helper function', async () => { - const result = await rateLimit('helper-ip', 3, 60000); + it('should return valid rate limit response structure for screen reader consumers', async () => { + vi.stubEnv('KV_REST_API_URL', ''); + vi.stubEnv('KV_REST_API_TOKEN', ''); + + const result = await rateLimit('screen-reader-test', 3, 60000); - expect(result).toMatchObject({ - success: expect.any(Boolean), - limit: expect.any(Number), - remaining: expect.any(Number), - reset: expect.any(Number), - }); + expect(typeof result.success).toBe('boolean'); + expect(typeof result.limit).toBe('number'); + expect(typeof result.remaining).toBe('number'); + expect(typeof result.reset).toBe('number'); }); });