mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 10:27:28 +00:00
perf(test): fold telegram sent-message cache tests into send suite
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import type { Bot } from "grammy";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
getTelegramSendTestMocks,
|
||||
importTelegramSendModule,
|
||||
installTelegramSendTestHooks,
|
||||
} from "./send.test-harness.js";
|
||||
import { clearSentMessageCache, recordSentMessage, wasSentByBot } from "./sent-message-cache.js";
|
||||
|
||||
installTelegramSendTestHooks();
|
||||
|
||||
@@ -18,6 +19,38 @@ const {
|
||||
sendStickerTelegram,
|
||||
} = await importTelegramSendModule();
|
||||
|
||||
describe("sent-message-cache", () => {
|
||||
afterEach(() => {
|
||||
clearSentMessageCache();
|
||||
});
|
||||
|
||||
it("records and retrieves sent messages", () => {
|
||||
recordSentMessage(123, 1);
|
||||
recordSentMessage(123, 2);
|
||||
recordSentMessage(456, 10);
|
||||
|
||||
expect(wasSentByBot(123, 1)).toBe(true);
|
||||
expect(wasSentByBot(123, 2)).toBe(true);
|
||||
expect(wasSentByBot(456, 10)).toBe(true);
|
||||
expect(wasSentByBot(123, 3)).toBe(false);
|
||||
expect(wasSentByBot(789, 1)).toBe(false);
|
||||
});
|
||||
|
||||
it("handles string chat IDs", () => {
|
||||
recordSentMessage("123", 1);
|
||||
expect(wasSentByBot("123", 1)).toBe(true);
|
||||
expect(wasSentByBot(123, 1)).toBe(true);
|
||||
});
|
||||
|
||||
it("clears cache", () => {
|
||||
recordSentMessage(123, 1);
|
||||
expect(wasSentByBot(123, 1)).toBe(true);
|
||||
|
||||
clearSentMessageCache();
|
||||
expect(wasSentByBot(123, 1)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildInlineKeyboard", () => {
|
||||
it("returns undefined for empty input", () => {
|
||||
expect(buildInlineKeyboard()).toBeUndefined();
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { clearSentMessageCache, recordSentMessage, wasSentByBot } from "./sent-message-cache.js";
|
||||
|
||||
describe("sent-message-cache", () => {
|
||||
afterEach(() => {
|
||||
clearSentMessageCache();
|
||||
});
|
||||
|
||||
it("records and retrieves sent messages", () => {
|
||||
recordSentMessage(123, 1);
|
||||
recordSentMessage(123, 2);
|
||||
recordSentMessage(456, 10);
|
||||
|
||||
expect(wasSentByBot(123, 1)).toBe(true);
|
||||
expect(wasSentByBot(123, 2)).toBe(true);
|
||||
expect(wasSentByBot(456, 10)).toBe(true);
|
||||
expect(wasSentByBot(123, 3)).toBe(false);
|
||||
expect(wasSentByBot(789, 1)).toBe(false);
|
||||
});
|
||||
|
||||
it("handles string chat IDs", () => {
|
||||
recordSentMessage("123", 1);
|
||||
expect(wasSentByBot("123", 1)).toBe(true);
|
||||
expect(wasSentByBot(123, 1)).toBe(true);
|
||||
});
|
||||
|
||||
it("clears cache", () => {
|
||||
recordSentMessage(123, 1);
|
||||
expect(wasSentByBot(123, 1)).toBe(true);
|
||||
|
||||
clearSentMessageCache();
|
||||
expect(wasSentByBot(123, 1)).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user