refactor: extract MEDIA parsing helper and tidy whitespace

This commit is contained in:
Peter Steinberger
2025-11-25 05:49:18 +01:00
parent bafaed37fe
commit 072998a6ab
3 changed files with 70 additions and 42 deletions

View File

@@ -17,6 +17,7 @@ type TwilioFactoryMock = ReturnType<typeof createMockTwilio>["factory"];
const twilioFactory = (await import("twilio")).default as TwilioFactoryMock;
import * as index from "./index.js";
import { splitMediaFromOutput } from "./media/parse.js";
const envBackup = { ...process.env } as Record<string, string | undefined>;
@@ -223,6 +224,14 @@ describe("config and templating", () => {
expect(result?.mediaUrl).toBeUndefined();
});
it("splitMediaFromOutput strips media token and preserves text", () => {
const { text, mediaUrl } = splitMediaFromOutput(
"line1\nMEDIA:https://x/y.png\nline2",
);
expect(mediaUrl).toBe("https://x/y.png");
expect(text).toBe("line1\nline2");
});
it("getReplyFromConfig runs command and manages session store", async () => {
const tmpStore = path.join(os.tmpdir(), `warelay-store-${Date.now()}.json`);
vi.spyOn(crypto, "randomUUID").mockReturnValue("session-123");