work-order-activation.test.mjs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env node
  2. /**
  3. * 列表行「下一步」的执行锁(2026-11-17:开通工单按服务开始日执行)。
  4. *
  5. * 存在理由:开通类三类(`open`/`service_open`/`updown`)的计划执行日=订阅**服务开始日**。
  6. * 未到该日时服务端 `actions.backfill`/`check_done` 恒 false,列表行也⛔ 给 `?act=` 深链
  7. * (点进去是一个点不动的抽屉);开始日当天必须立刻恢复深链。另一条同样容易写错的是
  8. * 「开始日当天算不算超期」——**不算**,次日起才算(后端 `domain::is_overdue_by_type`)。
  9. */
  10. import test from "node:test";
  11. import assert from "node:assert/strict";
  12. import { nextStepOf } from "../src/lib/work-order-next-step.ts";
  13. import { businessToday } from "../src/lib/business-date.ts";
  14. const row = (over = {}) => ({
  15. ticket_id: "9001",
  16. ticket_no: "T-20261117-0001",
  17. ticket_type: "open",
  18. status: "processing",
  19. title: "开户-测试客户",
  20. customer_id: "1001",
  21. customer_name: "测试客户",
  22. assign_team_id: null,
  23. assignee_user_id: "2002",
  24. backfill_source: null,
  25. expected_done_date: "2026-12-01",
  26. created_at: null,
  27. ...over,
  28. });
  29. // ⚠️ 用本地日历日(`businessToday`),⛔ `toISOString()`:UTC 换算在 +08 凌晨会退回前一天,
  30. // 那样这个测试就变成"在测 UTC 那套错误口径",与真实的业务日对不上。
  31. const isoOffset = (days) => {
  32. const d = new Date();
  33. d.setDate(d.getDate() + days);
  34. return businessToday(d);
  35. };
  36. test("未到服务开始日:不给动作深链,只给日期提示", () => {
  37. const step = nextStepOf(
  38. row({ execution_locked: true, execution_not_before: "2026-12-01" }),
  39. );
  40. assert.equal(step.action, undefined, "锁定期⛔ 给 ?act= 深链");
  41. assert.equal(step.tone, "waiting");
  42. assert.match(step.hint, /2026-12-01/);
  43. // 2026-11-18:只读态标签写「未到执行日」,次行不再重复这四个字(也不是「等待对方」)。
  44. assert.equal(step.passiveLabel, "未到执行日");
  45. assert.ok(!step.hint.includes("未到执行日"), "次行⛔ 重复标签");
  46. assert.ok(!step.hint.includes("("), "次行⛔ 带括号复述");
  47. });
  48. test("开始日当天:恢复施工回填深链", () => {
  49. assert.equal(
  50. nextStepOf(row({ execution_locked: false })).action,
  51. "backfill",
  52. );
  53. // 服务开通单走条目核对,口径一致。
  54. assert.equal(
  55. nextStepOf(row({ ticket_type: "service_open", execution_locked: false })).action,
  56. "check_done",
  57. );
  58. });
  59. test("开通类:开始日当天不算超期,次日起才算", () => {
  60. const today = isoOffset(0);
  61. const yesterday = isoOffset(-1);
  62. // 服务端没给 overdue_7d 时走本地兜底,必须与后端同口径(严格大于)。
  63. assert.equal(nextStepOf(row({ expected_done_date: today })).tone, "todo");
  64. assert.equal(nextStepOf(row({ expected_done_date: yesterday })).tone, "urgent");
  65. });
  66. test("停机类仍按期限日当天即计入(既有口径不回退)", () => {
  67. const today = isoOffset(0);
  68. assert.equal(
  69. nextStepOf(row({ ticket_type: "expiry_stop", expected_done_date: today })).tone,
  70. "urgent",
  71. );
  72. });
  73. test("服务端 overdue_7d 优先于本地推算", () => {
  74. const future = isoOffset(5);
  75. assert.equal(nextStepOf(row({ expected_done_date: future, overdue_7d: true })).tone, "urgent");
  76. assert.equal(
  77. nextStepOf(row({ ticket_type: "expiry_stop", expected_done_date: isoOffset(-3), overdue_7d: false })).tone,
  78. "todo",
  79. );
  80. });
  81. test("卡在别人手里要写明对家:主线等运营商回执,故障/售后等客户确认", () => {
  82. // 主线(开户/服务开通/到期停机/服务停用/升降配):通路 6,凭运营商回执闭环。
  83. for (const type of ["open", "service_open", "expiry_stop", "service_stop", "updown"]) {
  84. const step = nextStepOf(row({ ticket_type: type, status: "completed" }));
  85. assert.equal(step.action, undefined, "completed 不是责任人手上的动作");
  86. assert.equal(step.passiveLabel, "等运营商回执", `${type} 的对家应是运营商`);
  87. assert.match(step.hint, /运营商/);
  88. }
  89. // 非主线(故障/售后):通路 7,等提交方(客户)确认或超时自动闭环。
  90. for (const type of ["fault", "after_sale"]) {
  91. const step = nextStepOf(row({ ticket_type: type, status: "completed" }));
  92. assert.equal(step.passiveLabel, "等客户确认", `${type} 的对家应是客户`);
  93. assert.match(step.hint, /客户/);
  94. }
  95. // ⛔ 一律退化成「等待对方」——那等于没说卡在谁手里。
  96. for (const type of ["open", "fault"]) {
  97. assert.notEqual(nextStepOf(row({ ticket_type: type, status: "completed" })).passiveLabel, "等待对方");
  98. }
  99. });