Skip to content

test: add unit tests for cache warmer, request context, and signature utility - #745

Merged
DeFiVC merged 3 commits into
ChainLearnOfficial:mainfrom
Ejere:test/chainlearn-api-unit-tests-batch-chizube
Oct 21, 2026
Merged

DeFiVC merged 3 commits into
ChainLearnOfficial:mainfrom
Ejere:test/chainlearn-api-unit-tests-batch-chizube

Conversation

@Ejere

@Ejere Ejere commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This batch adds the missing unit tests called for by three test-coverage issues. A fourth issue in the batch (resilience utilities) was found already covered on main at a different file path, so it is flagged rather than duplicated.

closes #584
closes #585
closes #587
closes #586

Changes

  • Add unit tests for cache warmer #584 - Add unit tests for cache warmer: New tests/unit/cache/warmer.test.ts. Mocks course.service.js, logger.js, and request-context.js to isolate warmCourseCache(). Covers single-page vs multi-page pagination (including the initial probe fetch used to learn total), the zero-courses edge case, the userId=null contract (warming must not depend on per-user enrollment data), success logging with the correct pagesWarmed count, and error handling both on the initial probe fetch and partway through the warming loop, confirming the function never throws regardless of failure mode.
  • Add unit tests for request context utility #585 - Add unit tests for request context utility: New tests/unit/utils/request-context.test.ts. Covers runWithRequestContext/getRequestId propagation into synchronous code, setTimeout callbacks, and microtasks (Promise.resolve().then); isolation between sequential and concurrently-running contexts; correct resolution of nested contexts (inner value wins inside the nested call, outer value is restored after); and that getRequestId() returns undefined both before any context runs and after a context's callback returns (no leakage).
  • Add unit tests for Stellar signatures utility #587 - Add unit tests for Stellar signatures utility: Extended the existing tests/unit/stellar/signatures.test.ts (it already covered the happy path for both functions) with tests for nonce uniqueness, the actual mechanism that makes two calls with identical business inputs produce different signatures/hashes, which is the single-use guarantee the module's own docstring describes, plus ISO-8601 timestamp format, and the hash's 64-character hex SHA-256 shape. src/stellar/signatures.ts has no explicit input-validation branches (no checks on userAddress/quizId/score), so the issue's "tests for input validation" criterion isn't literally satisfiable without adding validation logic that's out of scope for a tests-only issue; this batch covers everything the module actually does instead of asserting on validation that doesn't exist.

#586 (resilience utilities) was found already covered on main at tests/unit/services/resilience.test.ts (not the tests/unit/stellar/resilience.test.ts path the issue specified). It imports from both src/stellar/resilience.ts and src/utils/resilience.ts and already exercises retry behavior, circuit breaker open/half-open/close transitions (including per-operation-type isolation), timeout enforcement, and error classification via isCircuitBreakerError. No change needed; left out of this batch. Flagging so the issue can be closed/confirmed by a maintainer independent of this PR.

Test plan

  • All three new/extended test files pass in isolation: npx vitest run tests/unit/cache/warmer.test.ts tests/unit/utils/request-context.test.ts tests/unit/stellar/signatures.test.ts, 25 tests, all green.
  • Ran the full suite on this branch and on a clean upstream/main baseline (separate worktree, fresh npm ci), then diffed the sorted FAIL lines from each: identical 89 failing test files/cases in both, all pre-existing (e2e/integration tests and a handful of unit tests that need a live DB/Redis connection unavailable in this environment). Zero new failures introduced by this PR.
  • npm run lint: 0 errors (329 pre-existing warnings repo-wide, none introduced by the files in this diff, verified by linting just the touched files, which shows only one pre-existing unused-var warning on an unrelated, unmodified line in signatures.test.ts).

Did not run against a live Postgres/Redis instance locally, the pre-existing e2e/integration failures on both branches are consistent with that infrastructure being unavailable here, not with a real regression.

Ejere added 3 commits October 21, 2026 07:54
Cover warmCourseCache()'s pagination (single page, multiple pages, zero
courses), the userId=null contract, success logging, and error handling
for both the initial probe fetch and a later page in the warming loop.
…ficial#585)

Cover runWithRequestContext/getRequestId's propagation to async operations
and microtasks, isolation between sequential and concurrent contexts,
nested-context resolution, and behavior outside of any context.
…age (ChainLearnOfficial#587)

createQuizProof and createMintAuthorization already had tests covering the
happy path; add coverage for nonce uniqueness (what makes two calls with
identical business inputs produce different signatures), ISO timestamp
format, and the hash's hex/length shape.
@drips-wave

drips-wave Bot commented Oct 21, 2026

Copy link
Copy Markdown

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

@DeFiVC
DeFiVC merged commit 1e6c39f into ChainLearnOfficial:main Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants