279 lines
9.9 KiB
JavaScript
279 lines
9.9 KiB
JavaScript
/**
|
||
* 资质申请管理 — 前后端联调冒烟测试
|
||
*
|
||
* 运行:
|
||
* API_BASE=http://127.0.0.1:8095/safetyEval ORG_INFO_ID=1 node docs/test-reports/测试用例/test-qual-filing-api.mjs
|
||
*
|
||
* 可选:
|
||
* FRONTEND_BASE=http://127.0.0.1:8081 (检测前端页面是否可访问)
|
||
*/
|
||
const API_BASE = process.env.API_BASE || "http://127.0.0.1:8095/safetyEval";
|
||
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=";
|
||
|
||
const results = [];
|
||
let passed = 0;
|
||
let failed = 0;
|
||
|
||
function assert(name, condition, detail = "") {
|
||
if (condition) {
|
||
passed += 1;
|
||
results.push({ name, status: "PASS", detail });
|
||
console.log(` ✓ ${name}${detail ? ` — ${detail}` : ""}`);
|
||
}
|
||
else {
|
||
failed += 1;
|
||
results.push({ name, status: "FAIL", detail });
|
||
console.log(` ✗ ${name}${detail ? ` — ${detail}` : ""}`);
|
||
}
|
||
}
|
||
|
||
async function request(method, path, body) {
|
||
const url = `${API_BASE}${path}`;
|
||
const options = {
|
||
method,
|
||
headers: {
|
||
"Content-Type": "application/json",
|
||
orgInfoId: ORG_INFO_ID,
|
||
},
|
||
};
|
||
if (body !== undefined) {
|
||
options.body = JSON.stringify(body);
|
||
}
|
||
const res = await fetch(url, options);
|
||
const text = await res.text();
|
||
try {
|
||
return { httpStatus: res.status, ...JSON.parse(text) };
|
||
}
|
||
catch {
|
||
return { httpStatus: res.status, success: false, raw: text };
|
||
}
|
||
}
|
||
|
||
async function uploadAllMaterials(filingId) {
|
||
const detail = await request("GET", `/qual-filing/detail?id=${filingId}`);
|
||
const materials = detail.data?.materials || [];
|
||
for (const material of materials) {
|
||
const uploaded = await request("POST", "/qual-filing-material/upload", {
|
||
id: material.id,
|
||
attachmentUrl: DEFAULT_URL,
|
||
});
|
||
if (uploaded.success !== true) {
|
||
return { ok: false, message: uploaded.message, materialId: material.id };
|
||
}
|
||
}
|
||
return { ok: true, count: materials.length };
|
||
}
|
||
|
||
async function saveCommitment(filingId) {
|
||
return request("POST", "/qual-filing-commitment/save-or-update", {
|
||
filingId,
|
||
signDate: "2026-06-30",
|
||
legalRepSignatureUrl: DEFAULT_URL,
|
||
commitmentContent: "联调测试承诺书",
|
||
});
|
||
}
|
||
|
||
async function runBackendTests() {
|
||
console.log("\n=== 后端 API(资质申请管理)===");
|
||
console.log(`API_BASE=${API_BASE} orgInfoId=${ORG_INFO_ID}\n`);
|
||
|
||
// 1. 创建草稿 + 材料模板
|
||
const draft = await request("POST", "/qual-filing/draft?applyTypeCode=1");
|
||
assert("备案申请-创建草稿", draft.success === true && draft.data?.id, draft.message || `id=${draft.data?.id}`);
|
||
const filingId = draft.data?.id;
|
||
if (!filingId) {
|
||
return null;
|
||
}
|
||
|
||
const initTpl = await request("POST", `/qual-filing-material/init-template?filingId=${filingId}`);
|
||
assert("备案申请-初始化材料模板", initTpl.success === true, initTpl.message);
|
||
|
||
const detail1 = await request("GET", `/qual-filing/detail?id=${filingId}`);
|
||
assert("备案申请-详情含10项材料", detail1.data?.materials?.length === 10, `count=${detail1.data?.materials?.length}`);
|
||
|
||
// 2. 暂存基本信息
|
||
const saved = await request("POST", "/qual-filing/save-draft", {
|
||
id: filingId,
|
||
filingUnitName: "脚本联调评价机构",
|
||
filingTerritoryName: "渝北区",
|
||
filingTerritoryCode: "渝北区",
|
||
businessScope: "化工",
|
||
});
|
||
assert("备案申请-暂存基本信息", saved.success === true, saved.message);
|
||
|
||
// 3. 备案申请分页(applyTypeCode=1)
|
||
const appPage = await request("GET", `/qual-filing/page?current=1&size=20&applyTypeCode=1`);
|
||
const appTypes = new Set((appPage.data || []).map((row) => row.applyTypeCode));
|
||
assert(
|
||
"备案申请-分页仅 applyType=1",
|
||
appPage.success === true && appTypes.size <= 1 && (appTypes.size === 0 || appTypes.has(1)),
|
||
`types=${[...appTypes].join(",")} total=${appPage.total}`,
|
||
);
|
||
|
||
// 4. 上传材料 + 承诺书 + 提交
|
||
const uploadRes = await uploadAllMaterials(filingId);
|
||
assert("备案申请-上传全部材料", uploadRes.ok === true, uploadRes.message || `count=${uploadRes.count}`);
|
||
|
||
const commitment = await saveCommitment(filingId);
|
||
assert("备案申请-保存承诺书", commitment.success === true, commitment.message);
|
||
|
||
const submit = await request("POST", `/qual-filing/submit?id=${filingId}`);
|
||
assert(
|
||
"备案申请-提交审核",
|
||
submit.success === true && submit.data?.filingStatusCode === 2,
|
||
submit.message || submit.data?.filingStatusName,
|
||
);
|
||
|
||
// 5. 审核通过 → 生成已备案记录
|
||
const approve = await request("POST", `/qual-filing/approve?id=${filingId}`);
|
||
assert(
|
||
"备案申请-审核通过",
|
||
approve.success === true && approve.data?.filingStatusCode === 1 && approve.data?.filingStatusName === "已备案",
|
||
approve.message || approve.data?.filingStatusName,
|
||
);
|
||
|
||
const filedPage = await request("GET", "/qual-filing/filed/page?current=1&size=20");
|
||
const filedTypes = new Set((filedPage.data || []).map((row) => row.applyTypeCode));
|
||
const filedStatuses = new Set((filedPage.data || []).map((row) => row.filingStatusCode));
|
||
assert(
|
||
"已备案-分页仅 applyType=3",
|
||
filedPage.success === true && [...filedTypes].every((t) => t === 3),
|
||
`types=${[...filedTypes].join(",")} count=${filedPage.data?.length}`,
|
||
);
|
||
assert(
|
||
"已备案-默认不含暂存",
|
||
![...filedStatuses].includes(5),
|
||
`statuses=${[...filedStatuses].join(",")}`,
|
||
);
|
||
|
||
const originFilingId = filedPage.data?.[0]?.id;
|
||
assert("已备案-存在记录", !!originFilingId, `originId=${originFilingId}`);
|
||
|
||
// 6. 已备案填报草稿
|
||
const filedDraft = await request("POST", "/qual-filing/filed/draft");
|
||
assert("已备案-创建填报草稿", filedDraft.success === true && filedDraft.data?.id, filedDraft.message);
|
||
assert(
|
||
"已备案-填报草稿为暂存",
|
||
filedDraft.data?.filingStatusCode === 5,
|
||
filedDraft.data?.filingStatusName,
|
||
);
|
||
|
||
const changePage = await request("GET", "/qual-filing/change/page?current=1&size=20");
|
||
const changeStatuses = new Set((changePage.data || []).map((row) => row.filingStatusCode));
|
||
assert(
|
||
"备案变更-列表仅已备案/变更审核中",
|
||
changePage.success === true && [...changeStatuses].every((s) => s === 1 || s === 4),
|
||
`statuses=${[...changeStatuses].join(",")}`,
|
||
);
|
||
|
||
if (!originFilingId) {
|
||
return filingId;
|
||
}
|
||
|
||
// 7. 备案变更
|
||
const changeStart = await request("POST", `/qual-filing-change/start?originFilingId=${originFilingId}`);
|
||
const draftFilingId = changeStart.data;
|
||
assert("备案变更-发起变更", changeStart.success === true && draftFilingId, `draftId=${draftFilingId}`);
|
||
|
||
if (draftFilingId) {
|
||
await request("POST", "/qual-filing/save-draft", {
|
||
id: draftFilingId,
|
||
businessScope: "化工, 矿山",
|
||
});
|
||
await uploadAllMaterials(draftFilingId);
|
||
await saveCommitment(draftFilingId);
|
||
|
||
const changeSubmit = await request("POST", "/qual-filing-change/submit", { draftFilingId });
|
||
assert("备案变更-提交", changeSubmit.success === true, changeSubmit.message);
|
||
|
||
const history = await request("GET", `/qual-filing-change/history?originFilingId=${originFilingId}`);
|
||
assert(
|
||
"备案变更-历史明细",
|
||
history.success === true && (history.data?.changeCount ?? 0) >= 1,
|
||
`changeCount=${history.data?.changeCount} records=${history.data?.records?.length}`,
|
||
);
|
||
}
|
||
|
||
// 8. 人员/装备批量引入(有数据则测)
|
||
const personnelPage = await request("GET", "/org-personnel/page?current=1&size=1");
|
||
const personnelId = personnelPage.data?.[0]?.id;
|
||
if (personnelId) {
|
||
const newDraft = await request("POST", "/qual-filing/draft?applyTypeCode=1");
|
||
const pid = newDraft.data?.id;
|
||
const batchP = await request("POST", "/qual-filing-personnel/batch-add-from-org", {
|
||
filingId: pid,
|
||
sourcePersonnelIds: [personnelId],
|
||
});
|
||
assert("备案人员-批量引入", batchP.success === true, batchP.message);
|
||
}
|
||
else {
|
||
assert("备案人员-批量引入", true, "跳过:无企业人员数据");
|
||
}
|
||
|
||
const equipPage = await request("GET", "/org-equipment/page?current=1&size=1");
|
||
const equipId = equipPage.data?.[0]?.id;
|
||
if (equipId) {
|
||
const newDraft2 = await request("POST", "/qual-filing/draft?applyTypeCode=1");
|
||
const eid = newDraft2.data?.id;
|
||
const batchE = await request("POST", "/qual-filing-equipment/batch-add-from-org", {
|
||
filingId: eid,
|
||
sourceEquipmentIds: [equipId],
|
||
});
|
||
assert("备案装备-批量引入", batchE.success === true, batchE.message);
|
||
}
|
||
else {
|
||
assert("备案装备-批量引入", true, "跳过:无企业装备数据");
|
||
}
|
||
|
||
return filingId;
|
||
}
|
||
|
||
async function runFrontendSmokeTests() {
|
||
console.log("\n=== 前端页面可访问性 ===");
|
||
console.log(`FRONTEND_BASE=${FRONTEND_BASE}\n`);
|
||
|
||
const pages = [
|
||
["/certificate/container/qualApplication/filingApplication/list", "资质备案申请列表"],
|
||
["/certificate/container/qualApplication/filedManage/list", "已备案资质管理列表"],
|
||
["/certificate/container/qualApplication/filingChange/list", "备案变更管理列表"],
|
||
];
|
||
|
||
for (const [path, label] of pages) {
|
||
try {
|
||
const res = await fetch(`${FRONTEND_BASE}${path}`, { method: "GET" });
|
||
assert(`前端-${label}`, res.status === 200, `HTTP ${res.status}`);
|
||
}
|
||
catch (err) {
|
||
assert(`前端-${label}`, false, err.message);
|
||
}
|
||
}
|
||
}
|
||
|
||
async function main() {
|
||
console.log("资质申请管理 — 联调冒烟测试");
|
||
try {
|
||
await runBackendTests();
|
||
}
|
||
catch (err) {
|
||
failed += 1;
|
||
console.error("\n后端测试异常:", err);
|
||
}
|
||
|
||
try {
|
||
await runFrontendSmokeTests();
|
||
}
|
||
catch (err) {
|
||
console.warn("\n前端页面检测跳过:", err.message);
|
||
}
|
||
|
||
console.log(`\n=== 结果: ${passed} 通过, ${failed} 失败 ===\n`);
|
||
if (failed > 0) {
|
||
process.exit(1);
|
||
}
|
||
}
|
||
|
||
main();
|