import { createMockFetch, YEMA_USER_BASIC, YEMA_USER_ERROR } from "@umt/testkit"; import { describe, expect, it } from "vitest"; import { runParser } from "./testing.ts"; import { YemaSiteUserInfo } from "./yema.ts"; const URL_ = "https://www.yemapt.org/openApi/user/fetchBasicInfo.json"; describe("YemaSiteUserInfo(MP yema.py)", () => { it("POST fetchBasicInfo(JSON 体,Authorization=AuthKey):促销流量为上传/下载", async () => { const m = createMockFetch({ [`POST ${URL_}`]: { body: YEMA_USER_BASIC } }); const info = await runParser(YemaSiteUserInfo, { fetch: m.fetch, url: "https://www.yemapt.org/", apikey: "ak" }); expect(info).toMatchObject({ schema: "Yema", userId: "321", username: "leo", userLevel: "3", joinAt: "2024-05-06 07:08:09", upload: 3000, download: 1000, ratio: 3, bonus: 12.3, }); const req = m.requests[0]!; expect(req.headers.authorization).toBe("ak"); expect(req.headers["content-type"]).toBe("application/json"); expect(req.body).toBe("{}"); }); it("success=false:errMsg 为 errorMessage", async () => { const m = createMockFetch({ [`POST ${URL_}`]: { body: YEMA_USER_ERROR } }); const info = await runParser(YemaSiteUserInfo, { fetch: m.fetch, url: "https://www.yemapt.org/", apikey: "x" }); expect(info.userId).toBeNull(); expect(info.errMsg).toBe("AuthKey 无效"); }); });