perf(test): fold telegram sent-message cache tests into send suite

This commit is contained in:
Peter Steinberger
2026-02-16 00:39:59 +00:00
parent e770728cb5
commit 65b5dbd6c1
2 changed files with 34 additions and 35 deletions

View File

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

View File

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