mirror of
https://github.com/openclaw/clawhub.git
synced 2026-08-14 08:52:21 +00:00
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
/* @vitest-environment node */
|
|
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const queryMock = vi.fn();
|
|
const clientCtorMock = vi.fn();
|
|
|
|
vi.mock("convex/browser", () => ({
|
|
ConvexHttpClient: class ConvexHttpClientMock {
|
|
constructor(url: string) {
|
|
clientCtorMock(url);
|
|
}
|
|
|
|
query = queryMock;
|
|
},
|
|
}));
|
|
|
|
vi.mock("../../convex/_generated/api", () => ({
|
|
api: { publishers: { getOgMetaByHandle: "publishers.getOgMetaByHandle" } },
|
|
}));
|
|
|
|
describe("fetchPublisherOgMeta", () => {
|
|
beforeEach(() => {
|
|
queryMock.mockReset();
|
|
clientCtorMock.mockReset();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.resetModules();
|
|
});
|
|
|
|
it("reads downloads from publisher profile stats", async () => {
|
|
queryMock.mockResolvedValue({
|
|
handle: "openclaw",
|
|
kind: "org",
|
|
displayName: "OpenClaw",
|
|
bio: "Build with claws.",
|
|
image: null,
|
|
official: true,
|
|
affiliations: [
|
|
{
|
|
publisher: {
|
|
handle: "github",
|
|
displayName: "GitHub",
|
|
image: "https://example.com/github.png",
|
|
},
|
|
},
|
|
],
|
|
stats: { downloads: 99, installs: 1200 },
|
|
});
|
|
|
|
const { fetchPublisherOgMeta } = await import("./fetchPublisherOgMeta");
|
|
const meta = await fetchPublisherOgMeta("openclaw", "https://example.convex.cloud");
|
|
|
|
expect(clientCtorMock).toHaveBeenCalledWith("https://example.convex.cloud");
|
|
expect(queryMock).toHaveBeenCalledWith("publishers.getOgMetaByHandle", {
|
|
handle: "openclaw",
|
|
});
|
|
expect(meta?.stats.downloads).toBe(99);
|
|
expect(meta?.official).toBe(true);
|
|
expect(meta?.affiliations).toEqual([
|
|
{ handle: "github", displayName: "GitHub", image: "https://example.com/github.png" },
|
|
]);
|
|
});
|
|
});
|