Skip to content

Feat/backend test coverage - #731

Open
AdEmOnD07 wants to merge 3 commits into
ritik4ever:mainfrom
AdEmOnD07:feat/backend-test-coverage
Open

Feat/backend test coverage#731
AdEmOnD07 wants to merge 3 commits into
ritik4ever:mainfrom
AdEmOnD07:feat/backend-test-coverage

Conversation

@AdEmOnD07

Copy link
Copy Markdown

Closes #636

Summary

This PR addresses issue #636 by increasing the backend test coverage to 81.41% branch coverage and 81.90% statement/line coverage. It fixes pre-existing runtime bugs and test failures, refactors the addPledge service to be synchronous, enforces strict CRC validation on Stellar public keys, and introduces a robust suite of new unit tests covering Express middlewares, route handlers, and refund/token balance logic.

Changes

Bug Fixes & Code Quality

  • Refactored campaignStore.ts: Made addPledge synchronous since its underlying SQLite database operations are synchronous. This resolves the Promise-spreading bug in index.ts that was stripping properties like id and deadline from active campaign responses.
  • Fixed test keys and schemas in schemas.ts & stellarAddress.test.ts:
    • Fixed a typo in the tests' main valid public key (GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWNV -> ending in 7).
    • Added .refine(isValidStellarPublicKey) checksum validation to Zod's stellarAccountIdSchema.
    • Updated all dummy/placeholder test keys to valid checksum-passing keys across the test suite to pass the refined Zod validation.
  • Fixed concurrent test states in campaignStore.concurrent.test.ts:
    • Corrected setup sequence by making pledges while campaign is open, then manually expiring the campaign in the database via SQL.
    • Wrapped synchronous calls in promise helper chains to simulate proper concurrent execution and corrected signature arguments for claimCampaign.
  • Fixed Windows database locks in historyEndpoint.test.ts: Included database resets (resetDbForTests()) in afterAll hooks to release active SQLite file locks, allowing clean test file deletion on Windows.
  • Removed empty integration.test.ts to prevent empty test suite collection errors.

New Unit Tests

  • middleware.test.ts: Added tests covering API key authorization checks, public route bypasses, cache misses/hits, cache invalidation, and mock Redis caching service states.
  • refundLogic.test.ts: Added tests covering contributor refund status constraints, database state updates, event recording, and group/multi-asset campaign token balance calculations.
  • routeHandlers.test.ts: Added tests covering configuration loading, open issues retrieval, leaderboard query limits, global statistics, payload-too-large 413 handling, and CORS-violation 403 handling.

Verification

Automated Tests

  • TypeScript build succeeds: npm run build
  • All tests compile and pass: npm run test (317 tests passed)
  • Scoped branch coverage of 81.41% (target >= 80% met): npm run test -- --coverage

@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

@AdEmOnD07 is attempting to deploy a commit to the ritik4ever's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@AdEmOnD07, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 45 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 41d93470-af0e-400e-9dba-11452e62b6c8

📥 Commits

Reviewing files that changed from the base of the PR and between 10f827c and be3ba9c.

⛔ Files ignored due to path filters (1)
  • backend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (31)
  • README.md
  • backend/src/api.test.ts
  • backend/src/config.ts
  • backend/src/historyEndpoint.test.ts
  • backend/src/index.test.ts
  • backend/src/index.ts
  • backend/src/logger.ts
  • backend/src/pledgesEndpoint.test.ts
  • backend/src/rateLimiter.test.ts
  • backend/src/requestId.test.ts
  • backend/src/security.test.ts
  • backend/src/services/__tests__/eventMetadata.test.ts
  • backend/src/services/__tests__/mutation.test.ts
  • backend/src/services/cache.ts
  • backend/src/services/campaignStore.concurrent.test.ts
  • backend/src/services/campaignStore.test.ts
  • backend/src/services/campaignStore.ts
  • backend/src/services/eventHistory.ts
  • backend/src/services/seedDeterministic.ts
  • backend/src/services/sorobanRpc.ts
  • backend/src/tests/middleware.test.ts
  • backend/src/tests/refundLogic.test.ts
  • backend/src/tests/routeHandlers.test.ts
  • backend/src/validation/schemas.test.ts
  • backend/src/validation/schemas.ts
  • backend/src/validation/stellarAddress.test.ts
  • backend/src/validation/urlSafety.ts
  • backend/tests/integration.test.ts
  • backend/vitest.config.ts
  • docs/ENVIRONMENT.md
  • pr-body.md

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@AdEmOnD07 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@ritik4ever

Copy link
Copy Markdown
Owner

Hi @AdEmOnD07,

This PR could not be merged because it has merge conflicts with the target branch.

Please resolve the merge conflicts, push the updated changes, and the PR can be reviewed and merged.

Thank you!

1 similar comment
@ritik4ever

Copy link
Copy Markdown
Owner

Hi @AdEmOnD07,

This PR could not be merged because it has merge conflicts with the target branch.

Please resolve the merge conflicts, push the updated changes, and the PR can be reviewed and merged.

Thank you!

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.

[FEATURE] Add backend unit test coverage to 80%+

2 participants