From f4c5f2c193a1d7d6b358b1b7f543594330563eb6 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 25 Nov 2025 05:21:59 +0100 Subject: [PATCH] test: cover media url extraction from command stdout --- src/index.core.test.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/index.core.test.ts b/src/index.core.test.ts index 408c748fb..a3507aa8a 100644 --- a/src/index.core.test.ts +++ b/src/index.core.test.ts @@ -116,6 +116,36 @@ describe("config and templating", () => { expect(result?.text).toContain("http://example.com/a.jpg"); }); + it("getReplyFromConfig extracts media URL from command stdout", async () => { + const runSpy = vi.spyOn(index, "runCommandWithTimeout").mockResolvedValue({ + stdout: "hello\nMEDIA: https://example.com/img.jpg\n", + stderr: "", + code: 0, + signal: null, + killed: false, + }); + const cfg = { + inbound: { + reply: { + mode: "command" as const, + command: ["echo", "{{Body}}"], + }, + }, + }; + const result = await index.getReplyFromConfig( + { + Body: "hi", + From: "+1", + To: "+2", + }, + undefined, + cfg, + runSpy, + ); + expect(result?.text).toBe("hello"); + expect(result?.mediaUrl).toBe("https://example.com/img.jpg"); + }); + 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");