mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-21 21:56:46 +00:00
test: tighten feishu send parsing assertions
This commit is contained in:
@@ -168,14 +168,18 @@ describe("getMessageFeishu", () => {
|
||||
messageId: "om_1",
|
||||
});
|
||||
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
messageId: "om_1",
|
||||
chatId: "oc_1",
|
||||
contentType: "interactive",
|
||||
content: "hello markdown\nhello div",
|
||||
}),
|
||||
);
|
||||
expect(result).toEqual({
|
||||
messageId: "om_1",
|
||||
chatId: "oc_1",
|
||||
chatType: undefined,
|
||||
senderId: undefined,
|
||||
senderOpenId: undefined,
|
||||
senderType: undefined,
|
||||
content: "hello markdown\nhello div",
|
||||
contentType: "interactive",
|
||||
createTime: undefined,
|
||||
threadId: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("falls through empty interactive card element arrays and locale variants", async () => {
|
||||
@@ -217,14 +221,18 @@ describe("getMessageFeishu", () => {
|
||||
messageId: "om_i18n_card",
|
||||
});
|
||||
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
messageId: "om_i18n_card",
|
||||
chatId: "oc_i18n_card",
|
||||
contentType: "interactive",
|
||||
content: "hello 2 tasks {{metadata}}",
|
||||
}),
|
||||
);
|
||||
expect(result).toEqual({
|
||||
messageId: "om_i18n_card",
|
||||
chatId: "oc_i18n_card",
|
||||
chatType: undefined,
|
||||
senderId: undefined,
|
||||
senderOpenId: undefined,
|
||||
senderType: undefined,
|
||||
content: "hello 2 tasks {{metadata}}",
|
||||
contentType: "interactive",
|
||||
createTime: undefined,
|
||||
threadId: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to post-format content when interactive card elements are empty", async () => {
|
||||
@@ -257,14 +265,18 @@ describe("getMessageFeishu", () => {
|
||||
messageId: "om_post_card",
|
||||
});
|
||||
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
messageId: "om_post_card",
|
||||
chatId: "oc_post_card",
|
||||
contentType: "interactive",
|
||||
content: "Card summary\n\n**fallback** body",
|
||||
}),
|
||||
);
|
||||
expect(result).toEqual({
|
||||
messageId: "om_post_card",
|
||||
chatId: "oc_post_card",
|
||||
chatType: undefined,
|
||||
senderId: undefined,
|
||||
senderOpenId: undefined,
|
||||
senderType: undefined,
|
||||
content: "Card summary\n\n**fallback** body",
|
||||
contentType: "interactive",
|
||||
createTime: undefined,
|
||||
threadId: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("extracts text content from post messages", async () => {
|
||||
@@ -294,14 +306,18 @@ describe("getMessageFeishu", () => {
|
||||
messageId: "om_post",
|
||||
});
|
||||
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
messageId: "om_post",
|
||||
chatId: "oc_post",
|
||||
contentType: "post",
|
||||
content: "Summary\n\npost body",
|
||||
}),
|
||||
);
|
||||
expect(result).toEqual({
|
||||
messageId: "om_post",
|
||||
chatId: "oc_post",
|
||||
chatType: undefined,
|
||||
senderId: undefined,
|
||||
senderOpenId: undefined,
|
||||
senderType: undefined,
|
||||
content: "Summary\n\npost body",
|
||||
contentType: "post",
|
||||
createTime: undefined,
|
||||
threadId: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("returns text placeholder instead of raw JSON for unsupported message types", async () => {
|
||||
@@ -326,14 +342,18 @@ describe("getMessageFeishu", () => {
|
||||
messageId: "om_file",
|
||||
});
|
||||
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
messageId: "om_file",
|
||||
chatId: "oc_file",
|
||||
contentType: "file",
|
||||
content: "[file message]",
|
||||
}),
|
||||
);
|
||||
expect(result).toEqual({
|
||||
messageId: "om_file",
|
||||
chatId: "oc_file",
|
||||
chatType: undefined,
|
||||
senderId: undefined,
|
||||
senderOpenId: undefined,
|
||||
senderType: undefined,
|
||||
content: "[file message]",
|
||||
contentType: "file",
|
||||
createTime: undefined,
|
||||
threadId: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("supports single-object response shape from Feishu API", async () => {
|
||||
@@ -354,14 +374,18 @@ describe("getMessageFeishu", () => {
|
||||
messageId: "om_single",
|
||||
});
|
||||
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
messageId: "om_single",
|
||||
chatId: "oc_single",
|
||||
contentType: "text",
|
||||
content: "single payload",
|
||||
}),
|
||||
);
|
||||
expect(result).toEqual({
|
||||
messageId: "om_single",
|
||||
chatId: "oc_single",
|
||||
chatType: undefined,
|
||||
senderId: undefined,
|
||||
senderOpenId: undefined,
|
||||
senderType: undefined,
|
||||
content: "single payload",
|
||||
contentType: "text",
|
||||
createTime: undefined,
|
||||
threadId: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("reuses the same content parsing for thread history messages", async () => {
|
||||
@@ -415,16 +439,22 @@ describe("getMessageFeishu", () => {
|
||||
});
|
||||
|
||||
expect(result).toEqual([
|
||||
expect.objectContaining({
|
||||
{
|
||||
messageId: "om_file",
|
||||
senderId: "ou_1",
|
||||
senderType: "user",
|
||||
contentType: "file",
|
||||
content: "[file message]",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
createTime: 1710000001000,
|
||||
},
|
||||
{
|
||||
messageId: "om_card",
|
||||
senderId: "app_1",
|
||||
senderType: "app",
|
||||
contentType: "interactive",
|
||||
content: "hello from card 2.0",
|
||||
}),
|
||||
createTime: 1710000000000,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -547,13 +577,14 @@ describe("buildStructuredCard", () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(card).toEqual(
|
||||
expect.objectContaining({
|
||||
header: {
|
||||
title: { tag: "plain_text", content: "Agent" },
|
||||
template: "blue",
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(card).toEqual({
|
||||
schema: "2.0",
|
||||
config: { width_mode: "fill" },
|
||||
body: { elements: [{ tag: "markdown", content: "hello" }] },
|
||||
header: {
|
||||
title: { tag: "plain_text", content: "Agent" },
|
||||
template: "blue",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user