Spaces:
Running
Running
File size: 2,766 Bytes
fb4d8fe | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | import { describe, expect, it } from "vitest";
import {
buildOutboundDeliveryJson,
formatGatewaySummary,
formatOutboundDeliverySummary,
} from "./format.js";
describe("formatOutboundDeliverySummary", () => {
it("falls back when result is missing", () => {
expect(formatOutboundDeliverySummary("telegram")).toBe(
"✅ Sent via Telegram. Message ID: unknown",
);
expect(formatOutboundDeliverySummary("imessage")).toBe(
"✅ Sent via iMessage. Message ID: unknown",
);
});
it("adds chat or channel details", () => {
expect(
formatOutboundDeliverySummary("telegram", {
channel: "telegram",
messageId: "m1",
chatId: "c1",
}),
).toBe("✅ Sent via Telegram. Message ID: m1 (chat c1)");
expect(
formatOutboundDeliverySummary("discord", {
channel: "discord",
messageId: "d1",
channelId: "chan",
}),
).toBe("✅ Sent via Discord. Message ID: d1 (channel chan)");
});
});
describe("buildOutboundDeliveryJson", () => {
it("builds direct delivery payloads", () => {
expect(
buildOutboundDeliveryJson({
channel: "telegram",
to: "123",
result: { channel: "telegram", messageId: "m1", chatId: "c1" },
mediaUrl: "https://example.com/a.png",
}),
).toEqual({
channel: "telegram",
via: "direct",
to: "123",
messageId: "m1",
mediaUrl: "https://example.com/a.png",
chatId: "c1",
});
});
it("supports whatsapp metadata when present", () => {
expect(
buildOutboundDeliveryJson({
channel: "whatsapp",
to: "+1",
result: { channel: "whatsapp", messageId: "w1", toJid: "jid" },
}),
).toEqual({
channel: "whatsapp",
via: "direct",
to: "+1",
messageId: "w1",
mediaUrl: null,
toJid: "jid",
});
});
it("keeps timestamp for signal", () => {
expect(
buildOutboundDeliveryJson({
channel: "signal",
to: "+1",
result: { channel: "signal", messageId: "s1", timestamp: 123 },
}),
).toEqual({
channel: "signal",
via: "direct",
to: "+1",
messageId: "s1",
mediaUrl: null,
timestamp: 123,
});
});
});
describe("formatGatewaySummary", () => {
it("formats gateway summaries with channel", () => {
expect(formatGatewaySummary({ channel: "whatsapp", messageId: "m1" })).toBe(
"✅ Sent via gateway (whatsapp). Message ID: m1",
);
});
it("supports custom actions", () => {
expect(
formatGatewaySummary({
action: "Poll sent",
channel: "discord",
messageId: "p1",
}),
).toBe("✅ Poll sent via gateway (discord). Message ID: p1");
});
});
|