Skip to content

test: add unit tests for LoggingInterceptor, HttpExceptionFilter, Sta… - #169

Open
yahia008 wants to merge 1 commit into
stellar-vortex-protocol:mainfrom
yahia008:test/logging-interceptor-http-exception-filter-stats-service-unit-tests
Open

test: add unit tests for LoggingInterceptor, HttpExceptionFilter, Sta…#169
yahia008 wants to merge 1 commit into
stellar-vortex-protocol:mainfrom
yahia008:test/logging-interceptor-http-exception-filter-stats-service-unit-tests

Conversation

@yahia008

Copy link
Copy Markdown

Title:

test: add unit tests for LoggingInterceptor, HttpExceptionFilter, and StatsService

Description:

Summary

Adds missing unit test coverage for three untested modules across the codebase.


LoggingInterceptor (src/common/logging.interceptor.spec.ts)

  • Verifies the log message format is METHOD URL STATUS Nms
  • Asserts the response stream passes through unchanged
  • Confirms no log is emitted when the handler errors (error propagates to subscriber)
  • Checks statusCode is read inside the tap callback, not captured at intercept time
  • Covers multi-value observable streams and non-negative duration values

HttpExceptionFilter (src/common/http-exception.filter.spec.ts)

Tests all four distinct response-shape branches explicitly:

  • Branch 1 — string body → { error: string }
  • Branch 2 — validation-array body (message: string[]) → { error: "Validation failed", details: [...] }
  • Branch 3 — custom-shaped body with error string passes through as-is
  • Branch 4 — object body with a string message{ error: message }
  • Branch 5 — non-HttpException errors → 500, logger.error called; non-Error throws and null handled gracefully

StatsService (src/stats/stats.service.spec.ts)

Covers all aggregation edge cases:

  • Empty store all-zero guard
  • totalVolume BigInt reduce with missing fillAmount, large precision values beyond Number.MAX_SAFE_INTEGER, result always returned as a string
  • avgFillTime with no filled intents, all filledAt unset, correct rounding, and exclusion of intents missing filledAt
  • fillRate divide-by-zero guard (intents.length === 0 → 0)
  • uniqueUsers deduplication via Set
  • activeSolvers filtering by isActive: true

Closes #101
Closes #102
Closes #103

…tsService

- src/common/logging.interceptor.spec.ts (stellar-vortex-protocol#103)
  - verifies log message format (METHOD URL STATUS Nms)
  - asserts response stream passes through unchanged
  - confirms no log emitted on handler error
  - checks statusCode is read at tap time, not intercept time

- src/common/http-exception.filter.spec.ts (stellar-vortex-protocol#102)
  - branch 1: string body → { error: string }
  - branch 2: validation-array body → { error: 'Validation failed', details }
  - branch 3: custom-shaped body passes through as-is
  - branch 4: object body with string message → { error: message }
  - branch 5: non-HttpException Error → 500, logger.error called
  - non-Error throw and null throw handled gracefully

- src/stats/stats.service.spec.ts (stellar-vortex-protocol#101)
  - empty-store all-zero guard
  - totalVolume BigInt reduce, missing fillAmount, large precision values
  - avgFillTime edge cases: no fills, filledAt unset, correct rounding
  - fillRate divide-by-zero guard (intents.length === 0)
  - uniqueUsers deduplication, activeSolvers filtering
@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

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

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.

Add unit tests for LoggingInterceptor Add unit tests for HttpExceptionFilter Add unit tests for StatsService.getProtocolStats()

1 participant