const assert = require("assert");
const fs = require("fs");
const path = require("path");

const source = fs.readFileSync(
  path.resolve(__dirname, "../../src/views/ccdiProject/components/detail/PreliminaryCheck.vue"),
  "utf8"
);
const apiSource = fs.readFileSync(
  path.resolve(__dirname, "../../src/api/ccdi/projectOverview.js"),
  "utf8"
);

[
  "getOverviewDashboard",
  "getOverviewRiskPeople",
  "getOverviewRiskModelCards",
  "getOverviewEmployeeCreditNegative",
  "loadOverviewData",
  "Promise.all",
].forEach((token) => assert(source.includes(token), token));

assert(!source.includes("getOverviewTopRiskPeople"), "页面不应再依赖TOP10接口");
assert(!source.includes("topRiskPeopleRes"), "页面不应再处理TOP10响应");
assert(!source.includes("topRiskPeopleData"), "页面不应再处理TOP10数据");

const loadOverviewDataBlock = source.match(
  /const \[dashboardRes, riskPeopleRes, riskModelCardsRes, suspiciousRes, creditNegativeRes\] = await Promise\.all\(\[([\s\S]*?)\]\);/m
);

assert(loadOverviewDataBlock, "入口页应继续并发请求仪表盘、风险人员、模型卡片、涉疑交易和员工负面征信");
[
  "getOverviewDashboard(this.projectId)",
  "getOverviewRiskPeople({",
  "projectId: this.projectId",
  "pageNum: 1",
  "pageSize: 5",
  "getOverviewRiskModelCards(this.projectId)",
  "getOverviewSuspiciousTransactions({",
  "getOverviewEmployeeCreditNegative({",
].forEach((token) => assert(loadOverviewDataBlock[0].includes(token), token));

[
  "createOverviewLoadedData",
  "dashboardData",
  "riskPeopleData",
  "riskPeopleData.rows",
  "riskModelCardsData",
  "creditNegativeData",
].forEach((token) => assert(source.includes(token), token));

["employeeResult", "resultTable", "topRiskList"].forEach((token) =>
  assert(!source.includes(token), `入口页不应感知或回退到旧/新底层数据源字段：${token}`)
);

[
  "getOverviewPersonAnalysisDetail",
  "/ccdi/project/overview/person-analysis/detail",
  "staffIdCard: params.staffIdCard",
].forEach((token) => assert(apiSource.includes(token), token));
