import { describe, expect, test } from "vitest"; import { buildAudienceProfileCsv } from "../src/content/market/audience-profile-csv"; import type { AudienceProfileExportRow } from "../src/content/market/audience-profile-types"; describe("audience-profile-csv", () => { test("appends structured audience profile columns after the market export columns", () => { const csv = buildAudienceProfileCsv([ { profile: { age: [{ label: "31-40", value: "50%" }], cityTier: [{ label: "一线城市", value: "100%" }], cityTop: [{ label: "广州", value: "30.4%" }], crowd: [{ label: "都市蓝领", value: "100%" }], gender: [ { label: "男性", value: "71.7%" }, { label: "女性", value: "28.3%" } ], interest: [{ label: "随拍", value: "100%" }], province: [{ label: "广东", value: "60%" }], status: "success" }, record: { authorId: "123", authorName: "达人 A", exportFields: { 达人信息: "达人 A", 连接用户数: "300w" }, status: "success" } } ] satisfies AudienceProfileExportRow[]); const [headerLine, rowLine] = csv.split("\n"); expect(headerLine).toContain("达人信息,连接用户数"); expect(headerLine).toContain("画像抓取状态"); expect(headerLine).toContain("连接用户-男性占比"); expect(headerLine).toContain("连接用户-31-40占比"); expect(headerLine).toContain("省份-广东占比"); expect(headerLine).toContain("地域TOP1名称,地域TOP1占比"); expect(headerLine).toContain("城市等级-一线城市占比"); expect(headerLine).toContain("兴趣TOP1名称,兴趣TOP1占比"); expect(headerLine).toContain("八大人群-都市蓝领占比"); expect(rowLine).toContain("成功"); expect(rowLine).toContain("71.7%"); expect(rowLine).toContain("广州,30.4%"); expect(rowLine).toContain("随拍,100%"); }); test("keeps failed profile rows and marks their failure reason", () => { const csv = buildAudienceProfileCsv([ { profile: { failureReason: "request-failed", status: "failed" }, record: { authorId: "123", authorName: "达人 A", status: "success" } } ] satisfies AudienceProfileExportRow[]); const [, rowLine] = csv.split("\n"); expect(rowLine).toContain("失败"); expect(rowLine).toContain("request-failed"); }); });