Add market watch and match hub workflows
这个提交包含在:
54
server/tutorialMetrics.test.ts
普通文件
54
server/tutorialMetrics.test.ts
普通文件
@@ -0,0 +1,54 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { fetchTutorialMetrics, shouldRefreshTutorialMetrics } from "./tutorialMetrics";
|
||||
|
||||
describe("shouldRefreshTutorialMetrics", () => {
|
||||
it("returns false without a supported source", () => {
|
||||
expect(shouldRefreshTutorialMetrics({ sourcePlatform: "site", platformVideoId: null })).toBe(false);
|
||||
});
|
||||
|
||||
it("returns true when metrics are missing", () => {
|
||||
expect(shouldRefreshTutorialMetrics({
|
||||
sourcePlatform: "bilibili",
|
||||
platformVideoId: "BV1test",
|
||||
metricsFetchedAt: null,
|
||||
})).toBe(true);
|
||||
});
|
||||
|
||||
it("returns false for fresh cached metrics", () => {
|
||||
expect(shouldRefreshTutorialMetrics({
|
||||
sourcePlatform: "bilibili",
|
||||
platformVideoId: "BV1test",
|
||||
metricsFetchedAt: new Date(),
|
||||
viewCount: 120,
|
||||
commentCount: 8,
|
||||
})).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("fetchTutorialMetrics", () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("parses bilibili metrics payloads", async () => {
|
||||
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: {
|
||||
pic: "http://i0.hdslb.com/demo.jpg",
|
||||
stat: {
|
||||
view: 3210,
|
||||
reply: 42,
|
||||
},
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
const result = await fetchTutorialMetrics("bilibili", "BV1demo");
|
||||
expect(result).toMatchObject({
|
||||
viewCount: 3210,
|
||||
commentCount: 42,
|
||||
thumbnailUrl: "https://i0.hdslb.com/demo.jpg",
|
||||
});
|
||||
});
|
||||
});
|
||||
在新工单中引用
屏蔽一个用户