mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 17:10:49 +00:00
test: share twitch account fixture
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it, vi, beforeEach } from "vitest";
|
||||
import { twitchMessageActions } from "./actions.js";
|
||||
import type { ResolvedTwitchAccountContext } from "./config.js";
|
||||
import { resolveTwitchAccountContext } from "./config.js";
|
||||
import { twitchOutbound } from "./outbound.js";
|
||||
|
||||
@@ -14,6 +15,22 @@ vi.mock("./outbound.js", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
function createSecondaryAccountContext(accountId = "secondary"): ResolvedTwitchAccountContext {
|
||||
return {
|
||||
accountId,
|
||||
account: {
|
||||
channel: "secondary-channel",
|
||||
username: "secondary",
|
||||
accessToken: "oauth:secondary-token",
|
||||
clientId: "secondary-client",
|
||||
enabled: true,
|
||||
},
|
||||
tokenResolution: { source: "config", token: "oauth:secondary-token" },
|
||||
configured: true,
|
||||
availableAccountIds: ["default", "secondary"],
|
||||
};
|
||||
}
|
||||
|
||||
describe("twitchMessageActions", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
@@ -21,32 +38,10 @@ describe("twitchMessageActions", () => {
|
||||
|
||||
it("uses configured defaultAccount when action accountId is omitted", async () => {
|
||||
vi.mocked(resolveTwitchAccountContext)
|
||||
.mockImplementationOnce(() => ({
|
||||
accountId: "secondary",
|
||||
account: {
|
||||
channel: "secondary-channel",
|
||||
username: "secondary",
|
||||
accessToken: "oauth:secondary-token",
|
||||
clientId: "secondary-client",
|
||||
enabled: true,
|
||||
},
|
||||
tokenResolution: { source: "config", token: "oauth:secondary-token" },
|
||||
configured: true,
|
||||
availableAccountIds: ["default", "secondary"],
|
||||
}))
|
||||
.mockImplementation((_cfg, accountId) => ({
|
||||
accountId: accountId?.trim() || "secondary",
|
||||
account: {
|
||||
channel: "secondary-channel",
|
||||
username: "secondary",
|
||||
accessToken: "oauth:secondary-token",
|
||||
clientId: "secondary-client",
|
||||
enabled: true,
|
||||
},
|
||||
tokenResolution: { source: "config", token: "oauth:secondary-token" },
|
||||
configured: true,
|
||||
availableAccountIds: ["default", "secondary"],
|
||||
}));
|
||||
.mockImplementationOnce(() => createSecondaryAccountContext())
|
||||
.mockImplementation((_cfg, accountId) =>
|
||||
createSecondaryAccountContext(accountId?.trim() || "secondary"),
|
||||
);
|
||||
const sendText = twitchOutbound.sendText;
|
||||
if (!sendText) {
|
||||
throw new Error("twitchOutbound.sendText is unavailable");
|
||||
|
||||
Reference in New Issue
Block a user