mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 15:20:44 +00:00
test(telegram): reset forum metadata cache
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
resetNativeCommandMenuMocks,
|
||||
waitForRegisteredCommands,
|
||||
} from "./bot-native-commands.menu-test-support.js";
|
||||
import { resetTelegramForumFlagCacheForTest } from "./bot/helpers.js";
|
||||
import { TELEGRAM_COMMAND_NAME_PATTERN } from "./command-config.js";
|
||||
import { pluginCommandMocks, resetPluginCommandMocks } from "./test-support/plugin-command.js";
|
||||
|
||||
@@ -101,6 +102,7 @@ describe("registerTelegramNativeCommands", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetTelegramForumFlagCacheForTest();
|
||||
resetNativeCommandMenuMocks();
|
||||
resetPluginCommandMocks();
|
||||
});
|
||||
|
||||
@@ -46,6 +46,7 @@ const {
|
||||
getTelegramSequentialKey,
|
||||
setTelegramBotRuntimeForTest,
|
||||
} = await import("./bot.js");
|
||||
const { resetTelegramForumFlagCacheForTest } = await import("./bot/helpers.js");
|
||||
let createTelegramBot: (
|
||||
opts: Parameters<typeof import("./bot.js").createTelegramBot>[0],
|
||||
) => ReturnType<typeof import("./bot.js").createTelegramBot>;
|
||||
@@ -131,6 +132,7 @@ describe("createTelegramBot", () => {
|
||||
process.env.TZ = ORIGINAL_TZ;
|
||||
});
|
||||
beforeEach(() => {
|
||||
resetTelegramForumFlagCacheForTest();
|
||||
setTelegramBotRuntimeForTest(
|
||||
telegramBotRuntimeForTest as unknown as Parameters<typeof setTelegramBotRuntimeForTest>[0],
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
buildTelegramRoutingTarget,
|
||||
buildTelegramThreadParams,
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
resolveTelegramDirectPeerId,
|
||||
resolveTelegramForumFlag,
|
||||
resolveTelegramForumThreadId,
|
||||
resetTelegramForumFlagCacheForTest,
|
||||
} from "./helpers.js";
|
||||
|
||||
describe("resolveTelegramForumThreadId", () => {
|
||||
@@ -34,6 +35,10 @@ describe("resolveTelegramForumThreadId", () => {
|
||||
});
|
||||
|
||||
describe("resolveTelegramForumFlag", () => {
|
||||
beforeEach(() => {
|
||||
resetTelegramForumFlagCacheForTest();
|
||||
});
|
||||
|
||||
it("keeps explicit forum metadata when Telegram already provides it", async () => {
|
||||
const getChat = vi.fn(async () => ({ is_forum: false }));
|
||||
await expect(
|
||||
|
||||
@@ -44,6 +44,10 @@ const TELEGRAM_FORUM_FLAG_CACHE_MAX_CHATS = 1024;
|
||||
const TELEGRAM_FORUM_FLAG_CACHE_TTL_MS = 10 * 60_000;
|
||||
const telegramForumFlagByChatId = new Map<string, { expiresAtMs: number; isForum: boolean }>();
|
||||
|
||||
export function resetTelegramForumFlagCacheForTest(): void {
|
||||
telegramForumFlagByChatId.clear();
|
||||
}
|
||||
|
||||
function cacheTelegramForumFlag(chatId: string | number, isForum: boolean, nowMs = Date.now()) {
|
||||
const cacheKey = String(chatId);
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user