mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 15:34:31 +00:00
refactor(test): dedupe slack inbound contract setup
This commit is contained in:
@@ -75,14 +75,12 @@ describe("slack prepareSlackMessage inbound contract", () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it("produces a finalized MsgContext", async () => {
|
function createThreadSlackCtx(params: { cfg: OpenClawConfig; replies: unknown }) {
|
||||||
const slackCtx = createSlackMonitorContext({
|
return createSlackMonitorContext({
|
||||||
cfg: {
|
cfg: params.cfg,
|
||||||
channels: { slack: { enabled: true } },
|
|
||||||
} as OpenClawConfig,
|
|
||||||
accountId: "default",
|
accountId: "default",
|
||||||
botToken: "token",
|
botToken: "token",
|
||||||
app: { client: {} } as App,
|
app: { client: { conversations: { replies: params.replies } } } as App,
|
||||||
runtime: {} as RuntimeEnv,
|
runtime: {} as RuntimeEnv,
|
||||||
botUserId: "B1",
|
botUserId: "B1",
|
||||||
teamId: "T1",
|
teamId: "T1",
|
||||||
@@ -95,12 +93,12 @@ describe("slack prepareSlackMessage inbound contract", () => {
|
|||||||
allowFrom: [],
|
allowFrom: [],
|
||||||
groupDmEnabled: true,
|
groupDmEnabled: true,
|
||||||
groupDmChannels: [],
|
groupDmChannels: [],
|
||||||
defaultRequireMention: true,
|
defaultRequireMention: false,
|
||||||
groupPolicy: "open",
|
groupPolicy: "open",
|
||||||
useAccessGroups: false,
|
useAccessGroups: false,
|
||||||
reactionMode: "off",
|
reactionMode: "off",
|
||||||
reactionAllowlist: [],
|
reactionAllowlist: [],
|
||||||
replyToMode: "off",
|
replyToMode: "all",
|
||||||
threadHistoryScope: "thread",
|
threadHistoryScope: "thread",
|
||||||
threadInheritParent: false,
|
threadInheritParent: false,
|
||||||
slashCommand: {
|
slashCommand: {
|
||||||
@@ -114,17 +112,22 @@ describe("slack prepareSlackMessage inbound contract", () => {
|
|||||||
mediaMaxBytes: 1024,
|
mediaMaxBytes: 1024,
|
||||||
removeAckAfterReply: false,
|
removeAckAfterReply: false,
|
||||||
});
|
});
|
||||||
// oxlint-disable-next-line typescript/no-explicit-any
|
}
|
||||||
slackCtx.resolveUserName = async () => ({ name: "Alice" }) as any;
|
|
||||||
|
|
||||||
const account: ResolvedSlackAccount = {
|
function createThreadAccount(): ResolvedSlackAccount {
|
||||||
|
return {
|
||||||
accountId: "default",
|
accountId: "default",
|
||||||
enabled: true,
|
enabled: true,
|
||||||
botTokenSource: "config",
|
botTokenSource: "config",
|
||||||
appTokenSource: "config",
|
appTokenSource: "config",
|
||||||
config: {},
|
config: {
|
||||||
|
replyToMode: "all",
|
||||||
|
thread: { initialHistoryLimit: 20 },
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
it("produces a finalized MsgContext", async () => {
|
||||||
const message: SlackMessageEvent = {
|
const message: SlackMessageEvent = {
|
||||||
channel: "D123",
|
channel: "D123",
|
||||||
channel_type: "im",
|
channel_type: "im",
|
||||||
@@ -133,12 +136,7 @@ describe("slack prepareSlackMessage inbound contract", () => {
|
|||||||
ts: "1.000",
|
ts: "1.000",
|
||||||
} as SlackMessageEvent;
|
} as SlackMessageEvent;
|
||||||
|
|
||||||
const prepared = await prepareSlackMessage({
|
const prepared = await prepareWithDefaultCtx(message);
|
||||||
ctx: slackCtx,
|
|
||||||
account,
|
|
||||||
message,
|
|
||||||
opts: { source: "message" },
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(prepared).toBeTruthy();
|
expect(prepared).toBeTruthy();
|
||||||
// oxlint-disable-next-line typescript/no-explicit-any
|
// oxlint-disable-next-line typescript/no-explicit-any
|
||||||
@@ -320,60 +318,19 @@ describe("slack prepareSlackMessage inbound contract", () => {
|
|||||||
],
|
],
|
||||||
response_metadata: { next_cursor: "" },
|
response_metadata: { next_cursor: "" },
|
||||||
});
|
});
|
||||||
const slackCtx = createSlackMonitorContext({
|
const slackCtx = createThreadSlackCtx({
|
||||||
cfg: {
|
cfg: {
|
||||||
session: { store: storePath },
|
session: { store: storePath },
|
||||||
channels: { slack: { enabled: true, replyToMode: "all", groupPolicy: "open" } },
|
channels: { slack: { enabled: true, replyToMode: "all", groupPolicy: "open" } },
|
||||||
} as OpenClawConfig,
|
} as OpenClawConfig,
|
||||||
accountId: "default",
|
replies,
|
||||||
botToken: "token",
|
|
||||||
app: { client: { conversations: { replies } } } as App,
|
|
||||||
runtime: {} as RuntimeEnv,
|
|
||||||
botUserId: "B1",
|
|
||||||
teamId: "T1",
|
|
||||||
apiAppId: "A1",
|
|
||||||
historyLimit: 0,
|
|
||||||
sessionScope: "per-sender",
|
|
||||||
mainKey: "main",
|
|
||||||
dmEnabled: true,
|
|
||||||
dmPolicy: "open",
|
|
||||||
allowFrom: [],
|
|
||||||
groupDmEnabled: true,
|
|
||||||
groupDmChannels: [],
|
|
||||||
defaultRequireMention: false,
|
|
||||||
groupPolicy: "open",
|
|
||||||
useAccessGroups: false,
|
|
||||||
reactionMode: "off",
|
|
||||||
reactionAllowlist: [],
|
|
||||||
replyToMode: "all",
|
|
||||||
threadHistoryScope: "thread",
|
|
||||||
threadInheritParent: false,
|
|
||||||
slashCommand: {
|
|
||||||
enabled: false,
|
|
||||||
name: "openclaw",
|
|
||||||
sessionPrefix: "slack:slash",
|
|
||||||
ephemeral: true,
|
|
||||||
},
|
|
||||||
textLimit: 4000,
|
|
||||||
ackReactionScope: "group-mentions",
|
|
||||||
mediaMaxBytes: 1024,
|
|
||||||
removeAckAfterReply: false,
|
|
||||||
});
|
});
|
||||||
slackCtx.resolveUserName = async (id: string) => ({
|
slackCtx.resolveUserName = async (id: string) => ({
|
||||||
name: id === "U1" ? "Alice" : "Bob",
|
name: id === "U1" ? "Alice" : "Bob",
|
||||||
});
|
});
|
||||||
slackCtx.resolveChannelName = async () => ({ name: "general", type: "channel" });
|
slackCtx.resolveChannelName = async () => ({ name: "general", type: "channel" });
|
||||||
|
|
||||||
const account: ResolvedSlackAccount = {
|
const account = createThreadAccount();
|
||||||
accountId: "default",
|
|
||||||
enabled: true,
|
|
||||||
botTokenSource: "config",
|
|
||||||
appTokenSource: "config",
|
|
||||||
config: {
|
|
||||||
replyToMode: "all",
|
|
||||||
thread: { initialHistoryLimit: 20 },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const message: SlackMessageEvent = {
|
const message: SlackMessageEvent = {
|
||||||
channel: "C123",
|
channel: "C123",
|
||||||
@@ -429,55 +386,11 @@ describe("slack prepareSlackMessage inbound contract", () => {
|
|||||||
const replies = vi.fn().mockResolvedValue({
|
const replies = vi.fn().mockResolvedValue({
|
||||||
messages: [{ text: "starter", user: "U2", ts: "200.000" }],
|
messages: [{ text: "starter", user: "U2", ts: "200.000" }],
|
||||||
});
|
});
|
||||||
const slackCtx = createSlackMonitorContext({
|
const slackCtx = createThreadSlackCtx({ cfg, replies });
|
||||||
cfg,
|
|
||||||
accountId: "default",
|
|
||||||
botToken: "token",
|
|
||||||
app: { client: { conversations: { replies } } } as App,
|
|
||||||
runtime: {} as RuntimeEnv,
|
|
||||||
botUserId: "B1",
|
|
||||||
teamId: "T1",
|
|
||||||
apiAppId: "A1",
|
|
||||||
historyLimit: 0,
|
|
||||||
sessionScope: "per-sender",
|
|
||||||
mainKey: "main",
|
|
||||||
dmEnabled: true,
|
|
||||||
dmPolicy: "open",
|
|
||||||
allowFrom: [],
|
|
||||||
groupDmEnabled: true,
|
|
||||||
groupDmChannels: [],
|
|
||||||
defaultRequireMention: false,
|
|
||||||
groupPolicy: "open",
|
|
||||||
useAccessGroups: false,
|
|
||||||
reactionMode: "off",
|
|
||||||
reactionAllowlist: [],
|
|
||||||
replyToMode: "all",
|
|
||||||
threadHistoryScope: "thread",
|
|
||||||
threadInheritParent: false,
|
|
||||||
slashCommand: {
|
|
||||||
enabled: false,
|
|
||||||
name: "openclaw",
|
|
||||||
sessionPrefix: "slack:slash",
|
|
||||||
ephemeral: true,
|
|
||||||
},
|
|
||||||
textLimit: 4000,
|
|
||||||
ackReactionScope: "group-mentions",
|
|
||||||
mediaMaxBytes: 1024,
|
|
||||||
removeAckAfterReply: false,
|
|
||||||
});
|
|
||||||
slackCtx.resolveUserName = async () => ({ name: "Alice" });
|
slackCtx.resolveUserName = async () => ({ name: "Alice" });
|
||||||
slackCtx.resolveChannelName = async () => ({ name: "general", type: "channel" });
|
slackCtx.resolveChannelName = async () => ({ name: "general", type: "channel" });
|
||||||
|
|
||||||
const account: ResolvedSlackAccount = {
|
const account = createThreadAccount();
|
||||||
accountId: "default",
|
|
||||||
enabled: true,
|
|
||||||
botTokenSource: "config",
|
|
||||||
appTokenSource: "config",
|
|
||||||
config: {
|
|
||||||
replyToMode: "all",
|
|
||||||
thread: { initialHistoryLimit: 20 },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const message: SlackMessageEvent = {
|
const message: SlackMessageEvent = {
|
||||||
channel: "C123",
|
channel: "C123",
|
||||||
|
|||||||
Reference in New Issue
Block a user