mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 17:40:44 +00:00
test: reuse chat-not-found assertion helper
This commit is contained in:
@@ -20,6 +20,26 @@ const {
|
|||||||
sendStickerTelegram,
|
sendStickerTelegram,
|
||||||
} = await importTelegramSendModule();
|
} = await importTelegramSendModule();
|
||||||
|
|
||||||
|
async function expectChatNotFoundWithChatId(
|
||||||
|
action: Promise<unknown>,
|
||||||
|
expectedChatId: string,
|
||||||
|
): Promise<void> {
|
||||||
|
try {
|
||||||
|
await action;
|
||||||
|
throw new Error("Expected action to reject with chat-not-found context");
|
||||||
|
} catch (error) {
|
||||||
|
if (
|
||||||
|
error instanceof Error &&
|
||||||
|
error.message === "Expected action to reject with chat-not-found context"
|
||||||
|
) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
|
expect(message).toMatch(/chat not found/i);
|
||||||
|
expect(message).toMatch(new RegExp(`chat_id=${expectedChatId}`));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
describe("sent-message-cache", () => {
|
describe("sent-message-cache", () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
clearSentMessageCache();
|
clearSentMessageCache();
|
||||||
@@ -285,11 +305,9 @@ describe("sendMessageTelegram", () => {
|
|||||||
sendMessage: typeof sendMessage;
|
sendMessage: typeof sendMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
await expect(sendMessageTelegram(chatId, "hi", { token: "tok", api })).rejects.toThrow(
|
await expectChatNotFoundWithChatId(
|
||||||
/chat not found/i,
|
sendMessageTelegram(chatId, "hi", { token: "tok", api }),
|
||||||
);
|
chatId,
|
||||||
await expect(sendMessageTelegram(chatId, "hi", { token: "tok", api })).rejects.toThrow(
|
|
||||||
/chat_id=123/,
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1236,11 +1254,9 @@ describe("sendStickerTelegram", () => {
|
|||||||
sendSticker: typeof sendSticker;
|
sendSticker: typeof sendSticker;
|
||||||
};
|
};
|
||||||
|
|
||||||
await expect(sendStickerTelegram(chatId, "fileId123", { token: "tok", api })).rejects.toThrow(
|
await expectChatNotFoundWithChatId(
|
||||||
/chat not found/i,
|
sendStickerTelegram(chatId, "fileId123", { token: "tok", api }),
|
||||||
);
|
chatId,
|
||||||
await expect(sendStickerTelegram(chatId, "fileId123", { token: "tok", api })).rejects.toThrow(
|
|
||||||
/chat_id=123/,
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user