| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #!/usr/bin/env node
- /**
- * 工单明细行校验(回填的网络线路/境外 IP 明细)。
- *
- * 存在理由:施工回填此前没有 `route_rows`/`ip_rows` 与建单人,提交必回 `60404` 必填组不齐。
- * 「整行必填」口径⛔ 散在组件里,本测试把后端 `handlers/handle.rs` 的逐行必填口径钉死在这里。
- *
- * ⚠️ 2026-11-17:「开通准备资料」整块退役,本文件只保留回填两类明细的用例。
- */
- import test from "node:test";
- import assert from "node:assert/strict";
- import {
- backfillIpRowsFromDetail,
- buildBackfillIpRows,
- buildRouteRows,
- newBackfillIpRow,
- newRouteRow,
- normalizeBuilderUserId,
- parseLineExits,
- routeRowsFromDetail,
- validateBackfillIpRows,
- validateRouteRows,
- } from "../src/lib/ticketRows.ts";
- const fullRoute = (over = {}) => ({
- ...newRouteRow(),
- sub_account_id: "SUB-000023",
- network_account_name: "hailan-office-01",
- intranet_ip: "10.20.30.11",
- subnet_mask: "255.255.255.0",
- gateway: "10.20.30.1",
- vlan: "120",
- vni: "50120",
- src_endpoint: "上海临港POP",
- dst_endpoint: "中国香港POP",
- egress_pop: "中国香港",
- down_mbps: "100",
- up_mbps: "50",
- ...over,
- });
- const fullIp = (over = {}) => ({
- ...newBackfillIpRow(),
- egress: "中国香港",
- overseas_ip: "203.0.113.7",
- ip_type: "fixed_ip",
- bandwidth_mbps: "10",
- pin: "PIN-8842",
- cpid: "CPID-8842",
- ...over,
- });
- test("回填网络线路:整行 12 列缺一列就报出缺哪一列(组一整行必填)", () => {
- assert.equal(validateRouteRows([fullRoute()], true), null);
- assert.match(validateRouteRows([fullRoute({ gateway: "" })], true) ?? "", /第 1 行线路缺网关/);
- assert.match(
- validateRouteRows([fullRoute({ vlan: "", vni: "" })], true) ?? "",
- /缺VLAN、VNI/,
- );
- // 只填了一格的半行⛔ 当空行丢掉,必须点名还缺哪些列
- const half = { ...newRouteRow(), sub_account_id: "SUB-000023", gateway: "" };
- assert.match(validateRouteRows([half], true) ?? "", /第 1 行线路缺网络账户名/);
- });
- test("回填网络线路:至少一行(开通类),空行不占名额也不入载荷", () => {
- assert.match(validateRouteRows([newRouteRow()], true) ?? "", /至少填写一行/);
- assert.equal(validateRouteRows([newRouteRow()], false), null);
- assert.equal(buildRouteRows([newRouteRow()]).length, 0);
- // 未勾「本次开通」:后端只处理 picked ⇒ 既不校验也不入库,前端同口径放行且不下发
- const parked = { ...fullRoute(), open_this_time: false };
- assert.match(validateRouteRows([parked], true) ?? "", /勾选至少一行/);
- assert.equal(validateRouteRows([parked, fullRoute()], true), null);
- assert.equal(buildRouteRows([parked, fullRoute()]).length, 1);
- const built = buildRouteRows([fullRoute()]);
- assert.equal(built.length, 1);
- assert.equal(built[0].down_mbps, 100);
- assert.equal(built[0].open_this_time, true);
- assert.equal(Object.keys(built[0]).length, 13, "RouteIn 十二列 + open_this_time");
- });
- test("回填网络线路:非法 IP 与非法带宽被拦", () => {
- assert.match(validateRouteRows([fullRoute({ intranet_ip: "10.20.30" })], true) ?? "", /不是合法 IP/);
- assert.equal(validateRouteRows([fullRoute({ subnet_mask: "255.255.255.0/32" })], true), null);
- assert.match(validateRouteRows([fullRoute({ up_mbps: "0" })], true) ?? "", /正数/);
- });
- test("回填境外 IP 明细:六项含 PIN/CPID 整行必填,IP 去重", () => {
- assert.equal(validateBackfillIpRows([]), null, "合同核定数为 0 时允许一行不填");
- assert.equal(validateBackfillIpRows([fullIp()]), null);
- assert.match(validateBackfillIpRows([fullIp({ pin: "" })]) ?? "", /缺PIN/);
- assert.match(validateBackfillIpRows([fullIp({ cpid: "" })]) ?? "", /缺CPID/);
- assert.match(validateBackfillIpRows([fullIp({ overseas_ip: "203.0.113" })]) ?? "", /不是合法 IP/);
- assert.match(
- validateBackfillIpRows([fullIp(), fullIp({ egress: "中国香港" })]) ?? "",
- /重复登记/,
- );
- const built = buildBackfillIpRows([fullIp({ pin: " " })]);
- assert.equal(built.length, 1);
- });
- test("建单人只接受数字身份 ID(后端 parse::<i64>,非数字等于没填 ⇒ 组二永不齐)", () => {
- assert.equal(normalizeBuilderUserId("377168275206836224"), "377168275206836224");
- assert.equal(normalizeBuilderUserId(" 377168275206836224 "), "377168275206836224");
- assert.equal(normalizeBuilderUserId("klt_bos_ops"), null);
- assert.equal(normalizeBuilderUserId(undefined), null);
- });
- test("合同核定出口解析:取不到就回空数组,让页面退回手填", () => {
- assert.deepEqual(parseLineExits('["中国香港","日本东京"]'), ["中国香港", "日本东京"]);
- assert.deepEqual(parseLineExits(null), []);
- assert.deepEqual(parseLineExits("{不是 JSON"), []);
- assert.deepEqual(parseLineExits('["", " "]'), []);
- });
- test("明细回填摊平:读侧 null 落空串,PIN 不回显", () => {
- const rows = routeRowsFromDetail([
- {
- id: "1", sub_account_id: null, network_account_name: null, intranet_ip: "10.0.0.1",
- subnet_mask: null, gateway: null, vlan: null, vni: null, src_endpoint: null,
- dst_endpoint: null, egress_pop: null, down_mbps: null, up_mbps: null, updated_at: null,
- },
- ]);
- assert.equal(rows[0].sub_account_id, "");
- assert.equal(rows[0].subnet_mask, "");
- assert.equal(rows[0].intranet_ip, "10.0.0.1");
- assert.equal(rows[0].open_this_time, true);
- const ips = backfillIpRowsFromDetail([
- { 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 },
- ]);
- assert.equal(ips[0].pin, "", "库内只有密文,覆盖保存前须重填 PIN");
- assert.equal(ips[0].cpid, "");
- });
|