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

const apiPath = path.resolve(__dirname, "../../src/api/ccdiCreditInfo.js");
const pagePath = path.resolve(__dirname, "../../src/views/ccdiCreditInfo/index.vue");

const apiSource = fs.readFileSync(apiPath, "utf8");
const pageSource = fs.readFileSync(pagePath, "utf8");

assert(
  apiSource.includes("const formData = new FormData()"),
  "征信上传 API 应在接口层构造 FormData，避免页面层直接传裸 FormData"
);
assert(
  apiSource.includes("files.forEach((file) => {"),
  "征信上传 API 应逐个追加批量文件"
);
assert(
  apiSource.includes("formData.append('files', file)"),
  "征信上传 API 应按后端约定使用 files 字段名"
);
assert(
  apiSource.includes("'Content-Type': 'multipart/form-data'"),
  "征信上传 API 必须显式声明 multipart/form-data 请求头"
);
assert(
  pageSource.includes("const files = this.uploadFileList.map((file) => file.raw || file);") &&
    pageSource.includes("uploadCreditHtml(files)"),
  "征信上传页面应把原始文件数组交给 API 层处理"
);
assert(
  !pageSource.includes("const formData = new FormData();"),
  "征信上传页面不应自行拼装 FormData"
);

console.log("credit-info-upload-api-behavior test passed");
