mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-21 22:21:33 +00:00
* refactor: move Discord channel implementation to extensions/discord/src/ Move all Discord source files from src/discord/ to extensions/discord/src/, following the extension migration pattern. Source files in src/discord/ are replaced with re-export shims. Channel-plugin files from src/channels/plugins/*/discord* are similarly moved and shimmed. - Copy all .ts source files preserving subdirectory structure (monitor/, voice/) - Move channel-plugin files (actions, normalize, onboarding, outbound, status-issues) - Fix all relative imports to use correct paths from new location - Create re-export shims at original locations for backward compatibility - Delete test files from shim locations (tests live in extension now) - Update tsconfig.plugin-sdk.dts.json rootDir from "src" to "." to accommodate extension files outside src/ - Update write-plugin-sdk-entry-dts.ts to match new declaration output paths * fix: add importOriginal to thread-bindings session-meta mock for extensions test * style: fix formatting in thread-bindings lifecycle test
68 lines
2.1 KiB
TypeScript
68 lines
2.1 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { fetchPluralKitMessageInfo } from "./pluralkit.js";
|
|
|
|
type MockResponse = {
|
|
status: number;
|
|
ok: boolean;
|
|
text: () => Promise<string>;
|
|
json: () => Promise<unknown>;
|
|
};
|
|
|
|
const buildResponse = (params: { status: number; body?: unknown }): MockResponse => {
|
|
const body = params.body;
|
|
const textPayload = typeof body === "string" ? body : body == null ? "" : JSON.stringify(body);
|
|
return {
|
|
status: params.status,
|
|
ok: params.status >= 200 && params.status < 300,
|
|
text: async () => textPayload,
|
|
json: async () => body ?? {},
|
|
};
|
|
};
|
|
|
|
describe("fetchPluralKitMessageInfo", () => {
|
|
it("returns null when disabled", async () => {
|
|
const fetcher = vi.fn();
|
|
const result = await fetchPluralKitMessageInfo({
|
|
messageId: "123",
|
|
config: { enabled: false },
|
|
fetcher: fetcher as unknown as typeof fetch,
|
|
});
|
|
expect(result).toBeNull();
|
|
expect(fetcher).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("returns null on 404", async () => {
|
|
const fetcher = vi.fn(async () => buildResponse({ status: 404 }));
|
|
const result = await fetchPluralKitMessageInfo({
|
|
messageId: "missing",
|
|
config: { enabled: true },
|
|
fetcher: fetcher as unknown as typeof fetch,
|
|
});
|
|
expect(result).toBeNull();
|
|
});
|
|
|
|
it("returns payload and sends token when configured", async () => {
|
|
let receivedHeaders: Record<string, string> | undefined;
|
|
const fetcher = vi.fn(async (_url: string, init?: RequestInit) => {
|
|
receivedHeaders = init?.headers as Record<string, string> | undefined;
|
|
return buildResponse({
|
|
status: 200,
|
|
body: {
|
|
id: "123",
|
|
member: { id: "mem_1", name: "Alex" },
|
|
system: { id: "sys_1", name: "System" },
|
|
},
|
|
});
|
|
});
|
|
|
|
const result = await fetchPluralKitMessageInfo({
|
|
messageId: "123",
|
|
config: { enabled: true, token: "pk_test" },
|
|
fetcher: fetcher as unknown as typeof fetch,
|
|
});
|
|
|
|
expect(result?.member?.id).toBe("mem_1");
|
|
expect(receivedHeaders?.Authorization).toBe("pk_test");
|
|
});
|
|
});
|