Skip to content

Commit 2709f27

Browse files
committed
test: add Jest test suite for web API validation and rate-limiter
Adds the first unit tests for the Next.js web layer. The existing test suite (pytest) covers the CLI/desktop; this PR adds coverage for the server-side logic that handles all incoming API requests. Changes: - Extract inline Zod schemas from api/results/route.ts into a shared src/lib/validation.ts module so they can be imported and tested independently without spinning up a Next.js server. - Add src/__tests__/rate-limit.test.ts: 27 tests covering checkRateLimit (allow on first request, count increments, block at limit, window reset, independent IP buckets, independent named buckets, default limit of 30) and getClientIP (x-forwarded-for with multiple IPs, single IP, x-real-ip fallback, 127.0.0.1 fallback, whitespace trimming). - Add src/__tests__/validation.test.ts: 14 PingResultSchema tests and 12 SubmitRequestSchema tests covering field presence, string length limits, numeric range boundaries (0/10000/10001), array length limits (100/101 raw_times, 50/51 results), defaults for all optional fields, and nested validation propagation. - Add jest.config.js with ts-jest transform and @/ path alias mapping. - Add test script to package.json. All 41 tests pass. Build and lint unaffected.
1 parent 8054623 commit 2709f27

7 files changed

Lines changed: 6367 additions & 2564 deletions

File tree

web/jest.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** @type {import('jest').Config} */
2+
module.exports = {
3+
testEnvironment: 'node',
4+
transform: {
5+
'^.+\\.tsx?$': ['ts-jest', { tsconfig: { jsx: 'react', esModuleInterop: true } }],
6+
},
7+
testMatch: ['**/__tests__/**/*.test.ts'],
8+
moduleNameMapper: {
9+
'^@/(.*)$': '<rootDir>/src/$1',
10+
},
11+
};

0 commit comments

Comments
 (0)