From e29479185808f14a1637ae55dda12e13ac8f005d Mon Sep 17 00:00:00 2001 From: Jackson Roberts Date: Mon, 9 Mar 2026 03:29:00 -0500 Subject: [PATCH] fix: provide real checkColdStatus in wfOpportunity mock, remove stray closing brace --- tests/unit/wfOpportunity.test.ts | 45 +++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/tests/unit/wfOpportunity.test.ts b/tests/unit/wfOpportunity.test.ts index 9a48c93..0cc5d01 100644 --- a/tests/unit/wfOpportunity.test.ts +++ b/tests/unit/wfOpportunity.test.ts @@ -88,16 +88,47 @@ mock.module("../../src/services/cw.opportunityService", () => ({ submitTimeEntry: mockSubmitTimeEntry, })); -const mockCheckColdStatus = mock(() => ({ cold: false, triggeredBy: null })); +const REAL_COLD_THRESHOLDS: Record = { + 43: { days: 14, ms: 14 * 24 * 60 * 60 * 1000 }, + 57: { days: 30, ms: 30 * 24 * 60 * 60 * 1000 }, +}; + +const REAL_STATUS_NAMES: Record = { + 43: "QuoteSent", + 57: "ConfirmedQuote", +}; + +/** Real checkColdStatus implementation — used as the default so that + * algoColdThreshold.test.ts gets the real function if it loads after us. */ +function realCheckColdStatus(input: { + statusCwId: number | null; + lastActivityDate: Date | null; + now?: Date; +}) { + const NOT_COLD = { cold: false as const, triggeredBy: null }; + if (!input.statusCwId) return NOT_COLD; + const threshold = REAL_COLD_THRESHOLDS[input.statusCwId]; + if (!threshold) return NOT_COLD; + if (!input.lastActivityDate) return NOT_COLD; + const now = input.now ?? new Date(); + const elapsed = now.getTime() - input.lastActivityDate.getTime(); + if (elapsed < threshold.ms) return NOT_COLD; + return { + cold: true as const, + triggeredBy: { + statusCwId: input.statusCwId, + statusName: REAL_STATUS_NAMES[input.statusCwId] ?? "Unknown", + thresholdDays: threshold.days, + staleDays: Math.floor(elapsed / (24 * 60 * 60 * 1000)), + }, + }; +} + +const mockCheckColdStatus = mock(realCheckColdStatus); mock.module("../../src/modules/algorithms/algo.coldThreshold", () => ({ checkColdStatus: mockCheckColdStatus, - // Include all named exports to avoid poisoning other test files that - // import COLD_THRESHOLDS or types from this module. - COLD_THRESHOLDS: { - 43: { days: 14, ms: 14 * 24 * 60 * 60 * 1000 }, - 57: { days: 30, ms: 30 * 24 * 60 * 60 * 1000 }, - }, + COLD_THRESHOLDS: REAL_COLD_THRESHOLDS, })); // ---------------------------------------------------------------------------