Skip to content

test(pr-insights): Enhance mock-integrations tests for async service layer and local cache stubs#8094

Open
soumyasekharshee265-ux wants to merge 2 commits into
JhaSourav07:mainfrom
soumyasekharshee265-ux:test/pr-insights-route-mock-integrations-6781
Open

test(pr-insights): Enhance mock-integrations tests for async service layer and local cache stubs#8094
soumyasekharshee265-ux wants to merge 2 commits into
JhaSourav07:mainfrom
soumyasekharshee265-ux:test/pr-insights-route-mock-integrations-6781

Conversation

@soumyasekharshee265-ux

Copy link
Copy Markdown
Contributor

Description

Fixes #6781

This PR adds the new test file app/api/pr-insights/route.mock-integrations.test.ts targeting Asynchronous Service Layer Mocking & Local Cache Stubs for the app/api/pr-insights/route.ts route (Variation 9).

The tests use vi.mock() to stub every async boundary the route depends on — the PR insights service, the local GitHub token cache, the client IP resolver, and the abort-error type guard — so the suite stays hermetic, deterministic, and offline.

What is covered (5 test cases)

  1. Standard async imports resolve — verifies the mocked fetchPRInsights service is invoked once with the trimmed username and returns the mocked payload with a 200 status.
  2. Local cache queried before remote retrieval — asserts getUserGitHubToken (local cache layer) executes before fetchPRInsights (remote fetch) and that the cached token is forwarded to the downstream call.
  3. Fallback on upstream timeout / abort — simulates the AbortController firing and confirms the route returns a 504 with the correct timeout message.
  4. Complete success callback path — full happy-path sync from token lookup → async service → JSON response body.
  5. Non-abort errors propagate as 500 — a database retrieval failure surfaces as 500 with the underlying error message.

Verification

  • npm run test -- app/api/pr-insights/route.mock-integrations.test.ts5/5 passing
  • npm run format → clean ✅
  • npm run lint0 errors in the new file ✅
  • Single atomic commit following Conventional Commits ✅

Note: The unrelated pre-existing failures in app/api/streak/route.timezone-boundaries.test.ts and flaky timing assertions in utils/trustedProxy.test.ts also fail/flake on main and are not caused by this PR.

Pillar

Visual Preview

Not applicable — this PR adds unit tests only and does not touch any SVG output or UI.

Checklist before requesting a review:

  • I have read the CONTRIBUTING.md file.
  • I have tested these changes locally (npm run test -- app/api/pr-insights/route.mock-integrations.test.ts — all 5 tests pass).
  • I have run npm run format and npm run lint locally and resolved all errors (CI will fail otherwise).
  • My commits follow the Conventional Commits format (e.g., feat(themes): ..., fix(calculate): ...).
  • I have updated README.md if I added a new theme or URL parameter. (N/A — no new theme or URL parameter added)
  • I have starred the repo.
  • I have made sure that i have only one commit to merge in this PR.
  • The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). (N/A — tests only)
  • (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.

@retenta-bot

retenta-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

This PR adds important test coverage for the asynchronous service layer and local cache stubs in the PR insights route. It follows a similar approach to previous decisions made regarding mock integrations, such as the tests added for types and wrapped API routes. This ensures that our testing strategy remains consistent and effective. Thank you for your contribution!

@retenta-bot retenta-bot Bot changed the title test(pr-insights): add mock-integrations tests for async service layer and local cache stubs test(pr-insights): Enhance mock-integrations tests for async service layer and local cache stubs Jul 15, 2026
@github-actions github-actions Bot added the status:blocked This PR is blocked due to a failing CI check. label Jul 15, 2026
@soumyasekharshee265-ux

Copy link
Copy Markdown
Contributor Author

Hi maintainers 👋

The failing TypeScript Type Check job is caused by pre-existing errors on main — not by this PR.

Running npm run typecheck locally on a clean main (before my changes) produces the same 4 errors in unrelated files:

app/generator/components/EditorPanel.type-compiler.test.tsx:8:50 — TS2344
app/generator/components/PreviewPanel.type-compiler.test.tsx:13:45 — TS2344
lib/rss.ts:1:20 — TS2307 (Cannot find module 'rss-parser')
lib/rss.ts:36:50 — TS7006 (Parameter 'item' implicitly has 'any' type)

None of these files are touched by this PR. My changes are limited to a single new test file:
app/api/pr-insights/route.mock-integrations.test.ts

Verification that my change is clean:

  • npm run test -- app/api/pr-insights/route.mock-integrations.test.ts → 5/5 tests passing
  • npm run lint → 0 errors in the new file
  • npm run format → clean
  • ✅ Single atomic commit following Conventional Commits

Could you please advise whether:

  1. I should wait for main to be fixed and rebase, or
  2. Someone can trigger a re-run once main is patched?

Happy to help fix the type errors on main in a separate PR if that's preferred. Thanks! 🙏

@github-actions github-actions Bot removed the status:blocked This PR is blocked due to a failing CI check. label Jul 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Size Report (Gzipped Sizes)

✨ No significant bundle size changes detected.

📊 Summary of Totals

Category PR Size Base Size Difference
Total JS 3958.92 KB 3958.92 KB 0 B
Total CSS 327.67 KB 327.67 KB 0 B

@Aamod007 Aamod007 added level:intermediate Moderate complexity tasks quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. type:testing Adding, updating, or fixing tests mentor:Aamod007 labels Jul 17, 2026

@Aamod007 Aamod007 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work on the mock integrations test for PR insights. Testing the async service layer boundaries and local cache fallback behaviors adds great stability. However, the Vercel check is failing. Please resolve the issues and rerun the CI pipeline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:intermediate Moderate complexity tasks mentor:Aamod007 quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. type:testing Adding, updating, or fixing tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(ApiPr-insightsRoute-mock-integrations): verify Asynchronous Service Layer Mocking & Local Cache Stubs (Variation 9)

2 participants