mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 11:41:24 +00:00
refactor(extensions): dedupe connector helper usage
This commit is contained in:
@@ -9,9 +9,13 @@
|
||||
* - Abort signal handling
|
||||
*/
|
||||
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { twitchOutbound } from "./outbound.js";
|
||||
import {
|
||||
BASE_TWITCH_TEST_ACCOUNT,
|
||||
installTwitchTestHooks,
|
||||
makeTwitchTestConfig,
|
||||
} from "./test-fixtures.js";
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock("./config.js", () => ({
|
||||
@@ -35,29 +39,12 @@ vi.mock("./utils/twitch.js", () => ({
|
||||
|
||||
describe("outbound", () => {
|
||||
const mockAccount = {
|
||||
username: "testbot",
|
||||
...BASE_TWITCH_TEST_ACCOUNT,
|
||||
accessToken: "oauth:test123",
|
||||
clientId: "test-client-id",
|
||||
channel: "#testchannel",
|
||||
};
|
||||
|
||||
const mockConfig = {
|
||||
channels: {
|
||||
twitch: {
|
||||
accounts: {
|
||||
default: mockAccount,
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
const mockConfig = makeTwitchTestConfig(mockAccount);
|
||||
installTwitchTestHooks();
|
||||
|
||||
describe("metadata", () => {
|
||||
it("should have direct delivery mode", () => {
|
||||
|
||||
@@ -10,9 +10,13 @@
|
||||
* - Registry integration
|
||||
*/
|
||||
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { sendMessageTwitchInternal } from "./send.js";
|
||||
import {
|
||||
BASE_TWITCH_TEST_ACCOUNT,
|
||||
installTwitchTestHooks,
|
||||
makeTwitchTestConfig,
|
||||
} from "./test-fixtures.js";
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock("./config.js", () => ({
|
||||
@@ -43,29 +47,12 @@ describe("send", () => {
|
||||
};
|
||||
|
||||
const mockAccount = {
|
||||
username: "testbot",
|
||||
...BASE_TWITCH_TEST_ACCOUNT,
|
||||
token: "oauth:test123",
|
||||
clientId: "test-client-id",
|
||||
channel: "#testchannel",
|
||||
};
|
||||
|
||||
const mockConfig = {
|
||||
channels: {
|
||||
twitch: {
|
||||
accounts: {
|
||||
default: mockAccount,
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
const mockConfig = makeTwitchTestConfig(mockAccount);
|
||||
installTwitchTestHooks();
|
||||
|
||||
describe("sendMessageTwitchInternal", () => {
|
||||
it("should send a message successfully", async () => {
|
||||
|
||||
30
extensions/twitch/src/test-fixtures.ts
Normal file
30
extensions/twitch/src/test-fixtures.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
||||
import { afterEach, beforeEach, vi } from "vitest";
|
||||
|
||||
export const BASE_TWITCH_TEST_ACCOUNT = {
|
||||
username: "testbot",
|
||||
clientId: "test-client-id",
|
||||
channel: "#testchannel",
|
||||
};
|
||||
|
||||
export function makeTwitchTestConfig(account: Record<string, unknown>): OpenClawConfig {
|
||||
return {
|
||||
channels: {
|
||||
twitch: {
|
||||
accounts: {
|
||||
default: account,
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
}
|
||||
|
||||
export function installTwitchTestHooks() {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user