|
| 1 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 2 | + |
| 3 | +import { sendMessage, sendPoll } from "./message.js"; |
| 4 | + |
| 5 | +const callGatewayMock = vi.fn(); |
| 6 | +vi.mock("../../gateway/call.js", () => ({ |
| 7 | + callGateway: (...args: unknown[]) => callGatewayMock(...args), |
| 8 | + randomIdempotencyKey: () => "idem-1", |
| 9 | +})); |
| 10 | + |
| 11 | +describe("sendMessage provider normalization", () => { |
| 12 | + beforeEach(() => { |
| 13 | + callGatewayMock.mockReset(); |
| 14 | + }); |
| 15 | + |
| 16 | + it("normalizes Teams alias", async () => { |
| 17 | + const sendMSTeams = vi.fn(async () => ({ |
| 18 | + messageId: "m1", |
| 19 | + conversationId: "c1", |
| 20 | + })); |
| 21 | + const result = await sendMessage({ |
| 22 | + cfg: {}, |
| 23 | + to: "conversation:19:[email protected]", |
| 24 | + content: "hi", |
| 25 | + provider: "teams", |
| 26 | + deps: { sendMSTeams }, |
| 27 | + }); |
| 28 | + |
| 29 | + expect(sendMSTeams).toHaveBeenCalledWith( |
| 30 | + "conversation:19:[email protected]", |
| 31 | + "hi", |
| 32 | + ); |
| 33 | + expect(result.provider).toBe("msteams"); |
| 34 | + }); |
| 35 | + |
| 36 | + it("normalizes iMessage alias", async () => { |
| 37 | + const sendIMessage = vi.fn(async () => ({ messageId: "i1" })); |
| 38 | + const result = await sendMessage({ |
| 39 | + cfg: {}, |
| 40 | + |
| 41 | + content: "hi", |
| 42 | + provider: "imsg", |
| 43 | + deps: { sendIMessage }, |
| 44 | + }); |
| 45 | + |
| 46 | + expect(sendIMessage).toHaveBeenCalledWith( |
| 47 | + |
| 48 | + "hi", |
| 49 | + expect.any(Object), |
| 50 | + ); |
| 51 | + expect(result.provider).toBe("imessage"); |
| 52 | + }); |
| 53 | +}); |
| 54 | + |
| 55 | +describe("sendPoll provider normalization", () => { |
| 56 | + beforeEach(() => { |
| 57 | + callGatewayMock.mockReset(); |
| 58 | + }); |
| 59 | + |
| 60 | + it("normalizes Teams alias for polls", async () => { |
| 61 | + callGatewayMock.mockResolvedValueOnce({ messageId: "p1" }); |
| 62 | + |
| 63 | + const result = await sendPoll({ |
| 64 | + cfg: {}, |
| 65 | + to: "conversation:19:[email protected]", |
| 66 | + question: "Lunch?", |
| 67 | + options: ["Pizza", "Sushi"], |
| 68 | + provider: "Teams", |
| 69 | + }); |
| 70 | + |
| 71 | + const call = callGatewayMock.mock.calls[0]?.[0] as { |
| 72 | + params?: Record<string, unknown>; |
| 73 | + }; |
| 74 | + expect(call?.params?.provider).toBe("msteams"); |
| 75 | + expect(result.provider).toBe("msteams"); |
| 76 | + }); |
| 77 | +}); |
0 commit comments