feat: simplify KOC resource imports
This commit is contained in:
@@ -4,7 +4,9 @@ import { buildRecoveryWorkbook } from "../lib/recovery-workbook.ts";
|
||||
import {
|
||||
mergeCooperationSources,
|
||||
normalizeProfileUrl,
|
||||
parseResourceFollowers,
|
||||
parseResourceImportFile,
|
||||
resourceImportMissingFields,
|
||||
resourcePlatformUid,
|
||||
} from "../lib/resource-import.ts";
|
||||
|
||||
@@ -21,14 +23,50 @@ test("parses CSV resources and normalizes public profile data", () => {
|
||||
nickname: "",
|
||||
publicAccountId: "",
|
||||
profileUrl: "https://www.xiaohongshu.com/user/profile/abc123",
|
||||
ipLocation: "待识别",
|
||||
ipLocation: "",
|
||||
followers: 0,
|
||||
followersResolved: false,
|
||||
cooperationSource: "林林KOC社群",
|
||||
errors: [],
|
||||
});
|
||||
assert.equal(resourcePlatformUid(rows[0]), "abc123");
|
||||
});
|
||||
|
||||
test("uses optional account fields directly and only requires the profile URL", () => {
|
||||
const csv = [
|
||||
"账号链接,账号昵称,账号ID,IP属地,粉丝数,合作来源",
|
||||
"https://www.xiaohongshu.com/user/profile/abc123,番茄不炒蛋,4171542126,江西,10+,历史资源",
|
||||
].join("\n");
|
||||
const [row] = parseResourceImportFile(
|
||||
"resources.csv",
|
||||
new TextEncoder().encode(csv),
|
||||
);
|
||||
assert.equal(row.nickname, "番茄不炒蛋");
|
||||
assert.equal(row.publicAccountId, "4171542126");
|
||||
assert.equal(row.ipLocation, "江西");
|
||||
assert.equal(row.followers, 10);
|
||||
assert.equal(row.followersResolved, true);
|
||||
assert.deepEqual(resourceImportMissingFields(row), []);
|
||||
});
|
||||
|
||||
test("normalizes common follower formats and identifies missing enrichment fields", () => {
|
||||
assert.deepEqual(parseResourceFollowers("1.3万"), {
|
||||
value: 13_000,
|
||||
resolved: true,
|
||||
valid: true,
|
||||
});
|
||||
assert.deepEqual(parseResourceFollowers("10+"), {
|
||||
value: 10,
|
||||
resolved: true,
|
||||
valid: true,
|
||||
});
|
||||
assert.deepEqual(parseResourceFollowers(""), {
|
||||
value: 0,
|
||||
resolved: false,
|
||||
valid: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("parses the first matching worksheet from an XLSX workbook", () => {
|
||||
const workbook = buildRecoveryWorkbook({
|
||||
sheetName: "KOC资源导入",
|
||||
@@ -45,6 +83,7 @@ test("parses the first matching worksheet from an XLSX workbook", () => {
|
||||
assert.equal(rows[0].platform, "小红书");
|
||||
assert.equal(rows[0].cooperationSource, "存量资源包");
|
||||
assert.equal(rows[0].errors.length, 0);
|
||||
assert.equal(rows[0].followersResolved, false);
|
||||
});
|
||||
|
||||
test("reports invalid required fields without hiding valid rows", () => {
|
||||
@@ -54,6 +93,18 @@ test("reports invalid required fields without hiding valid rows", () => {
|
||||
assert.match(rows[1].errors.join(";"), /仅支持小红书账号主页/);
|
||||
});
|
||||
|
||||
test("rejects invalid optional follower values without requiring other optional fields", () => {
|
||||
const csv = [
|
||||
"账号链接,粉丝数",
|
||||
"https://www.xiaohongshu.com/user/profile/abc123,很多",
|
||||
].join("\n");
|
||||
const [row] = parseResourceImportFile(
|
||||
"resources.csv",
|
||||
new TextEncoder().encode(csv),
|
||||
);
|
||||
assert.match(row.errors.join(";"), /粉丝数格式不正确/);
|
||||
});
|
||||
|
||||
test("normalizes profile URLs and merges cooperation sources", () => {
|
||||
assert.equal(
|
||||
normalizeProfileUrl("https://www.xiaohongshu.com/user/profile/abc/?foo=1#top"),
|
||||
|
||||
Reference in New Issue
Block a user