From 666bd04e6850c4c6210ad0ee7fc04fc585760d0e Mon Sep 17 00:00:00 2001 From: Aric Camarata Date: Sun, 25 Oct 2026 14:58:54 -0400 Subject: [PATCH] fix(frontend): make the trial subscription summary test clock-independent 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. --- .../subscription-state-machine.test.ts | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/frontend/src/lib/billing/__tests__/subscription-state-machine.test.ts b/frontend/src/lib/billing/__tests__/subscription-state-machine.test.ts index be29afed..1cf7b404 100644 --- a/frontend/src/lib/billing/__tests__/subscription-state-machine.test.ts +++ b/frontend/src/lib/billing/__tests__/subscription-state-machine.test.ts @@ -1029,19 +1029,33 @@ describe("getSubscriptionSummary", () => { expect(summary.canPause).toBe(true); }); - it("should create summary for trial subscription", () => { - const trialEndsAt = new Date(); - trialEndsAt.setDate(trialEndsAt.getDate() + 7); + describe("trial subscription", () => { + const DAY_MS = 24 * 60 * 60 * 1000; - const subscription = createTestSubscription({ - state: "trial", - trialEndsAt, + afterEach(() => { + jest.useRealTimers(); }); - const summary = getSubscriptionSummary(subscription); + // Fixed clocks, including one a week before the US DST fall-back + // (2026-11-01), where "now + 7 calendar days" is 7 days + 1 hour apart. + it.each([ + "2026-06-15T12:00:00.000Z", + "2026-10-25T01:28:00.000Z", + "2027-01-31T23:59:59.000Z", + ])("should create summary for trial subscription (now=%s)", (nowIso) => { + jest.useFakeTimers().setSystemTime(new Date(nowIso)); + const trialEndsAt = new Date(Date.now() + 7 * DAY_MS); - expect(summary.isInTrial).toBe(true); - expect(summary.trialDaysRemaining).toBe(7); + const subscription = createTestSubscription({ + state: "trial", + trialEndsAt, + }); + + const summary = getSubscriptionSummary(subscription); + + expect(summary.isInTrial).toBe(true); + expect(summary.trialDaysRemaining).toBe(7); + }); }); it("should indicate canceling state", () => {