From e8addf2ac22f97a275aa48b66be04e6d98310da7 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Mar 2026 21:23:10 +0000 Subject: [PATCH] test: add message action spec coverage --- .../outbound/message-action-spec.test.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/infra/outbound/message-action-spec.test.ts diff --git a/src/infra/outbound/message-action-spec.test.ts b/src/infra/outbound/message-action-spec.test.ts new file mode 100644 index 00000000000..138f61e08a0 --- /dev/null +++ b/src/infra/outbound/message-action-spec.test.ts @@ -0,0 +1,39 @@ +import { describe, expect, it } from "vitest"; +import { actionHasTarget, actionRequiresTarget } from "./message-action-spec.js"; + +describe("actionRequiresTarget", () => { + it.each([ + ["send", true], + ["channel-info", true], + ["broadcast", false], + ["search", false], + ])("returns %s for %s", (action, expected) => { + expect(actionRequiresTarget(action as never)).toBe(expected); + }); +}); + +describe("actionHasTarget", () => { + it("detects canonical target fields", () => { + expect(actionHasTarget("send", { to: " channel:C1 " })).toBe(true); + expect(actionHasTarget("channel-info", { channelId: " C123 " })).toBe(true); + expect(actionHasTarget("send", { to: " ", channelId: "" })).toBe(false); + }); + + it("detects alias targets for message and chat actions", () => { + expect(actionHasTarget("edit", { messageId: " msg_123 " })).toBe(true); + expect(actionHasTarget("react", { chatGuid: "chat-guid" })).toBe(true); + expect(actionHasTarget("react", { chatIdentifier: "chat-id" })).toBe(true); + expect(actionHasTarget("react", { chatId: 42 })).toBe(true); + }); + + it("rejects blank and non-finite alias targets", () => { + expect(actionHasTarget("edit", { messageId: " " })).toBe(false); + expect(actionHasTarget("react", { chatGuid: "" })).toBe(false); + expect(actionHasTarget("react", { chatId: Number.NaN })).toBe(false); + expect(actionHasTarget("react", { chatId: Number.POSITIVE_INFINITY })).toBe(false); + }); + + it("ignores alias fields for actions without alias target support", () => { + expect(actionHasTarget("send", { messageId: "msg_123", chatId: 42 })).toBe(false); + }); +});