mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:31:22 +00:00
fix: align extension tests and fetch typing for gate stability (#12816)
This commit is contained in:
@@ -83,6 +83,7 @@ vi.mock("@opentelemetry/sdk-trace-base", () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@opentelemetry/resources", () => ({
|
vi.mock("@opentelemetry/resources", () => ({
|
||||||
|
resourceFromAttributes: vi.fn((attrs: Record<string, unknown>) => attrs),
|
||||||
Resource: class {
|
Resource: class {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
||||||
constructor(_value?: unknown) {}
|
constructor(_value?: unknown) {}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export type MonitorMattermostOpts = {
|
|||||||
statusSink?: (patch: Partial<ChannelAccountSnapshot>) => void;
|
statusSink?: (patch: Partial<ChannelAccountSnapshot>) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
type FetchLike = typeof fetch;
|
type FetchLike = (input: URL | RequestInfo, init?: RequestInit) => Promise<Response>;
|
||||||
type MediaKind = "image" | "audio" | "video" | "document" | "unknown";
|
type MediaKind = "image" | "audio" | "video" | "document" | "unknown";
|
||||||
|
|
||||||
type MattermostEventPayload = {
|
type MattermostEventPayload = {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ vi.mock("./utils/twitch.js", () => ({
|
|||||||
describe("outbound", () => {
|
describe("outbound", () => {
|
||||||
const mockAccount = {
|
const mockAccount = {
|
||||||
username: "testbot",
|
username: "testbot",
|
||||||
token: "oauth:test123",
|
accessToken: "oauth:test123",
|
||||||
clientId: "test-client-id",
|
clientId: "test-client-id",
|
||||||
channel: "#testchannel",
|
channel: "#testchannel",
|
||||||
};
|
};
|
||||||
@@ -196,7 +196,14 @@ describe("outbound", () => {
|
|||||||
|
|
||||||
expect(result.channel).toBe("twitch");
|
expect(result.channel).toBe("twitch");
|
||||||
expect(result.messageId).toBe("twitch-msg-123");
|
expect(result.messageId).toBe("twitch-msg-123");
|
||||||
expect(result.to).toBe("testchannel");
|
expect(sendMessageTwitchInternal).toHaveBeenCalledWith(
|
||||||
|
"testchannel",
|
||||||
|
"Hello Twitch!",
|
||||||
|
mockConfig,
|
||||||
|
"default",
|
||||||
|
true,
|
||||||
|
console,
|
||||||
|
);
|
||||||
expect(result.timestamp).toBeGreaterThan(0);
|
expect(result.timestamp).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ vi.mock("@twurple/auth", () => ({
|
|||||||
describe("probeTwitch", () => {
|
describe("probeTwitch", () => {
|
||||||
const mockAccount: TwitchAccountConfig = {
|
const mockAccount: TwitchAccountConfig = {
|
||||||
username: "testbot",
|
username: "testbot",
|
||||||
token: "oauth:test123456789",
|
accessToken: "oauth:test123456789",
|
||||||
|
clientId: "test-client-id",
|
||||||
channel: "testchannel",
|
channel: "testchannel",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -74,7 +75,7 @@ describe("probeTwitch", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("returns error when token is missing", async () => {
|
it("returns error when token is missing", async () => {
|
||||||
const account = { ...mockAccount, token: "" };
|
const account = { ...mockAccount, accessToken: "" };
|
||||||
const result = await probeTwitch(account, 5000);
|
const result = await probeTwitch(account, 5000);
|
||||||
|
|
||||||
expect(result.ok).toBe(false);
|
expect(result.ok).toBe(false);
|
||||||
@@ -84,7 +85,7 @@ describe("probeTwitch", () => {
|
|||||||
it("attempts connection regardless of token prefix", async () => {
|
it("attempts connection regardless of token prefix", async () => {
|
||||||
// Note: probeTwitch doesn't validate token format - it tries to connect with whatever token is provided
|
// Note: probeTwitch doesn't validate token format - it tries to connect with whatever token is provided
|
||||||
// The actual connection would fail in production with an invalid token
|
// The actual connection would fail in production with an invalid token
|
||||||
const account = { ...mockAccount, token: "raw_token_no_prefix" };
|
const account = { ...mockAccount, accessToken: "raw_token_no_prefix" };
|
||||||
const result = await probeTwitch(account, 5000);
|
const result = await probeTwitch(account, 5000);
|
||||||
|
|
||||||
// With mock, connection succeeds even without oauth: prefix
|
// With mock, connection succeeds even without oauth: prefix
|
||||||
@@ -166,7 +167,7 @@ describe("probeTwitch", () => {
|
|||||||
it("trims token before validation", async () => {
|
it("trims token before validation", async () => {
|
||||||
const account: TwitchAccountConfig = {
|
const account: TwitchAccountConfig = {
|
||||||
...mockAccount,
|
...mockAccount,
|
||||||
token: " oauth:test123456789 ",
|
accessToken: " oauth:test123456789 ",
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await probeTwitch(account, 5000);
|
const result = await probeTwitch(account, 5000);
|
||||||
|
|||||||
Reference in New Issue
Block a user