200 lines
6.8 KiB
JavaScript
200 lines
6.8 KiB
JavaScript
|
|
/**
|
|||
|
|
* 资质申请管理 — 三模块审核接口 + 整体流程联调
|
|||
|
|
*
|
|||
|
|
* 运行:
|
|||
|
|
* API_BASE=http://127.0.0.1:8095/safety-eval ORG_INFO_ID=1 node docs/test-reports/测试用例/test-qual-filing-audit-flow.mjs
|
|||
|
|
*/
|
|||
|
|
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 DEFAULT_URL =
|
|||
|
|
"https://s1.aigei.com/prevfiles/6f2754563be2491bad7c957904cd7d2a.jpg?e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:CR60zg7VKDp-jUWyYls_rdvyQMM=";
|
|||
|
|
|
|||
|
|
let passed = 0;
|
|||
|
|
let failed = 0;
|
|||
|
|
|
|||
|
|
function ok(name, cond, detail = "") {
|
|||
|
|
if (cond) {
|
|||
|
|
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 };
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async function uploadAllMaterials(filingId) {
|
|||
|
|
const detail = await api("GET", `/qual-filing/detail?id=${filingId}`);
|
|||
|
|
for (const m of detail.data?.materials || []) {
|
|||
|
|
if (!m.attachmentUrl) {
|
|||
|
|
await api("POST", "/qual-filing-material/upload", { id: m.id, attachmentUrl: DEFAULT_URL });
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async function saveCommitment(filingId) {
|
|||
|
|
return api("POST", "/qual-filing-commitment/save-or-update", {
|
|||
|
|
filingId,
|
|||
|
|
signDate: "2026-06-30",
|
|||
|
|
legalRepSignatureUrl: DEFAULT_URL,
|
|||
|
|
commitmentContent: "审核流程联调测试承诺书",
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async function persistMinimal(filingId) {
|
|||
|
|
await api("POST", "/qual-filing/save-draft", {
|
|||
|
|
id: filingId,
|
|||
|
|
filingUnitName: "审核流程测试机构",
|
|||
|
|
filingTerritoryName: "渝北区",
|
|||
|
|
businessScope: "化工",
|
|||
|
|
});
|
|||
|
|
await api("POST", `/qual-filing-material/init-template?filingId=${filingId}`);
|
|||
|
|
await uploadAllMaterials(filingId);
|
|||
|
|
await saveCommitment(filingId);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async function testModule1ApplicationAudit() {
|
|||
|
|
console.log("\n=== 模块1:资质备案申请(提交 + 审核) ===");
|
|||
|
|
|
|||
|
|
const draft = await api("POST", "/qual-filing/draft?applyTypeCode=1");
|
|||
|
|
const filingId = draft.data?.id;
|
|||
|
|
ok("1.创建申请草稿", draft.success && filingId, `id=${filingId}`);
|
|||
|
|
if (!filingId) {
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
await persistMinimal(filingId);
|
|||
|
|
|
|||
|
|
const submit = await api("POST", `/qual-filing/submit?id=${filingId}`);
|
|||
|
|
ok("2.提交审核 POST /qual-filing/submit", submit.success && submit.data?.filingStatusCode === 2, submit.data?.filingStatusName);
|
|||
|
|
|
|||
|
|
const approve = await api("POST", `/qual-filing/approve?id=${filingId}`);
|
|||
|
|
ok(
|
|||
|
|
"3.审核通过 POST /qual-filing/approve",
|
|||
|
|
approve.success && approve.data?.filingStatusCode === 1,
|
|||
|
|
approve.data?.filingStatusName,
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
const filedPage = await api("GET", "/qual-filing/filed/page?current=1&size=5");
|
|||
|
|
const master = (filedPage.data || []).find((r) => r.filingStatusCode === 1);
|
|||
|
|
ok("4.审核后生成已备案主记录", !!master, master ? `masterId=${master.id}` : "filed/page 无已备案");
|
|||
|
|
|
|||
|
|
return { applicationId: filingId, masterId: master?.id };
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async function testModule2FiledManageAudit(masterId) {
|
|||
|
|
console.log("\n=== 模块2:已备案资质管理(填报提交 + 审核) ===");
|
|||
|
|
if (!masterId) {
|
|||
|
|
ok("跳过-无已备案主记录", false);
|
|||
|
|
return masterId;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const filedDraft = await api("POST", "/qual-filing/filed/draft");
|
|||
|
|
const draftId = filedDraft.data?.id;
|
|||
|
|
ok("1.创建填报草稿 POST /qual-filing/filed/draft", filedDraft.success && draftId, `id=${draftId}`);
|
|||
|
|
if (!draftId) {
|
|||
|
|
return masterId;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
await persistMinimal(draftId);
|
|||
|
|
|
|||
|
|
const submit = await api("POST", `/qual-filing/submit?id=${draftId}`);
|
|||
|
|
ok("2.提交填报审核 POST /qual-filing/submit", submit.success && submit.data?.filingStatusCode === 2, submit.data?.filingStatusName);
|
|||
|
|
|
|||
|
|
const approve = await api("POST", `/qual-filing/approve?id=${draftId}`);
|
|||
|
|
ok(
|
|||
|
|
"3.填报审核通过 POST /qual-filing/approve",
|
|||
|
|
approve.success && approve.data?.filingStatusCode === 1,
|
|||
|
|
approve.data?.filingStatusName,
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
return masterId;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async function testModule3ChangeAudit(originId) {
|
|||
|
|
console.log("\n=== 模块3:备案变更管理(变更提交 + 审核) ===");
|
|||
|
|
if (!originId) {
|
|||
|
|
ok("跳过-无变更源记录", false);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const originBefore = await api("GET", `/qual-filing/get?id=${originId}`);
|
|||
|
|
ok("1.变更源为已备案", originBefore.data?.filingStatusCode === 1, originBefore.data?.filingStatusName);
|
|||
|
|
|
|||
|
|
const start = await api("POST", `/qual-filing-change/start?originFilingId=${originId}`);
|
|||
|
|
const changeDraftId = start.data;
|
|||
|
|
ok("2.发起变更 POST /qual-filing-change/start", start.success && changeDraftId, `draftId=${changeDraftId}`);
|
|||
|
|
if (!changeDraftId) {
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
await api("POST", "/qual-filing/save-draft", {
|
|||
|
|
id: changeDraftId,
|
|||
|
|
businessScope: "化工, 矿山采选业",
|
|||
|
|
unitIntro: "变更后业务范围说明",
|
|||
|
|
});
|
|||
|
|
await uploadAllMaterials(changeDraftId);
|
|||
|
|
await saveCommitment(changeDraftId);
|
|||
|
|
|
|||
|
|
const changeSubmit = await api("POST", "/qual-filing-change/submit", { draftFilingId: changeDraftId });
|
|||
|
|
ok("3.提交变更审核 POST /qual-filing-change/submit", changeSubmit.success === true, changeSubmit.message);
|
|||
|
|
|
|||
|
|
const changePage = await api(
|
|||
|
|
"GET",
|
|||
|
|
`/qual-filing-change/page?current=1&size=5&originFilingId=${originId}&filingStatusCode=2`,
|
|||
|
|
);
|
|||
|
|
const pendingChange = (changePage.data || [])[0];
|
|||
|
|
const changeId = pendingChange?.id;
|
|||
|
|
ok("4.查询待审变更单 GET /qual-filing-change/page", !!changeId, `changeId=${changeId}`);
|
|||
|
|
|
|||
|
|
if (!changeId) {
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const changeApprove = await api("POST", `/qual-filing-change/approve?changeId=${changeId}`);
|
|||
|
|
ok("5.变更审核通过 POST /qual-filing-change/approve", changeApprove.success === true, changeApprove.message);
|
|||
|
|
|
|||
|
|
const originAfter = await api("GET", `/qual-filing/get?id=${originId}`);
|
|||
|
|
ok(
|
|||
|
|
"6.变更通过后主记录恢复已备案",
|
|||
|
|
originAfter.data?.filingStatusCode === 1,
|
|||
|
|
originAfter.data?.filingStatusName,
|
|||
|
|
);
|
|||
|
|
ok(
|
|||
|
|
"7.变更内容已生效",
|
|||
|
|
(originAfter.data?.businessScope || "").includes("矿山"),
|
|||
|
|
originAfter.data?.businessScope,
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async function main() {
|
|||
|
|
console.log("资质申请管理 — 三模块审核接口整体流程测试");
|
|||
|
|
console.log(`API_BASE=${API_BASE} orgInfoId=${ORG_INFO_ID}`);
|
|||
|
|
|
|||
|
|
const ctx = await testModule1ApplicationAudit();
|
|||
|
|
const masterId = await testModule2FiledManageAudit(ctx?.masterId);
|
|||
|
|
await testModule3ChangeAudit(masterId);
|
|||
|
|
|
|||
|
|
console.log(`\n=== 结果: ${passed} 通过, ${failed} 失败 ===`);
|
|||
|
|
if (failed > 0) {
|
|||
|
|
process.exitCode = 1;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
await main();
|