forked from longtao.wu/droboticflow
65 lines
2.7 KiB
JavaScript
65 lines
2.7 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import test from "node:test";
|
|
|
|
const pageURL = new URL("../../src/pages/ObjectSync.tsx", import.meta.url);
|
|
const serviceURL = new URL("../../src/services/api/object-sync.ts", import.meta.url);
|
|
const appURL = new URL("../../src/App.tsx", import.meta.url);
|
|
const sidebarURL = new URL("../../src/components/Sidebar.tsx", import.meta.url);
|
|
|
|
test("drosync page exposes capability, session, conflict, release, audit and update surfaces", async () => {
|
|
const source = await readFile(pageURL, "utf8");
|
|
for (const label of [
|
|
"能力门禁",
|
|
"同步空间",
|
|
"设备与授权",
|
|
"Session",
|
|
"Keep-both 冲突",
|
|
"不可变 Release",
|
|
"审计哈希链",
|
|
"客户端更新策略",
|
|
]) {
|
|
assert.match(source, new RegExp(label));
|
|
}
|
|
assert.match(source, /条件创建/);
|
|
assert.match(source, /发现漂移/);
|
|
assert.match(source, /已确认无外部直写/);
|
|
assert.match(source, /条件覆盖/);
|
|
assert.match(source, /window\.confirm/);
|
|
assert.match(source, /配对短码/);
|
|
assert.match(source, /findAuthorizationByCode/);
|
|
});
|
|
|
|
test("drosync page applies role-specific views", async () => {
|
|
const source = await readFile(pageURL, "utf8");
|
|
assert.match(source, /role === "admin"/);
|
|
assert.match(source, /role === "pipeline_engineer"/);
|
|
assert.match(source, /role === "compliance_auditor"/);
|
|
assert.match(source, /visible: isAdmin/);
|
|
assert.match(source, /visible: isAdmin \|\| isAuditor/);
|
|
assert.match(source, /visible: isAdmin \|\| isPipeline/);
|
|
});
|
|
|
|
test("drosync API client adds idempotency keys to every mutation", async () => {
|
|
const source = await readFile(serviceURL, "utf8");
|
|
assert.match(source, /"Idempotency-Key"/);
|
|
assert.match(source, /crypto\?\.randomUUID/);
|
|
assert.match(source, /const mutation =/);
|
|
assert.match(source, /\/api\/object-sync\/spaces/);
|
|
assert.match(source, /capability-probe/);
|
|
assert.match(source, /device-authorizations/);
|
|
assert.match(source, /audit-events\/export/);
|
|
assert.match(source, /force-overwrite/);
|
|
assert.match(source, /device-authorizations\/by-code\?userCode=/);
|
|
});
|
|
|
|
test("drosync route is lazy-loaded and visible to all supported business roles", async () => {
|
|
const [app, sidebar] = await Promise.all([readFile(appURL, "utf8"), readFile(sidebarURL, "utf8")]);
|
|
assert.match(app, /lazyRoute\(\(\) => import\("\.\/pages\/ObjectSync"\)\)/);
|
|
assert.match(app, /path="\/object-sync"/);
|
|
assert.match(sidebar, /label: "drosync"/);
|
|
for (const role of ["admin", "pipeline_engineer", "data_operator", "compliance_auditor", "auditor", "operator"]) {
|
|
assert.match(sidebar, new RegExp(`"${role}"`));
|
|
}
|
|
});
|