57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
import { describe, expect, test, vi } from "vitest";
|
|
|
|
import {
|
|
buildAuthorBaseInfoUrl,
|
|
createAuthorBaseClient,
|
|
mapAuthorBaseInfoResponse
|
|
} from "../src/content/market/author-base-client";
|
|
|
|
describe("author-base-client", () => {
|
|
test("builds Xingtu author base info url", () => {
|
|
expect(
|
|
buildAuthorBaseInfoUrl("6866044569306267651", "https://www.xingtu.cn")
|
|
).toBe(
|
|
"https://www.xingtu.cn/gw/api/author/get_author_base_info?o_author_id=6866044569306267651&platform_source=1&platform_channel=1&recommend=true&need_sec_uid=true&need_linkage_info=true"
|
|
);
|
|
});
|
|
|
|
test("maps author nickname into a market record", () => {
|
|
expect(mapAuthorBaseInfoResponse("6866044569306267651", {
|
|
base_resp: { status_code: 0, status_message: "Success" },
|
|
nick_name: "小九儿"
|
|
})).toEqual({
|
|
authorId: "6866044569306267651",
|
|
authorName: "小九儿",
|
|
status: "success"
|
|
});
|
|
});
|
|
|
|
test("loads author base info from Xingtu", async () => {
|
|
const fetchImpl = vi.fn(async () => ({
|
|
json: async () => ({
|
|
base_resp: { status_code: 0, status_message: "Success" },
|
|
nick_name: "小九儿"
|
|
}),
|
|
ok: true
|
|
}));
|
|
const client = createAuthorBaseClient({
|
|
baseUrl: "https://www.xingtu.cn",
|
|
fetchImpl,
|
|
timeoutMs: 1000
|
|
});
|
|
|
|
await expect(client.loadAuthorBaseInfo("6866044569306267651")).resolves.toEqual({
|
|
authorId: "6866044569306267651",
|
|
authorName: "小九儿",
|
|
status: "success"
|
|
});
|
|
expect(fetchImpl).toHaveBeenCalledWith(
|
|
"https://www.xingtu.cn/gw/api/author/get_author_base_info?o_author_id=6866044569306267651&platform_source=1&platform_channel=1&recommend=true&need_sec_uid=true&need_linkage_info=true",
|
|
expect.objectContaining({
|
|
credentials: "include",
|
|
method: "GET"
|
|
})
|
|
);
|
|
});
|
|
});
|