test: share twitch account fixture

This commit is contained in:
Peter Steinberger
2026-04-20 17:09:09 +01:00
parent 68fbe9fab1
commit 3ae3a5e77d

View File

@@ -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");