Skip to content

fix(frontend): make the trial subscription summary test clock-independent - #215

Merged
acamarata merged 1 commit into
mainfrom
dw3-nchat-1
Oct 25, 2026
Merged

acamarata merged 1 commit into
mainfrom
dw3-nchat-1

Conversation

@acamarata

Copy link
Copy Markdown
Collaborator

Problem

getSubscriptionSummary › should create summary for trial subscription started failing on main from 2026-10-25 (Expected 7, received 8) under TZ America/New_York.

Cause

The test built the trial end with setDate(getDate() + 7). In America/New_York the DST fall-back is 2026-11-01, so from 2026-10-25 that is 7 days + 1 hour of elapsed time. BillingCycleCalculator.calculateTrialDaysRemaining rounds elapsed time up, so it returned 8. The product code is correct; the test depended on the wall clock and local timezone.

Fix

Test only. The case now freezes the clock with jest.useFakeTimers().setSystemTime(...) (real timers restored in afterEach) and uses an exact 7 x 24h offset. The assertion (trialDaysRemaining === 7) is unchanged. It runs against three fixed clocks, including 2026-10-25T01:28Z, the one that failed.

Verification

  • Before: fails on today's date in TZ=America/New_York (8 vs 7).
  • After: suite passes (75/75) in TZ=America/New_York and TZ=UTC; result no longer depends on the system date.

Coverage note (not changed here)

The "global coverage threshold not met" lines in the failing run come from bail: process.env.CI ? 1 : 0 in frontend/jest.config.js: jest stopped after the first failure (66 of 710 suites ran), so coverage was only 7%. Not a real regression.

…dent

The test built its trial end with setDate(+7), which is 7 days + 1 hour away when the window crosses the US DST fall-back (2026-11-01). The code rounds up elapsed time, so it returned 8 in America/New_York from 2026-10-25. Freeze the clock with fake timers and use exact 24h offsets; the product code is correct.
@acamarata
acamarata merged commit 783f1c7 into main Oct 25, 2026
33 of 34 checks passed
@github-actions

Copy link
Copy Markdown

Coverage after merging dw3-nchat-1 into main will be

30.31%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   middleware.ts0%0%0%0%100, 100, 108, 116–117, 117–118, 122–123, 123–124, 128–129, 129–130, 133, 141, 143–144, 144, 144, 144–145, 151–152, 152–154, 154, 154, 154–156, 156–157, 157, 157, 16, 162, 164, 172, 179–181, 196, 198, 198, 198, 200, 204, 204, 21, 210, 210, 210, 210, 210, 210, 217, 217, 220, 230, 233, 236–240, 246, 246–247, 254, 256, 26, 262–263, 266, 266–267, 272–273, 278, 282, 282, 282, 282, 282, 284, 288, 290, 290–292, 295, 295–296, 303, 306, 306, 306, 306, 306, 306, 312–313, 313, 313, 317–318, 318, 318–319, 322, 322, 324, 324–325, 325, 325, 325, 325, 331–332, 334–335, 339, 339, 341, 341–345, 349, 349, 349, 349–350, 350, 352–355, 360–361, 365–366, 372, 40, 45, 50, 55, 60, 66–67, 67–68, 70, 70, 70, 78, 85, 92, 99
src/app
   error.tsx0%100%0%0%16–17, 19, 3–5
   layout.tsx0%0%0%0%10, 107, 123, 147, 150, 2, 20, 20, 20, 22, 22, 22, 226, 226, 24, 3–5, 8
   loading.tsx0%100%0%0%1, 7
   not-found.tsx0%100%0%0%1, 7
   page.tsx0%0%0%0%3, 35–38, 4, 40, 40, 40, 42–43, 43, 46, 46–48, 5, 52, 52, 52, 52, 52, 54, 54–55, 57, 6, 60–61, 65, 7, 73
src/app/(authenticated)/bookmarks
   page.tsx0%100%0%0%10–12, 14, 9
src/app/activity
   page.tsx0%0%0%0%10, 113, 113, 134, 142, 142, 147, 16, 162, 162, 162, 167, 167, 167, 17, 171, 18, 184, 186, 186, 189, 191, 191, 191, 191–193, 198, 205, 205, 210, 210, 222, 229, 229, 58, 74, 77, 80, 80–81, 9, 91–92
src/app/admin
   loading.tsx0%0%0%0%1, 104, 2–3, 38, 42, 42, 77, 9, 91
   page.tsx0%0%0%0%100–101, 103–104, 104, 104, 104, 104–105, 109–111, 111, 111, 111, 111–112, 115, 115, 115, 115, 115–116, 17–19, 199, 20–21, 239, 248, 248, 251, 251, 257, 261, 261, 28–29, 3, 30–31, 36, 39, 4, 43, 5, 52, 6–7, 90, 97–99
src/app/admin/advanced
   page.tsx0%0%0%0%106–110, 112–113, 113, 113, 113, 113–114, 118, 118, 118, 118, 118–119, 14–15, 25–26, 33–38, 392, 394, 41–45, 48, 77
src/app/admin/analytics
   page.tsx0%0%0%0%100, 100, 100, 100, 100, 103–107, 117, 124–125, 125, 130, 133, 133, 133–135, 135–137, 141, 141, 141–143, 143–145, 15, 154–159, 16, 160, 160, 163, 167–168, 168, 168–169, 169, 169, 17, 171, 171, 171, 173, 177, 18, 181–182, 182–183, 191, 193, 196, 196, 196–197, 200, 200, 208–209, 209–210, 216, 219, 219, 224–226, 226, 226–228, 228, 228, 230, 25, 256–257, 259, 26, 263, 265–266, 269, 271–279, 282, 282, 3, 313, 33, 331, 331, 34–36, 4, 41, 44, 49, 5, 52, 57, 60, 65, 68, 73, 76, 81, 84, 88, 96–98
src/app/admin/audit
   page.tsx0%0%0%0%116–117, 119–120, 123, 123, 123, 123, 123, 123, 125, 127, 129–130, 132, 134, 136, 138, 140, 143–144, 147, 149, 149, 149, 151, 151, 155, 163, 163, 171, 171, 177, 177, 189, 19, 196–198, 206, 209, 21, 211–212, 215–216, 216, 216, 216, 216–217, 22, 222–223, 225–229, 23, 233–234, 236–240, 243–244, 247–250, 252–255, 258, 258, 258, 258, 258–259, 263–267, 28, 289, 289, 291, 291, 299, 30, 303, 305, 305, 307, 307, 31, 322, 322, 43, 50, 59–60, 67, 7, 73, 79, 8, 80, 88, 9
src/app/admin/audit/security
   page.tsx0%0%0%0%10, 114, 12, 122, 13, 136, 136, 136, 140, 148, 148, 148, 15,

@github-actions

Copy link
Copy Markdown

Security Scan Results: PASSED

Scanner Critical High
SAST 0 0
Dependencies 0 0

@github-actions

Copy link
Copy Markdown

PR Checks Summary

Check Status
Lint & Format ✅ success
Type Check ✅ success
Unit Tests ✅ success
Build ✅ success

✅ All checks passed! Ready for review.

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.

1 participant