ticket-rows.test.mjs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/usr/bin/env node
  2. /**
  3. * 工单明细行校验(回填的网络线路/境外 IP 明细)。
  4. *
  5. * 存在理由:施工回填此前没有 `route_rows`/`ip_rows` 与建单人,提交必回 `60404` 必填组不齐。
  6. * 「整行必填」口径⛔ 散在组件里,本测试把后端 `handlers/handle.rs` 的逐行必填口径钉死在这里。
  7. *
  8. * ⚠️ 2026-11-17:「开通准备资料」整块退役,本文件只保留回填两类明细的用例。
  9. */
  10. import test from "node:test";
  11. import assert from "node:assert/strict";
  12. import {
  13. backfillIpRowsFromDetail,
  14. buildBackfillIpRows,
  15. buildRouteRows,
  16. newBackfillIpRow,
  17. newRouteRow,
  18. normalizeBuilderUserId,
  19. parseLineExits,
  20. routeRowsFromDetail,
  21. validateBackfillIpRows,
  22. validateRouteRows,
  23. } from "../src/lib/ticketRows.ts";
  24. const fullRoute = (over = {}) => ({
  25. ...newRouteRow(),
  26. sub_account_id: "SUB-000023",
  27. network_account_name: "hailan-office-01",
  28. intranet_ip: "10.20.30.11",
  29. subnet_mask: "255.255.255.0",
  30. gateway: "10.20.30.1",
  31. vlan: "120",
  32. vni: "50120",
  33. src_endpoint: "上海临港POP",
  34. dst_endpoint: "中国香港POP",
  35. egress_pop: "中国香港",
  36. down_mbps: "100",
  37. up_mbps: "50",
  38. ...over,
  39. });
  40. const fullIp = (over = {}) => ({
  41. ...newBackfillIpRow(),
  42. egress: "中国香港",
  43. overseas_ip: "203.0.113.7",
  44. ip_type: "fixed_ip",
  45. bandwidth_mbps: "10",
  46. pin: "PIN-8842",
  47. cpid: "CPID-8842",
  48. ...over,
  49. });
  50. test("回填网络线路:整行 12 列缺一列就报出缺哪一列(组一整行必填)", () => {
  51. assert.equal(validateRouteRows([fullRoute()], true), null);
  52. assert.match(validateRouteRows([fullRoute({ gateway: "" })], true) ?? "", /第 1 行线路缺网关/);
  53. assert.match(
  54. validateRouteRows([fullRoute({ vlan: "", vni: "" })], true) ?? "",
  55. /缺VLAN、VNI/,
  56. );
  57. // 只填了一格的半行⛔ 当空行丢掉,必须点名还缺哪些列
  58. const half = { ...newRouteRow(), sub_account_id: "SUB-000023", gateway: "" };
  59. assert.match(validateRouteRows([half], true) ?? "", /第 1 行线路缺网络账户名/);
  60. });
  61. test("回填网络线路:至少一行(开通类),空行不占名额也不入载荷", () => {
  62. assert.match(validateRouteRows([newRouteRow()], true) ?? "", /至少填写一行/);
  63. assert.equal(validateRouteRows([newRouteRow()], false), null);
  64. assert.equal(buildRouteRows([newRouteRow()]).length, 0);
  65. // 未勾「本次开通」:后端只处理 picked ⇒ 既不校验也不入库,前端同口径放行且不下发
  66. const parked = { ...fullRoute(), open_this_time: false };
  67. assert.match(validateRouteRows([parked], true) ?? "", /勾选至少一行/);
  68. assert.equal(validateRouteRows([parked, fullRoute()], true), null);
  69. assert.equal(buildRouteRows([parked, fullRoute()]).length, 1);
  70. const built = buildRouteRows([fullRoute()]);
  71. assert.equal(built.length, 1);
  72. assert.equal(built[0].down_mbps, 100);
  73. assert.equal(built[0].open_this_time, true);
  74. assert.equal(Object.keys(built[0]).length, 13, "RouteIn 十二列 + open_this_time");
  75. });
  76. test("回填网络线路:非法 IP 与非法带宽被拦", () => {
  77. assert.match(validateRouteRows([fullRoute({ intranet_ip: "10.20.30" })], true) ?? "", /不是合法 IP/);
  78. assert.equal(validateRouteRows([fullRoute({ subnet_mask: "255.255.255.0/32" })], true), null);
  79. assert.match(validateRouteRows([fullRoute({ up_mbps: "0" })], true) ?? "", /正数/);
  80. });
  81. test("回填境外 IP 明细:六项含 PIN/CPID 整行必填,IP 去重", () => {
  82. assert.equal(validateBackfillIpRows([]), null, "合同核定数为 0 时允许一行不填");
  83. assert.equal(validateBackfillIpRows([fullIp()]), null);
  84. assert.match(validateBackfillIpRows([fullIp({ pin: "" })]) ?? "", /缺PIN/);
  85. assert.match(validateBackfillIpRows([fullIp({ cpid: "" })]) ?? "", /缺CPID/);
  86. assert.match(validateBackfillIpRows([fullIp({ overseas_ip: "203.0.113" })]) ?? "", /不是合法 IP/);
  87. assert.match(
  88. validateBackfillIpRows([fullIp(), fullIp({ egress: "中国香港" })]) ?? "",
  89. /重复登记/,
  90. );
  91. const built = buildBackfillIpRows([fullIp({ pin: " " })]);
  92. assert.equal(built.length, 1);
  93. });
  94. test("建单人只接受数字身份 ID(后端 parse::<i64>,非数字等于没填 ⇒ 组二永不齐)", () => {
  95. assert.equal(normalizeBuilderUserId("377168275206836224"), "377168275206836224");
  96. assert.equal(normalizeBuilderUserId(" 377168275206836224 "), "377168275206836224");
  97. assert.equal(normalizeBuilderUserId("klt_bos_ops"), null);
  98. assert.equal(normalizeBuilderUserId(undefined), null);
  99. });
  100. test("合同核定出口解析:取不到就回空数组,让页面退回手填", () => {
  101. assert.deepEqual(parseLineExits('["中国香港","日本东京"]'), ["中国香港", "日本东京"]);
  102. assert.deepEqual(parseLineExits(null), []);
  103. assert.deepEqual(parseLineExits("{不是 JSON"), []);
  104. assert.deepEqual(parseLineExits('["", " "]'), []);
  105. });
  106. test("明细回填摊平:读侧 null 落空串,PIN 不回显", () => {
  107. const rows = routeRowsFromDetail([
  108. {
  109. id: "1", sub_account_id: null, network_account_name: null, intranet_ip: "10.0.0.1",
  110. subnet_mask: null, gateway: null, vlan: null, vni: null, src_endpoint: null,
  111. dst_endpoint: null, egress_pop: null, down_mbps: null, up_mbps: null, updated_at: null,
  112. },
  113. ]);
  114. assert.equal(rows[0].sub_account_id, "");
  115. assert.equal(rows[0].subnet_mask, "");
  116. assert.equal(rows[0].intranet_ip, "10.0.0.1");
  117. assert.equal(rows[0].open_this_time, true);
  118. const ips = backfillIpRowsFromDetail([
  119. { id: "2", row_no: 1, egress: null, overseas_ip: "203.0.113.9", ip_type: "fixed_ip", bandwidth_mbps: "5", pin_registered: true, cpid_registered: false },
  120. ]);
  121. assert.equal(ips[0].pin, "", "库内只有密文,覆盖保存前须重填 PIN");
  122. assert.equal(ips[0].cpid, "");
  123. });