Skip to content

fix(video-calls): clamp list limit#327

Merged
ralyodio merged 2 commits into
profullstack:masterfrom
Jorel97:codex/fix-video-calls-limit-326
May 29, 2026
Merged

fix(video-calls): clamp list limit#327
ralyodio merged 2 commits into
profullstack:masterfrom
Jorel97:codex/fix-video-calls-limit-326

Conversation

@Jorel97
Copy link
Copy Markdown
Contributor

@Jorel97 Jorel97 commented May 29, 2026

Summary

  • normalize GET /api/video-calls limit to finite integer bounds before querying
  • clamp negative values to 1 and non-numeric values to the default 20
  • add regression coverage for invalid negative and non-numeric limit inputs

Fixes #326.

Testing

  • Not run locally: this workspace has Node but no npm/pnpm/npx/corepack available to install or invoke Vitest.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 29, 2026

Greptile Summary

This PR replaces the parseInt-based limit parsing in GET /api/video-calls with a dedicated parseLimit helper that handles null, empty, non-numeric, non-finite, negative, and oversized values safely, and adds four regression tests covering those cases.

  • route.ts: Adds parseLimit(value: string | null) that normalises the limit query parameter to a finite integer in [1, 50], defaulting to 20 when the input is absent, empty, or non-numeric, and uses Math.trunc to strip any fractional part.
  • route.test.ts: Adds four GET tests that spy on the Supabase .limit() call to assert the clamped value (-5 → 1, "abc" → 20, missing → 20, 999 → 50), covering both the lower and upper bounds addressed by the previous comment thread.

Confidence Score: 5/5

Safe to merge — the change is a small, self-contained input-normalisation fix with correct clamping logic and full regression test coverage for every boundary case.

The old parseInt/Math.min one-liner could silently forward NaN or negative integers to Supabase's .limit() call; the new parseLimit helper closes all those paths and is straightforward to audit. All four boundary cases (negative, non-numeric, missing, oversized) are now exercised by the new tests, and the Supabase mock faithfully mirrors the actual query chain.

No files require special attention.

Important Files Changed

Filename Overview
src/app/api/video-calls/route.ts Adds parseLimit helper replacing the old parseInt one-liner; correctly handles null, empty, NaN, Infinity, negative, and oversized values via a three-step Number/isFinite/clamp chain.
src/app/api/video-calls/route.test.ts Adds four GET limit tests (negative clamp, non-numeric default, missing param default, upper-bound cap) with a spy-based mock that correctly mirrors the select→or→order→limit Supabase chain.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["parseLimit(value)"] --> B{"value is null\nor empty/whitespace?"}
    B -- "yes" --> C["parsed = Number(20) = 20"]
    B -- "no" --> D["parsed = Number(value)"]
    D --> E{"Number.isFinite(parsed)?"}
    E -- "no (NaN / Infinity)" --> F["finiteValue = 20"]
    E -- "yes" --> G["finiteValue = parsed"]
    C --> G
    F --> H["Math.trunc(finiteValue)"]
    G --> H
    H --> I["Math.max(truncated, 1)"]
    I --> J["Math.min(clamped, 50)"]
    J --> K["return limit in [1, 50]"]
Loading

Reviews (2): Last reviewed commit: "test(video-calls): cover limit boundarie..." | Re-trigger Greptile

Comment thread src/app/api/video-calls/route.test.ts
@ralyodio ralyodio merged commit 1812014 into profullstack:master May 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Video calls list accepts invalid limit values

2 participants