Repository navigation
test: add unit tests for cache warmer, request context, and signature utility - #745
Merged
DeFiVC merged 3 commits intoOct 21, 2026
Conversation
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.
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
tests/unit/cache/warmer.test.ts. Mockscourse.service.js,logger.js, andrequest-context.jsto isolatewarmCourseCache(). Covers single-page vs multi-page pagination (including the initial probe fetch used to learntotal), the zero-courses edge case, theuserId=nullcontract (warming must not depend on per-user enrollment data), success logging with the correctpagesWarmedcount, and error handling both on the initial probe fetch and partway through the warming loop, confirming the function never throws regardless of failure mode.tests/unit/utils/request-context.test.ts. CoversrunWithRequestContext/getRequestIdpropagation into synchronous code,setTimeoutcallbacks, 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 thatgetRequestId()returnsundefinedboth before any context runs and after a context's callback returns (no leakage).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.tshas no explicit input-validation branches (no checks onuserAddress/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
mainattests/unit/services/resilience.test.ts(not thetests/unit/stellar/resilience.test.tspath the issue specified). It imports from bothsrc/stellar/resilience.tsandsrc/utils/resilience.tsand already exercises retry behavior, circuit breaker open/half-open/close transitions (including per-operation-type isolation), timeout enforcement, and error classification viaisCircuitBreakerError. 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
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.upstream/mainbaseline (separate worktree, freshnpm ci), then diffed the sortedFAILlines 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 insignatures.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.