fix: provide real checkColdStatus in wfOpportunity mock, remove stray closing brace
This commit is contained in:
@@ -88,16 +88,47 @@ mock.module("../../src/services/cw.opportunityService", () => ({
|
||||
submitTimeEntry: mockSubmitTimeEntry,
|
||||
}));
|
||||
|
||||
const mockCheckColdStatus = mock(() => ({ cold: false, triggeredBy: null }));
|
||||
const REAL_COLD_THRESHOLDS: Record<number, { days: number; ms: number }> = {
|
||||
43: { days: 14, ms: 14 * 24 * 60 * 60 * 1000 },
|
||||
57: { days: 30, ms: 30 * 24 * 60 * 60 * 1000 },
|
||||
};
|
||||
|
||||
const REAL_STATUS_NAMES: Record<number, string> = {
|
||||
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,
|
||||
}));
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user