const test = require("node:test"); const assert = require("node:assert/strict"); // The userscript exports some helpers in a shorthand object; in Node that means any // undeclared identifiers referenced there must exist on `global`. global.buildSpreadsheetXml = () => ""; global.document = { cookie: "x=y" }; const api = require("./xhs-pgy-export.user.js"); function okJson(payload) { return { ok: true, status: 200, async json() { return payload; }, }; } test("data_summary request includes business=1", async () => { const urls = []; async function fetchImpl(url) { urls.push(url); if (String(url).startsWith(api.API_BASE)) { return okJson({ data: { userId: "u-123" } }); } return okJson({ data: {} }); } await api.fetchMergedBloggerRecord("any-id", fetchImpl); const target = urls.find((u) => String(u).includes("/v1/pugongying/data_summary")); assert.ok(target, "expected a call to /v1/pugongying/data_summary"); const parsed = new URL(target); assert.equal(parsed.searchParams.get("business"), "1"); assert.equal(parsed.searchParams.get("userId"), "u-123"); });