test(telegram): reset forum metadata cache

This commit is contained in:
Peter Steinberger
2026-04-23 10:11:12 +01:00
parent e880eab486
commit 0a7668595c
4 changed files with 14 additions and 1 deletions

View File

@@ -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();
});

View File

@@ -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],
);

View File

@@ -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(

View File

@@ -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 (