Repository navigation
test(credit): add injectable clock and freeze time in credit suites (#1209) - #1335
Merged
greatest0fallt1me merged 2 commits intoOct 24, 2026
Merged
Conversation
…reditra#1209) - Add centralised injectable clock in src/lib/clock.ts with now() and nowMs() - Add freezeTime and unfreezeTime test helpers in src/test/freezeTime.ts - Anchor mockData.ts generateAprHistory and attestations to fixed reference date - Replace raw Date.now() and new Date() with clock in Dashboard, CreditLines, TransactionHistory, CreditLineAging, and RepaymentSchedule - Apply freezeTime across Dashboard, CreditLines, RepayPage, RepaySuccess, DrawCreditPage, and TransactionHistory test suites - Document credit domain frozen clock policy in docs/TESTING.md - Fix patterns.css import in TransactionStatus.tsx and react-router-dom import in RepayPage.tsx Resolves Creditra#1209
|
@IbnNaseer 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! 🚀 |
Contributor
Author
|
maintener review and merge pls |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # src/pages/CreditLines.tsx # src/pages/Dashboard.test.tsx # src/pages/Dashboard.tsx # src/pages/DrawCreditPage.test.tsx # src/pages/TransactionHistory.test.tsx # src/pages/__tests__/RepaySuccess.test.tsx
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
Resolves #1209
Credit lifecycle suites (
Dashboard,CreditLines,RepayPage,RepaySuccess,DrawCreditPage,TransactionHistory) depend on relative dates, due dates, repayment schedules, and aging tags. Because mock fixtures rely on fixed anchor dates, executing tests against floating host system time (Date.now()/new Date()) introduced date drift and flakiness across the credit test suites.This PR introduces a centralized, injectable clock utility, adds test helpers to pin system time deterministically, refactors components to consume the clock, and documents the credit domain time-pinning policy.
Changes
1. Centralized Clock & Test Helpers
src/lib/clock.ts: Introduced injectable clock utility withnow()andnowMs().src/test/freezeTime.ts: CreatedfreezeTime()andunfreezeTime()helpers pinning both fake timers (vi.setSystemTime) and the injectable clock to a canonical reference date (DEFAULT_FROZEN_TIME = '2025-02-25T12:00:00.000Z').2. Component & Mock Updates
new Date()/Date.now()withclock.now()inDashboard,CreditLines,TransactionHistory,CreditLineAging, andRepaymentSchedule.generateAprHistoryand attestations insrc/data/mockData.tstoFIXTURE_ANCHOR_DATE.3. Test Suites & Documentation
freezeTime()and cleanup hooks across:Dashboard.test.tsxCreditLines.test.tsxRepayPage.test.tsxRepaySuccess.test.tsxDrawCreditPage.test.tsxTransactionHistory.test.tsxdocs/TESTING.md.TransactionStatus.tsxand router imports inRepayPage.tsx.How to Verify