#!/usr/bin/env node /** * 列表行「下一步」的执行锁(2026-11-17:开通工单按服务开始日执行)。 * * 存在理由:开通类三类(`open`/`service_open`/`updown`)的计划执行日=订阅**服务开始日**。 * 未到该日时服务端 `actions.backfill`/`check_done` 恒 false,列表行也⛔ 给 `?act=` 深链 * (点进去是一个点不动的抽屉);开始日当天必须立刻恢复深链。另一条同样容易写错的是 * 「开始日当天算不算超期」——**不算**,次日起才算(后端 `domain::is_overdue_by_type`)。 */ import test from "node:test"; import assert from "node:assert/strict"; import { nextStepOf } from "../src/lib/work-order-next-step.ts"; import { businessToday } from "../src/lib/business-date.ts"; const row = (over = {}) => ({ ticket_id: "9001", ticket_no: "T-20261117-0001", ticket_type: "open", status: "processing", title: "开户-测试客户", customer_id: "1001", customer_name: "测试客户", assign_team_id: null, assignee_user_id: "2002", backfill_source: null, expected_done_date: "2026-12-01", created_at: null, ...over, }); // ⚠️ 用本地日历日(`businessToday`),⛔ `toISOString()`:UTC 换算在 +08 凌晨会退回前一天, // 那样这个测试就变成"在测 UTC 那套错误口径",与真实的业务日对不上。 const isoOffset = (days) => { const d = new Date(); d.setDate(d.getDate() + days); return businessToday(d); }; test("未到服务开始日:不给动作深链,只给日期提示", () => { const step = nextStepOf( row({ execution_locked: true, execution_not_before: "2026-12-01" }), ); assert.equal(step.action, undefined, "锁定期⛔ 给 ?act= 深链"); assert.equal(step.tone, "waiting"); assert.match(step.hint, /2026-12-01/); // 2026-11-18:只读态标签写「未到执行日」,次行不再重复这四个字(也不是「等待对方」)。 assert.equal(step.passiveLabel, "未到执行日"); assert.ok(!step.hint.includes("未到执行日"), "次行⛔ 重复标签"); assert.ok(!step.hint.includes("("), "次行⛔ 带括号复述"); }); test("开始日当天:恢复施工回填深链", () => { assert.equal( nextStepOf(row({ execution_locked: false })).action, "backfill", ); // 服务开通单走条目核对,口径一致。 assert.equal( nextStepOf(row({ ticket_type: "service_open", execution_locked: false })).action, "check_done", ); }); test("开通类:开始日当天不算超期,次日起才算", () => { const today = isoOffset(0); const yesterday = isoOffset(-1); // 服务端没给 overdue_7d 时走本地兜底,必须与后端同口径(严格大于)。 assert.equal(nextStepOf(row({ expected_done_date: today })).tone, "todo"); assert.equal(nextStepOf(row({ expected_done_date: yesterday })).tone, "urgent"); }); test("停机类仍按期限日当天即计入(既有口径不回退)", () => { const today = isoOffset(0); assert.equal( nextStepOf(row({ ticket_type: "expiry_stop", expected_done_date: today })).tone, "urgent", ); }); test("服务端 overdue_7d 优先于本地推算", () => { const future = isoOffset(5); assert.equal(nextStepOf(row({ expected_done_date: future, overdue_7d: true })).tone, "urgent"); assert.equal( nextStepOf(row({ ticket_type: "expiry_stop", expected_done_date: isoOffset(-3), overdue_7d: false })).tone, "todo", ); }); test("卡在别人手里要写明对家:主线等运营商回执,故障/售后等客户确认", () => { // 主线(开户/服务开通/到期停机/服务停用/升降配):通路 6,凭运营商回执闭环。 for (const type of ["open", "service_open", "expiry_stop", "service_stop", "updown"]) { const step = nextStepOf(row({ ticket_type: type, status: "completed" })); assert.equal(step.action, undefined, "completed 不是责任人手上的动作"); assert.equal(step.passiveLabel, "等运营商回执", `${type} 的对家应是运营商`); assert.match(step.hint, /运营商/); } // 非主线(故障/售后):通路 7,等提交方(客户)确认或超时自动闭环。 for (const type of ["fault", "after_sale"]) { const step = nextStepOf(row({ ticket_type: type, status: "completed" })); assert.equal(step.passiveLabel, "等客户确认", `${type} 的对家应是客户`); assert.match(step.hint, /客户/); } // ⛔ 一律退化成「等待对方」——那等于没说卡在谁手里。 for (const type of ["open", "fault"]) { assert.notEqual(nextStepOf(row({ ticket_type: type, status: "completed" })).passiveLabel, "等待对方"); } });