Commit 2709f27
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
- src
- __tests__
- app/api/results
- lib
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
0 commit comments