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" ;
vi.mock("./config.js" , () => ({
DEFAULT_ACCOUNT_ID: "default" ,
resolveTwitchAccountContext: vi.fn(),
}));
vi.mock("./outbound.js" , () => ({
twitchOutbound: {
sendText: vi.fn(),
},
}));
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();
});
it("uses configured defaultAccount when action accountId is omitted" , async () => {
vi.mocked(resolveTwitchAccountContext)
.mockImplementationOnce(() => createSecondaryAccountContext())
.mockImplementation((_cfg, accountId) =>
createSecondaryAccountContext(accountId?.trim() || "secondary" ),
);
const sendText = twitchOutbound.sendText;
if (!sendText) {
throw new Error("twitchOutbound.sendText is unavailable" );
}
vi.mocked(sendText).mockResolvedValue({
channel: "twitch" ,
messageId: "msg-1" ,
timestamp: 1 ,
});
await twitchMessageActions.handleAction!({
action: "send" ,
params: { message: "Hello!" },
cfg: {
channels: {
twitch: {
defaultAccount: "secondary" ,
},
},
},
} as never);
expect(twitchOutbound.sendText).toHaveBeenCalledWith(
expect.objectContaining({
accountId: "secondary" ,
to: "secondary-channel" ,
}),
);
});
});
Messung V0.5 in Prozent C=99 H=99 G=98
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-05-26)
¤
*© Formatika GbR, Deutschland