Tests: cover shared Telegram sent message cache

This commit is contained in:
Vincent Koc
2026-03-12 01:27:11 -04:00
parent 07e7e8424b
commit 21a024e4f8

View File

@@ -1,5 +1,6 @@
import type { Bot } from "grammy";
import { afterEach, describe, expect, it, vi } from "vitest";
import { importFreshModule } from "../../test/helpers/import-fresh.js";
import {
getTelegramSendTestMocks,
importTelegramSendModule,
@@ -88,6 +89,29 @@ describe("sent-message-cache", () => {
clearSentMessageCache();
expect(wasSentByBot(123, 1)).toBe(false);
});
it("shares sent-message state across distinct module instances", async () => {
const cacheA = await importFreshModule<typeof import("./sent-message-cache.js")>(
import.meta.url,
"./sent-message-cache.js?scope=shared-a",
);
const cacheB = await importFreshModule<typeof import("./sent-message-cache.js")>(
import.meta.url,
"./sent-message-cache.js?scope=shared-b",
);
cacheA.clearSentMessageCache();
try {
cacheA.recordSentMessage(123, 1);
expect(cacheB.wasSentByBot(123, 1)).toBe(true);
cacheB.clearSentMessageCache();
expect(cacheA.wasSentByBot(123, 1)).toBe(false);
} finally {
cacheA.clearSentMessageCache();
}
});
});
describe("buildInlineKeyboard", () => {