import { JSDOM } from "jsdom"; import { describe, expect, test } from "vitest"; import { extractAuthorIdFromRow } from "../src/content/market/id-extractor"; import { createListSignature } from "../src/content/market/list-signature"; describe("market id extractor", () => { test("extracts authorId from a detail link inside the row", () => { const row = createRow( '达人详情' ); expect(extractAuthorIdFromRow(row)).toEqual({ authorId: "6629661559960371207", source: "detail-link", success: true }); }); test("extracts authorId from fallback row attributes", () => { const row = createRow( '' ); expect(extractAuthorIdFromRow(row)).toEqual({ authorId: "7312345678901234567", source: "attribute", success: true }); }); test("returns an explicit missing-author-id result when no stable source exists", () => { const row = createRow('没有达人 id'); expect(extractAuthorIdFromRow(row)).toEqual({ authorId: null, reason: "missing-author-id", success: false }); }); test("builds a deterministic list signature from authorIds and url state", () => { expect( createListSignature({ authorIds: ["111", "222", "333"], url: "https://xingtu.cn/ad/creator/market?page=2&keyword=test" }) ).toBe("/ad/creator/market?page=2&keyword=test::111,222,333"); }); }); function createRow(innerHtml: string) { const dom = new JSDOM( `
| ${innerHtml} |