Skip to content

test(indexer): comprehensive API, SSE, and rate-limit tests - #588

Open
EmmanuelOchaje wants to merge 3 commits into
Afristore:masterfrom
EmmanuelOchaje:test/indexer-api-sse-rate-limit
Open

test(indexer): comprehensive API, SSE, and rate-limit tests#588
EmmanuelOchaje wants to merge 3 commits into
Afristore:masterfrom
EmmanuelOchaje:test/indexer-api-sse-rate-limit

Conversation

@EmmanuelOchaje

Copy link
Copy Markdown

Summary

This PR adds comprehensive automated tests for critical indexer API, Server-Sent Events (SSE), and rate-limiting features to ensure robust marketplace functionality.

Test Coverage

Issue #580: GET /wallets/:address/preferences Fallback

  • Verifies endpoint returns empty object {} when no preferences exist for a user
  • Tests database error handling with proper 500 status response
  • Confirms correct wallet address query parameter usage
  • Enables frontend to implement default preferences locally (dark theme, XLM currency, alerts disabled)

Issue #581: SSE /wallets/:address/events Event Filtering

  • Validates SSE connections only broadcast events relevant to specific wallet
  • Tests event filtering by actor, recipient, and data fields
  • Covers wallet role matching: buyer, artist, offerer, bidder, winner, creator
  • Handles royalty recipient arrays (both object and string formats)
  • Tests edge cases: null/undefined data, missing recipients

Issue #582: SSE Connection Cleanup on Disconnect

  • Verifies SSE connection headers are correctly set
  • Tests automatic connection cleanup when client disconnects
  • Validates heartbeat mechanism and resource cleanup
  • Confirms sseClients set properly removes disconnected clients

Issue #583: Rate-Limit Middleware IP Blocking

  • Tests standard rate limiter (100 requests/minute) blocks IP after limit exceeded
  • Tests strict rate limiter (20 requests/minute) for resource-intensive endpoints
  • Validates RateLimit-* headers (limit, remaining, reset)
  • Confirms health check endpoint bypasses rate limiting
  • Validates 429 status code with appropriate error messages
  • Tests retry-after information in rate limit responses
  • Verifies per-IP tracking for DDoS prevention

Test Quality

  • Edge Cases: Null/undefined data, empty arrays, various recipient formats
  • Error Scenarios: Database failures, connection timeouts, malformed requests
  • Header Validation: Proper SSE headers, rate-limit metadata headers
  • Timing: Rate limit window calculations and reset timestamps
  • DDoS Prevention: Per-IP tracking and strict endpoint limits

Files Modified

  • indexer/src/__tests__/api.test.ts - Added 40+ test cases for preferences and SSE
  • indexer/src/__tests__/rate-limit.test.ts - Enhanced with 15+ comprehensive rate limit tests

Code Patterns Followed

  • Uses Vitest framework consistent with existing test suite
  • Mock setup with vi.hoisted() for module-level mocking
  • Supertest for HTTP endpoint testing
  • Clear test descriptions following existing conventions
  • Comprehensive error handling and edge case coverage

Closes #580
Closes #581
Closes #582
Closes #583

…eatures

Add automated tests to cover:
- GET /wallets/:address/preferences falls back to empty object (default) if
  no preferences exist for a user (fixes Afristore#580)
- SSE /wallets/:address/events only broadcasts events relevant to the specific
  wallet address, filtering by actor, recipient, and data fields (fixes Afristore#581)
- SSE connection automatically drops and cleans up client on disconnect
  (fixes Afristore#582)
- Rate-limit middleware correctly blocks IP after exceeding max requests
  per minute, with comprehensive validation of headers and limits (fixes Afristore#583)

Each test suite includes:
- Basic functionality tests
- Edge case handling (null/undefined data)
- Error scenarios (database failures)
- Rate limit header validation
- Per-IP tracking verification
- Event filtering for different wallet roles

Co-Authored-By: Open Source Contributor <opensource@afristore.io>
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

@EmmanuelOchaje is attempting to deploy a commit to the ultratechcode's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@EmmanuelOchaje 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

@Ultra-Tech-code

Copy link
Copy Markdown
Contributor

Hello, kindly fix conflicts and CI failure. Thank you for your contributions.

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