refactor: streamline outbound payload handling
This commit is contained in:
50
src/infra/outbound/payloads.test.ts
Normal file
50
src/infra/outbound/payloads.test.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
formatOutboundPayloadLog,
|
||||
normalizeOutboundPayloadsForJson,
|
||||
} from "./payloads.js";
|
||||
|
||||
describe("normalizeOutboundPayloadsForJson", () => {
|
||||
it("normalizes payloads with mediaUrl and mediaUrls", () => {
|
||||
expect(
|
||||
normalizeOutboundPayloadsForJson([
|
||||
{ text: "hi" },
|
||||
{ text: "photo", mediaUrl: "https://x.test/a.jpg" },
|
||||
{ text: "multi", mediaUrls: ["https://x.test/1.png"] },
|
||||
]),
|
||||
).toEqual([
|
||||
{ text: "hi", mediaUrl: null, mediaUrls: undefined },
|
||||
{
|
||||
text: "photo",
|
||||
mediaUrl: "https://x.test/a.jpg",
|
||||
mediaUrls: ["https://x.test/a.jpg"],
|
||||
},
|
||||
{
|
||||
text: "multi",
|
||||
mediaUrl: null,
|
||||
mediaUrls: ["https://x.test/1.png"],
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatOutboundPayloadLog", () => {
|
||||
it("trims trailing text and appends media lines", () => {
|
||||
expect(
|
||||
formatOutboundPayloadLog({
|
||||
text: "hello ",
|
||||
mediaUrls: ["https://x.test/a.png", "https://x.test/b.png"],
|
||||
}),
|
||||
).toBe("hello\nMEDIA:https://x.test/a.png\nMEDIA:https://x.test/b.png");
|
||||
});
|
||||
|
||||
it("logs media-only payloads", () => {
|
||||
expect(
|
||||
formatOutboundPayloadLog({
|
||||
text: "",
|
||||
mediaUrls: ["https://x.test/a.png"],
|
||||
}),
|
||||
).toBe("MEDIA:https://x.test/a.png");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user