feat: map favorites to batch records

This commit is contained in:
wxs
2026-07-17 12:08:45 +08:00
parent ac8e86ab7b
commit 27a4fbb1aa
2 changed files with 93 additions and 0 deletions
+76
View File
@@ -0,0 +1,76 @@
import { describe, expect, test } from "vitest";
import { toFavoriteMarketRecords } from "../src/content/market/favorites-import";
describe("favorites-import", () => {
test("returns no records for an empty favorites list", () => {
expect(toFavoriteMarketRecords([])).toEqual([]);
});
test("preserves a creator core user id for later batch payload mapping", () => {
expect(
toFavoriteMarketRecords([
{
authorId: "author-1",
authorName: "达人A",
coreUserId: "core-1",
savedAt: "2026-07-17T00:00:00.000Z"
}
])
).toEqual([
{
authorId: "author-1",
authorName: "达人A",
coreUserId: "core-1",
status: "idle"
}
]);
});
test("keeps the first creator for each author id in first-occurrence order", () => {
expect(
toFavoriteMarketRecords([
{
authorId: "author-2",
authorName: "达人B",
savedAt: "2026-07-17T00:00:00.000Z"
},
{
authorId: "author-1",
authorName: "达人A",
savedAt: "2026-07-17T00:00:01.000Z"
},
{
authorId: "author-2",
authorName: "达人B更新",
coreUserId: "core-2",
savedAt: "2026-07-17T00:00:02.000Z"
}
])
).toEqual([
{ authorId: "author-2", authorName: "达人B", status: "idle" },
{ authorId: "author-1", authorName: "达人A", status: "idle" }
]);
});
test("returns only the minimal idle market record fields", () => {
const [record] = toFavoriteMarketRecords([
{
authorId: "author-1",
authorName: "达人A",
savedAt: "2026-07-17T00:00:00.000Z"
}
]);
expect(record).toEqual({
authorId: "author-1",
authorName: "达人A",
status: "idle"
});
expect(Object.keys(record ?? {})).toEqual([
"authorId",
"authorName",
"status"
]);
});
});