55 lines
2.0 KiB
JavaScript
55 lines
2.0 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { createRequire } from "node:module";
|
|
import { existsSync, readFileSync } from "node:fs";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
const indexSource = readFileSync("pages/index/index.js", "utf8");
|
|
const helperPath = "utils/scanRouting.js";
|
|
|
|
assert.ok(existsSync(helperPath), "scan routing helper should exist");
|
|
|
|
const { buildErpLoginConfirmUrlFromScanResult } = require("../utils/scanRouting.js");
|
|
|
|
assert.equal(
|
|
buildErpLoginConfirmUrlFromScanResult({
|
|
path: "pages/erpLoginConfirm/erpLoginConfirm?scene=t%3Dabc123%26s%3D7",
|
|
}),
|
|
"/pages/erpLoginConfirm/erpLoginConfirm?scene=t%3Dabc123%26s%3D7",
|
|
);
|
|
assert.equal(
|
|
buildErpLoginConfirmUrlFromScanResult({
|
|
result: "scene=t%3DcompactTicket%26s%3D9",
|
|
}),
|
|
"/pages/erpLoginConfirm/erpLoginConfirm?scene=t%3DcompactTicket%26s%3D9",
|
|
);
|
|
assert.equal(
|
|
buildErpLoginConfirmUrlFromScanResult({
|
|
path: "pages/erpLoginConfirm/erpLoginConfirm?ticket=legacyTicket&session_id=12",
|
|
}),
|
|
"/pages/erpLoginConfirm/erpLoginConfirm?scene=t%3DlegacyTicket%26s%3D12",
|
|
);
|
|
assert.equal(
|
|
buildErpLoginConfirmUrlFromScanResult({
|
|
result: "pages/clock/clock?scene=mold%3Dabc123",
|
|
}),
|
|
"",
|
|
);
|
|
assert.equal(
|
|
buildErpLoginConfirmUrlFromScanResult({
|
|
result: "mold=abc123",
|
|
}),
|
|
"",
|
|
);
|
|
|
|
const scanDeviceIndex = indexSource.indexOf("async scanDevice()");
|
|
const erpRoutingIndex = indexSource.indexOf("buildErpLoginConfirmUrlFromScanResult", scanDeviceIndex);
|
|
const moldRoutingIndex = indexSource.indexOf("extractMoldName", scanDeviceIndex);
|
|
const locationGuardIndex = indexSource.indexOf("ensureFactoryLocation", scanDeviceIndex);
|
|
|
|
assert.ok(scanDeviceIndex >= 0, "index page should have scanDevice");
|
|
assert.ok(erpRoutingIndex > scanDeviceIndex, "scanDevice should check ERP login scan result");
|
|
assert.ok(erpRoutingIndex < moldRoutingIndex, "ERP login scan should be routed before mold parsing");
|
|
assert.ok(erpRoutingIndex < locationGuardIndex, "ERP login scan should not require report location guard");
|
|
|
|
console.log("erp login scan routing checks passed");
|