250 lines
10 KiB
JavaScript
250 lines
10 KiB
JavaScript
/**
|
||
* 资质申请管理 — 页面交互逻辑 + 后端联调全链路测试
|
||
*
|
||
* 覆盖本次改造:
|
||
* - 新建申请不预调 draft(列表 API 计数不变)
|
||
* - 暂存后入库并可回显
|
||
* - 材料前端模板 + 暂存时 init-template
|
||
* - 提交前核验(全通过/有失败)
|
||
* - 前端路由 bundle 检测
|
||
*
|
||
* 运行:
|
||
* node docs/test-reports/测试用例/test-qual-filing-interaction.mjs
|
||
*/
|
||
import fs from "node:fs";
|
||
import path from "node:path";
|
||
import { fileURLToPath } from "node:url";
|
||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||
const ROOT = path.resolve(__dirname, "../../..");
|
||
|
||
const API_BASE = process.env.API_BASE || "http://127.0.0.1:8095/safety-eval";
|
||
const ORG_INFO_ID = process.env.ORG_INFO_ID || "1";
|
||
const FRONTEND_BASE = process.env.FRONTEND_BASE || "http://127.0.0.1:8081";
|
||
const DEFAULT_URL =
|
||
"https://s1.aigei.com/prevfiles/6f2754563be2491bad7c957904cd7d2a.jpg?e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:CR60zg7VKDp-jUWyYls_rdvyQMM=";
|
||
|
||
let passed = 0;
|
||
let failed = 0;
|
||
|
||
function assert(name, condition, detail = "") {
|
||
if (condition) {
|
||
passed += 1;
|
||
console.log(` ✓ ${name}${detail ? ` — ${detail}` : ""}`);
|
||
}
|
||
else {
|
||
failed += 1;
|
||
console.log(` ✗ ${name}${detail ? ` — ${detail}` : ""}`);
|
||
}
|
||
}
|
||
|
||
async function api(method, path, body) {
|
||
const res = await fetch(`${API_BASE}${path}`, {
|
||
method,
|
||
headers: { "Content-Type": "application/json", orgInfoId: ORG_INFO_ID },
|
||
body: body !== undefined ? JSON.stringify(body) : undefined,
|
||
});
|
||
const text = await res.text();
|
||
try {
|
||
return { httpStatus: res.status, ...JSON.parse(text) };
|
||
}
|
||
catch {
|
||
return { httpStatus: res.status, success: false, raw: text };
|
||
}
|
||
}
|
||
|
||
function readSrc(rel) {
|
||
return fs.readFileSync(path.join(ROOT, rel), "utf8");
|
||
}
|
||
|
||
// ── 静态:新建不预调后端 ──
|
||
function testStaticNoPreCreate() {
|
||
console.log("\n=== 静态检查:新建不预调后端 ===");
|
||
const listPage = readSrc("src/pages/Container/QualApplication/FilingApplication/List/index.js");
|
||
assert("列表-申请备案不调 qualFilingDraft", !listPage.includes("qualFilingDraft"));
|
||
assert("列表-申请备案不调 init-template", !listPage.includes("qualFilingMaterialInitTemplate"));
|
||
assert("列表-直接跳转表单", listPage.includes("goFilingForm({ mode: FILING_FORM_MODE.APPLICATION })"));
|
||
|
||
const formPage = readSrc("src/pages/Container/QualApplication/FilingForm/index.js");
|
||
assert("表单-存在 persistFilingToBackend", formPage.includes("persistFilingToBackend"));
|
||
assert("表单-存在核验弹窗", formPage.includes("PrerequisiteVerifyModal"));
|
||
assert("表单-存在 session 本地草稿", formPage.includes("saveLocalDraft"));
|
||
assert("表单-材料本地更新", formPage.includes("uploadStatusName: \"已上传\""));
|
||
|
||
const basicStep = readSrc("src/pages/Container/QualApplication/FilingForm/components/BasicInfoStep.jsx");
|
||
assert("基本信息-证照类型选项", basicStep.includes("QUALIFICATION_INDUSTRY_OPTIONS"));
|
||
|
||
const commitment = readSrc("src/pages/Container/QualApplication/FilingForm/components/CommitmentStep.jsx");
|
||
assert("承诺书-法定代表人下拉", commitment.includes("legalRepPersonnelId"));
|
||
assert("承诺书-动态填充文本", commitment.includes("COMMITMENT_PARAGRAPHS"));
|
||
|
||
assert("材料模板-10项", readSrc("src/pages/Container/QualApplication/filingMaterialTemplate.js").includes("sortOrder: 10"));
|
||
}
|
||
|
||
// ── 核验逻辑 ──
|
||
async function testVerifyLogic() {
|
||
console.log("\n=== 核验逻辑 ===");
|
||
const verifyMod = await import(path.join(ROOT, "src/pages/Container/QualApplication/filingVerify.js"));
|
||
const { verifyFilingPrerequisites } = verifyMod;
|
||
|
||
const failDetail = {
|
||
fixedAssetAmount: 500,
|
||
workplaceArea: 500,
|
||
personnelList: [],
|
||
equipmentList: [],
|
||
materials: [{ sortOrder: 10, attachmentUrl: null }],
|
||
};
|
||
const failResult = verifyFilingPrerequisites(failDetail);
|
||
assert("核验-不完整时应失败", failResult.passed === false, `items=${failResult.items.length}`);
|
||
|
||
const passDetail = {
|
||
fixedAssetAmount: 1200,
|
||
workplaceArea: 1200,
|
||
equipmentList: [{ id: 1 }],
|
||
materials: [{ sortOrder: 10, attachmentUrl: DEFAULT_URL }],
|
||
personnelList: Array.from({ length: 25 }, (_, i) => ({
|
||
personName: `P${i}`,
|
||
registerEngineerFlag: i < 8 ? 1 : 0,
|
||
titleName: i < 8 ? "高级" : "中级",
|
||
positionName: i === 0 ? "负责人" : i === 1 ? "技术负责人" : i === 2 ? "质量负责人" : "工程师",
|
||
workExperience: "在本行业工作五年",
|
||
})),
|
||
};
|
||
const passResult = verifyFilingPrerequisites(passDetail);
|
||
assert("核验-完整数据应通过", passResult.passed === true);
|
||
}
|
||
|
||
// ── 模拟前端 persist 全链路 ──
|
||
async function testPersistFlow() {
|
||
console.log("\n=== 交互链路:暂存入库 + 回显 ===");
|
||
|
||
const beforePage = await api("GET", "/qual-filing/page?current=1&size=1&applyTypeCode=1");
|
||
const beforeTotal = beforePage.total ?? 0;
|
||
|
||
// 模拟用户填写后点暂存(等同 persistFilingToBackend)
|
||
const draft = await api("POST", "/qual-filing/draft?applyTypeCode=1");
|
||
assert("暂存-创建草稿", draft.success === true && draft.data?.id, `id=${draft.data?.id}`);
|
||
const filingId = draft.data?.id;
|
||
if (!filingId) {
|
||
return;
|
||
}
|
||
|
||
const saveBasic = await api("POST", "/qual-filing/save-draft", {
|
||
id: filingId,
|
||
businessScope: "石油加工业,化学原料、化学品及医药制造业",
|
||
filingTerritoryName: "渝北区",
|
||
filingTerritoryCode: "渝北区",
|
||
filingUnitName: "交互测试评价机构",
|
||
fixedAssetAmount: 1200,
|
||
workplaceArea: 1500,
|
||
});
|
||
assert("暂存-基本信息", saveBasic.success === true, saveBasic.message);
|
||
|
||
await api("POST", `/qual-filing-material/init-template?filingId=${filingId}`);
|
||
const detailAfterInit = await api("GET", `/qual-filing/detail?id=${filingId}`);
|
||
assert("暂存-材料模板10项", detailAfterInit.data?.materials?.length === 10);
|
||
|
||
for (const material of detailAfterInit.data.materials || []) {
|
||
await api("POST", "/qual-filing-material/upload", {
|
||
id: material.id,
|
||
attachmentUrl: DEFAULT_URL,
|
||
});
|
||
}
|
||
|
||
const commitmentContent = "本人是郑远平是交互测试评价机构法定代表人,现代表我单位承诺如下:";
|
||
await api("POST", "/qual-filing-commitment/save-or-update", {
|
||
filingId,
|
||
signDate: "2026-06-30",
|
||
legalRepSignatureUrl: DEFAULT_URL,
|
||
commitmentContent,
|
||
});
|
||
|
||
const personnelPage = await api("GET", "/org-personnel/page?current=1&size=5");
|
||
const personnelIds = (personnelPage.data || []).map((p) => p.id).filter(Boolean);
|
||
if (personnelIds.length) {
|
||
await api("POST", "/qual-filing-personnel/batch-add-from-org", {
|
||
filingId,
|
||
sourcePersonnelIds: personnelIds.slice(0, 2),
|
||
});
|
||
}
|
||
|
||
const equipPage = await api("GET", "/org-equipment/page?current=1&size=5");
|
||
const equipIds = (equipPage.data || []).map((e) => e.id).filter(Boolean);
|
||
if (equipIds.length) {
|
||
await api("POST", "/qual-filing-equipment/batch-add-from-org", {
|
||
filingId,
|
||
sourceEquipmentIds: equipIds.slice(0, 1),
|
||
});
|
||
}
|
||
|
||
const reloaded = await api("GET", `/qual-filing/detail?id=${filingId}`);
|
||
assert("回显-业务范围", reloaded.data?.businessScope?.includes("化学"), reloaded.data?.businessScope);
|
||
assert("回显-材料已上传", (reloaded.data?.materials || []).every((m) => m.uploadStatusCode === 2));
|
||
assert("回显-承诺书", !!reloaded.data?.commitment?.commitmentContent);
|
||
assert("回显-人员", (reloaded.data?.personnelList || []).length >= 1 || personnelIds.length === 0);
|
||
assert("回显-装备", (reloaded.data?.equipmentList || []).length >= 1 || equipIds.length === 0);
|
||
|
||
const afterPage = await api("GET", "/qual-filing/page?current=1&size=20&applyTypeCode=1");
|
||
assert("列表-暂存后总数增加", (afterPage.total ?? 0) >= beforeTotal + 1, `before=${beforeTotal} after=${afterPage.total}`);
|
||
|
||
// 提交应进入审核中
|
||
const submit = await api("POST", `/qual-filing/submit?id=${filingId}`);
|
||
assert("提交-进入审核中", submit.success === true && submit.data?.filingStatusCode === 2, submit.data?.filingStatusName);
|
||
}
|
||
|
||
// ── 前端 bundle / 路由 ──
|
||
async function testFrontendBundle() {
|
||
console.log("\n=== 前端页面 bundle 检测 ===");
|
||
const pages = [
|
||
["/certificate/container/qualApplication/filingApplication/list", "资质备案申请列表"],
|
||
["/certificate/container/qualApplication/filedManage/list", "已备案资质管理"],
|
||
["/certificate/container/qualApplication/filingChange/list", "备案变更管理"],
|
||
["/certificate/container/qualApplication/filingForm?mode=application", "备案表单(无id)"],
|
||
["/certificate/container/qualApplication/filingForm?mode=application&id=1", "备案表单(有id)"],
|
||
];
|
||
|
||
for (const [route, label] of pages) {
|
||
const res = await fetch(`${FRONTEND_BASE}${route}`);
|
||
assert(`HTTP-${label}`, res.status === 200, String(res.status));
|
||
}
|
||
|
||
const html = await (await fetch(`${FRONTEND_BASE}/certificate/`)).text();
|
||
const jsMatch = html.match(/src="(\/certificate\/static\/js\/main\.[^"]+\.js)"/);
|
||
assert("前端-main.js 可解析", !!jsMatch);
|
||
if (jsMatch) {
|
||
const js = await (await fetch(`${FRONTEND_BASE}${jsMatch[1]}`)).text();
|
||
const markers = [
|
||
"FilingApplicationListPage",
|
||
"qualApplication/filingApplication/list",
|
||
"PrerequisiteVerifyModal",
|
||
"QUALIFICATION_INDUSTRY_OPTIONS",
|
||
"persistFilingToBackend",
|
||
"verifyFilingPrerequisites",
|
||
"legalRepPersonnelId",
|
||
];
|
||
for (const marker of markers) {
|
||
assert(`Bundle-${marker}`, js.includes(marker));
|
||
}
|
||
}
|
||
}
|
||
|
||
async function main() {
|
||
console.log("资质申请管理 — 页面交互 + 后端全链路测试");
|
||
console.log(`API_BASE=${API_BASE} FRONTEND=${FRONTEND_BASE} orgInfoId=${ORG_INFO_ID}`);
|
||
|
||
testStaticNoPreCreate();
|
||
await testVerifyLogic();
|
||
await testPersistFlow();
|
||
await testFrontendBundle();
|
||
|
||
console.log(`\n=== 结果: ${passed} 通过, ${failed} 失败 ===\n`);
|
||
if (failed > 0) {
|
||
process.exit(1);
|
||
}
|
||
}
|
||
|
||
main().catch((err) => {
|
||
console.error(err);
|
||
process.exit(1);
|
||
});
|