feat(discord): Discord transport
This commit is contained in:
committed by
Peter Steinberger
parent
557f8e5a04
commit
ac659ff5a7
@@ -11,13 +11,16 @@ vi.mock("../gateway/call.js", () => ({
|
||||
}));
|
||||
|
||||
const originalTelegramToken = process.env.TELEGRAM_BOT_TOKEN;
|
||||
const originalDiscordToken = process.env.DISCORD_BOT_TOKEN;
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.TELEGRAM_BOT_TOKEN = "token-abc";
|
||||
process.env.DISCORD_BOT_TOKEN = "token-discord";
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
process.env.TELEGRAM_BOT_TOKEN = originalTelegramToken;
|
||||
process.env.DISCORD_BOT_TOKEN = originalDiscordToken;
|
||||
});
|
||||
|
||||
const runtime: RuntimeEnv = {
|
||||
@@ -31,6 +34,7 @@ const runtime: RuntimeEnv = {
|
||||
const makeDeps = (overrides: Partial<CliDeps> = {}): CliDeps => ({
|
||||
sendMessageWhatsApp: vi.fn(),
|
||||
sendMessageTelegram: vi.fn(),
|
||||
sendMessageDiscord: vi.fn(),
|
||||
...overrides,
|
||||
});
|
||||
|
||||
@@ -83,6 +87,25 @@ describe("sendCommand", () => {
|
||||
expect(deps.sendMessageWhatsApp).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("routes to discord provider", async () => {
|
||||
const deps = makeDeps({
|
||||
sendMessageDiscord: vi
|
||||
.fn()
|
||||
.mockResolvedValue({ messageId: "d1", channelId: "chan" }),
|
||||
});
|
||||
await sendCommand(
|
||||
{ to: "channel:chan", message: "hi", provider: "discord" },
|
||||
deps,
|
||||
runtime,
|
||||
);
|
||||
expect(deps.sendMessageDiscord).toHaveBeenCalledWith(
|
||||
"channel:chan",
|
||||
"hi",
|
||||
expect.objectContaining({ token: "token-discord" }),
|
||||
);
|
||||
expect(deps.sendMessageWhatsApp).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("emits json output", async () => {
|
||||
callGatewayMock.mockResolvedValueOnce({ messageId: "direct2" });
|
||||
const deps = makeDeps();
|
||||
|
||||
Reference in New Issue
Block a user