## test: add unit tests for cache-analytics, cache-optimization, and transaction-helper services - #1388
Merged
Merged
Conversation
Co-Authored-By: Codebuff <noreply@codebuff.com>
…onService Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@DevMuhdishaq 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! 🚀 |
… transaction-helper services ### Summary Adds focused unit tests for three services that previously had no test coverage, verifying their public APIs with both happy-path and edge-case scenarios. ### What changed | File | Tests | Covers | |---|---|---| | `src/caching/cache-analytics.service.spec.ts` | 43 | `recordHit`, `recordMiss`, `recordSet`, `getRecommendedTTL`, `generateAnalyticsReport`, `applyAdaptiveTTLAdjustments`, `cleanupOldMetrics`, event handlers, TTL recommendations, cost scoring | | `src/caching/cache-optimization.service.spec.ts` | 25 | `get`, `set`, `del`, `optimizeCache`, config get/update, default TTL selection per prefix, adaptive TTL, error handling | | `src/common/database/transaction-helper.service.spec.ts` | 32 | `executeInTransaction`, `executeWithRollback`, savepoint CRUD, `isInTransaction`, `getIsolationLevel`, timeout setters, input validation | **Total: 100 tests across 3 files, all passing.** ### Edge cases tested - Corrupt/unparseable Redis metrics data - Redis connection failures (graceful fallback) - Transaction rollback on operation failure (including commit failure) - Savepoint name validation - Conditional operation skipping in `executeWithRollback` - Rollback function failure handling - Disabled feature flags (adaptive TTL, hit rate optimization, memory optimization) - Cache-manager error handling across `get`/`set`/`del` ### Validation ``` npx jest src/caching/cache-analytics.service.spec.ts --forceExit # 43/43 passed npx jest src/caching/cache-optimization.service.spec.ts --forceExit # 25/25 passed npx jest src/common/database/transaction-helper.service.spec.ts --forceExit # 32/32 passed ```
Contributor
|
Thank you for contributing to the project. |
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.
Closes #1270
Summary
Adds focused unit tests for three services that previously had no test coverage, verifying their public APIs with both happy-path and edge-case scenarios.
Closes #1271
What changed
src/caching/cache-analytics.service.spec.tsrecordHit,recordMiss,recordSet,getRecommendedTTL,generateAnalyticsReport,applyAdaptiveTTLAdjustments,cleanupOldMetrics, event handlers, TTL recommendations, cost scoringsrc/caching/cache-optimization.service.spec.tsget,set,del,optimizeCache, config get/update, default TTL selection per prefix, adaptive TTL, error handlingsrc/common/database/transaction-helper.service.spec.tsexecuteInTransaction,executeWithRollback, savepoint CRUD,isInTransaction,getIsolationLevel, timeout setters, input validationTotal: 100 tests across 3 files, all passing.
Closes #1273
Edge cases tested
executeWithRollbackget/set/delValidation
Closes #1274