fix: hydrate id export metrics and remove new tier columns

This commit is contained in:
2026-05-18 19:50:14 +08:00
parent 38da39589f
commit 37f7e0b5e6
4 changed files with 114 additions and 11 deletions
+58 -5
View File
@@ -1728,6 +1728,26 @@ describe("market-content-entry", () => {
gender: [{ label: "男性", value: "60%" }],
status: "success" as const
}));
const loadAuthorMetrics = vi.fn(async (authorId: string) => ({
rates: {
personalVideoAfterSearchRate:
authorId === "6866044569306267651" ? "12.3%" : "45.6%",
singleVideoAfterSearchRate:
authorId === "6866044569306267651" ? "7.8%" : "9.1%"
},
success: true as const
}));
const searchBackendMetrics = vi.fn(async (starIds: string[]) =>
starIds.map((starId) => ({
a3IncreaseCount: starId === "6866044569306267651" ? "100" : "200",
afterViewSearchCount: starId === "6866044569306267651" ? "300" : "400",
afterViewSearchRate: starId === "6866044569306267651" ? "1.1%" : "2.2%",
cpSearch: starId === "6866044569306267651" ? "10" : "20",
cpa3: starId === "6866044569306267651" ? "30" : "40",
newA3Rate: starId === "6866044569306267651" ? "3.3%" : "4.4%",
starId
}))
);
const onCsvReady = vi.fn();
const { createMarketController } = await import("../src/content/market/index");
@@ -1737,10 +1757,7 @@ describe("market-content-entry", () => {
loadAuthorBaseInfo,
loadBusinessAbility,
loadAudienceProfile,
loadAuthorMetrics: async () => ({
success: false,
reason: "request-failed"
}),
loadAuthorMetrics,
onCsvReady,
promptAuthorIds: () => `
6866044569306267651
@@ -1748,10 +1765,13 @@ describe("market-content-entry", () => {
6866044569306267651
bad-id
`,
searchBackendMetrics,
window
}));
await controller.ready;
loadAuthorMetrics.mockClear();
searchBackendMetrics.mockClear();
click('[data-plugin-export-audience-profile-by-id="button"]');
await waitForMockCall(buildAudienceProfileCsv, 40, 50);
@@ -1761,23 +1781,56 @@ describe("market-content-entry", () => {
]);
expect(loadAudienceProfile).toHaveBeenCalledTimes(6);
expect(loadBusinessAbility).toHaveBeenCalledTimes(2);
expect(loadAuthorMetrics.mock.calls.map(([authorId]) => authorId)).toEqual([
"6866044569306267651",
"7040323176106033165"
]);
expect(searchBackendMetrics).toHaveBeenCalledTimes(1);
expect(searchBackendMetrics).toHaveBeenCalledWith([
"6866044569306267651",
"7040323176106033165"
]);
expect(buildAudienceProfileCsv).toHaveBeenCalledWith([
expect.objectContaining({
record: expect.objectContaining({
authorId: "6866044569306267651",
authorName: "小九儿",
backendMetrics: expect.objectContaining({
a3IncreaseCount: "100",
afterViewSearchCount: "300",
afterViewSearchRate: "1.1%",
cpSearch: "10",
cpa3: "30",
newA3Rate: "3.3%"
}),
exportFields: {
ID: "6866044569306267651",
: "小九儿",
: "成功",
: ""
},
rates: {
personalVideoAfterSearchRate: "12.3%",
singleVideoAfterSearchRate: "7.8%"
}
})
}),
expect.objectContaining({
record: expect.objectContaining({
authorId: "7040323176106033165",
authorName: "达人 B"
authorName: "达人 B",
backendMetrics: expect.objectContaining({
a3IncreaseCount: "200",
afterViewSearchCount: "400",
afterViewSearchRate: "2.2%",
cpSearch: "20",
cpa3: "40",
newA3Rate: "4.4%"
}),
rates: {
personalVideoAfterSearchRate: "45.6%",
singleVideoAfterSearchRate: "9.1%"
}
})
})
]);