Skip to content

test(credit): add injectable clock and freeze time in credit suites (#1209) - #1335

Merged
greatest0fallt1me merged 2 commits into
Creditra:mainfrom
IbnNaseer:test/credit-frozen-clock
Oct 24, 2026
Merged

greatest0fallt1me merged 2 commits into
Creditra:mainfrom
IbnNaseer:test/credit-frozen-clock

Conversation

@IbnNaseer

Copy link
Copy Markdown
Contributor

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 with now() and nowMs().
  • src/test/freezeTime.ts: Created freezeTime() and unfreezeTime() 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

  • Replaced raw time reads: Swapped new Date() / Date.now() with clock.now() in Dashboard, CreditLines, TransactionHistory, CreditLineAging, and RepaymentSchedule.
  • Fixture stability: Anchored generateAprHistory and attestations in src/data/mockData.ts to FIXTURE_ANCHOR_DATE.

3. Test Suites & Documentation

  • Freezing credit suites: Integrated freezeTime() and cleanup hooks across:
    • Dashboard.test.tsx
    • CreditLines.test.tsx
    • RepayPage.test.tsx
    • RepaySuccess.test.tsx
    • DrawCreditPage.test.tsx
    • TransactionHistory.test.tsx
  • Testing documentation: Added Section 7 ("Credit Domain Clock & Time Pinning Policy") to docs/TESTING.md.
  • Fixes: Cleaned up pattern imports in TransactionStatus.tsx and router imports in RepayPage.tsx.

How to Verify

# Run unit & component test suites
npm test -- --run

# Run type check and production build
npm run build

…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
@drips-wave

drips-wave Bot commented Oct 22, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@IbnNaseer

Copy link
Copy Markdown
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
@greatest0fallt1me
greatest0fallt1me merged commit 69127bb into Creditra:main Oct 24, 2026
1 check passed
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.

Credit tests: freeze the clock for credit-lifecycle suites, because mockData and the pages read the real current date

2 participants