bypass checkColdStatus — always returns not-cold until feature ready
This commit is contained in:
@@ -96,28 +96,7 @@ const STATUS_NAMES: Record<number, string> = {
|
|||||||
*
|
*
|
||||||
* @returns A `ColdCheckResult` indicating cold status and trigger metadata.
|
* @returns A `ColdCheckResult` indicating cold status and trigger metadata.
|
||||||
*/
|
*/
|
||||||
export function checkColdStatus(input: ColdCheckInput): ColdCheckResult {
|
export function checkColdStatus(_input: ColdCheckInput): ColdCheckResult {
|
||||||
const NOT_COLD: ColdCheckResult = { cold: false, triggeredBy: null };
|
// Bypassed — always returns not-cold until cold-stall feature is ready
|
||||||
|
return { cold: false, triggeredBy: null };
|
||||||
if (!input.statusCwId) return NOT_COLD;
|
|
||||||
|
|
||||||
const threshold = 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,
|
|
||||||
triggeredBy: {
|
|
||||||
statusCwId: input.statusCwId,
|
|
||||||
statusName: STATUS_NAMES[input.statusCwId] ?? "Unknown",
|
|
||||||
thresholdDays: threshold.days,
|
|
||||||
staleDays: Math.floor(elapsed / (24 * 60 * 60 * 1000)),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* Tests for src/modules/algorithms/algo.coldThreshold.ts
|
* Tests for src/modules/algorithms/algo.coldThreshold.ts
|
||||||
*
|
*
|
||||||
* Pure function — no mocking needed.
|
* checkColdStatus is currently bypassed (always returns not-cold).
|
||||||
|
* COLD_THRESHOLDS config is still tested.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, test, expect } from "bun:test";
|
import { describe, test, expect } from "bun:test";
|
||||||
@@ -24,106 +25,20 @@ describe("COLD_THRESHOLDS", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("checkColdStatus", () => {
|
describe("checkColdStatus (bypassed)", () => {
|
||||||
test("returns not cold when statusCwId is null", () => {
|
test("always returns not-cold regardless of input", () => {
|
||||||
const result = checkColdStatus({
|
// With null status
|
||||||
statusCwId: null,
|
expect(checkColdStatus({ statusCwId: null, lastActivityDate: new Date() }))
|
||||||
lastActivityDate: new Date(),
|
.toEqual({ cold: false, triggeredBy: null });
|
||||||
});
|
|
||||||
expect(result.cold).toBe(false);
|
|
||||||
expect(result.triggeredBy).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("returns not cold for non-eligible status", () => {
|
// With eligible status and stale activity
|
||||||
const result = checkColdStatus({
|
|
||||||
statusCwId: 24, // New — not in threshold table
|
|
||||||
lastActivityDate: new Date("2020-01-01"),
|
|
||||||
now: new Date("2026-06-01"),
|
|
||||||
});
|
|
||||||
expect(result.cold).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("returns not cold when lastActivityDate is null", () => {
|
|
||||||
const result = checkColdStatus({
|
|
||||||
statusCwId: 43, // QuoteSent
|
|
||||||
lastActivityDate: null,
|
|
||||||
});
|
|
||||||
expect(result.cold).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("returns not cold when within threshold (QuoteSent, 13 days)", () => {
|
|
||||||
const now = new Date("2026-03-14T00:00:00Z");
|
|
||||||
const lastActivity = new Date("2026-03-01T00:00:00Z"); // 13 days ago
|
|
||||||
const result = checkColdStatus({
|
|
||||||
statusCwId: 43,
|
|
||||||
lastActivityDate: lastActivity,
|
|
||||||
now,
|
|
||||||
});
|
|
||||||
expect(result.cold).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("returns cold when QuoteSent exceeds 14 days", () => {
|
|
||||||
const now = new Date("2026-03-16T00:00:00Z");
|
const now = new Date("2026-03-16T00:00:00Z");
|
||||||
const lastActivity = new Date("2026-03-01T00:00:00Z"); // 15 days ago
|
const lastActivity = new Date("2026-03-01T00:00:00Z"); // 15 days ago
|
||||||
const result = checkColdStatus({
|
expect(checkColdStatus({ statusCwId: 43, lastActivityDate: lastActivity, now }))
|
||||||
statusCwId: 43,
|
.toEqual({ cold: false, triggeredBy: null });
|
||||||
lastActivityDate: lastActivity,
|
|
||||||
now,
|
|
||||||
});
|
|
||||||
expect(result.cold).toBe(true);
|
|
||||||
expect(result.triggeredBy).not.toBeNull();
|
|
||||||
expect(result.triggeredBy!.statusCwId).toBe(43);
|
|
||||||
expect(result.triggeredBy!.statusName).toBe("QuoteSent");
|
|
||||||
expect(result.triggeredBy!.thresholdDays).toBe(14);
|
|
||||||
expect(result.triggeredBy!.staleDays).toBe(15);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("returns cold when ConfirmedQuote exceeds 30 days", () => {
|
// With ConfirmedQuote exceeding threshold
|
||||||
const now = new Date("2026-04-01T00:00:00Z");
|
expect(checkColdStatus({ statusCwId: 57, lastActivityDate: new Date("2026-02-01"), now: new Date("2026-04-01") }))
|
||||||
const lastActivity = new Date("2026-02-28T00:00:00Z"); // 32 days
|
.toEqual({ cold: false, triggeredBy: null });
|
||||||
const result = checkColdStatus({
|
|
||||||
statusCwId: 57,
|
|
||||||
lastActivityDate: lastActivity,
|
|
||||||
now,
|
|
||||||
});
|
|
||||||
expect(result.cold).toBe(true);
|
|
||||||
expect(result.triggeredBy!.statusName).toBe("ConfirmedQuote");
|
|
||||||
expect(result.triggeredBy!.thresholdDays).toBe(30);
|
|
||||||
expect(result.triggeredBy!.staleDays).toBeGreaterThanOrEqual(30);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("returns not cold when ConfirmedQuote within 30 days", () => {
|
|
||||||
const now = new Date("2026-03-20T00:00:00Z");
|
|
||||||
const lastActivity = new Date("2026-03-01T00:00:00Z"); // 19 days
|
|
||||||
const result = checkColdStatus({
|
|
||||||
statusCwId: 57,
|
|
||||||
lastActivityDate: lastActivity,
|
|
||||||
now,
|
|
||||||
});
|
|
||||||
expect(result.cold).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("exactly at threshold is cold (>= threshold)", () => {
|
|
||||||
const now = new Date("2026-03-15T00:00:00Z");
|
|
||||||
const lastActivity = new Date("2026-03-01T00:00:00Z"); // exactly 14 days
|
|
||||||
const result = checkColdStatus({
|
|
||||||
statusCwId: 43,
|
|
||||||
lastActivityDate: lastActivity,
|
|
||||||
now,
|
|
||||||
});
|
|
||||||
expect(result.cold).toBe(true);
|
|
||||||
expect(result.triggeredBy!.staleDays).toBe(14);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("now override works as expected", () => {
|
|
||||||
const fixed = new Date("2026-06-01T00:00:00Z");
|
|
||||||
const lastActivity = new Date("2026-05-01T00:00:00Z"); // 31 days
|
|
||||||
const result = checkColdStatus({
|
|
||||||
statusCwId: 57,
|
|
||||||
lastActivityDate: lastActivity,
|
|
||||||
now: fixed,
|
|
||||||
});
|
|
||||||
expect(result.cold).toBe(true);
|
|
||||||
expect(result.triggeredBy!.staleDays).toBe(31);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -93,38 +93,10 @@ const REAL_COLD_THRESHOLDS: Record<number, { days: number; ms: number }> = {
|
|||||||
57: { days: 30, ms: 30 * 24 * 60 * 60 * 1000 },
|
57: { days: 30, ms: 30 * 24 * 60 * 60 * 1000 },
|
||||||
};
|
};
|
||||||
|
|
||||||
const REAL_STATUS_NAMES: Record<number, string> = {
|
/** checkColdStatus is bypassed in source — always returns not-cold. */
|
||||||
43: "QuoteSent",
|
const mockCheckColdStatus = mock(
|
||||||
57: "ConfirmedQuote",
|
() => ({ cold: false as const, triggeredBy: null }),
|
||||||
};
|
);
|
||||||
|
|
||||||
/** 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", () => ({
|
mock.module("../../src/modules/algorithms/algo.coldThreshold", () => ({
|
||||||
checkColdStatus: mockCheckColdStatus,
|
checkColdStatus: mockCheckColdStatus,
|
||||||
|
|||||||
Reference in New Issue
Block a user