Tests: align routing and iMessage helpers

This commit is contained in:
Peter Steinberger
2026-04-07 06:23:49 +08:00
parent a463a33eee
commit ca8570be02
2 changed files with 22 additions and 5 deletions

View File

@@ -1,5 +1,4 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { compileSlackInteractiveReplies } from "../../../extensions/slack/src/interactive-replies.ts";
import type {
ChannelMessagingAdapter,
ChannelPlugin,
@@ -29,11 +28,30 @@ vi.mock("../../infra/outbound/deliver-runtime.js", async () => {
const { routeReply } = await import("./route-reply.js");
function compileSlackInteractiveRepliesForTest(
payload: Parameters<NonNullable<ChannelMessagingAdapter["transformReplyPayload"]>>[0]["payload"],
) {
const text = payload.text ?? "";
if (!text.includes("[[slack_select:") && !text.includes("[[slack_buttons:")) {
return payload;
}
return {
...payload,
channelData: {
...payload.channelData,
slack: {
...(payload.channelData?.slack as Record<string, unknown> | undefined),
blocks: [{ type: "section", text }],
},
},
};
}
const slackMessaging: ChannelMessagingAdapter = {
transformReplyPayload: ({ payload, cfg }) =>
(cfg.channels?.slack as { capabilities?: { interactiveReplies?: boolean } } | undefined)
?.capabilities?.interactiveReplies === true
? compileSlackInteractiveReplies(payload)
? compileSlackInteractiveRepliesForTest(payload)
: payload,
enableInteractiveReplies: ({ cfg }) =>
(cfg.channels?.slack as { capabilities?: { interactiveReplies?: boolean } } | undefined)
@@ -422,7 +440,7 @@ describe("routeReply", () => {
expectLastDelivery({
channel: "mattermost",
to: "channel:CHAN1",
replyToId: null,
replyToId: "post-root",
threadId: "post-root",
});
});

View File

@@ -250,10 +250,9 @@ function resolveIMessageMaxBytes(
export const imessageOutboundForTest: ChannelOutboundAdapter = {
deliveryMode: "direct",
sanitizeText: ({ text }) => text,
sendText: async ({ cfg, to, text, accountId, deps }) =>
sendText: async ({ to, text, accountId, deps }) =>
withIMessageChannel(
await resolveIMessageSender(deps)(to, text, {
maxBytes: resolveIMessageMaxBytes(cfg, accountId),
accountId: accountId ?? undefined,
}),
),