import { mkdtemp } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { loadConfig } from "../src/config.js"; export const tmp = () => mkdtemp(join(tmpdir(), "sp-")); export const testConfig = (extra = {}) => ({ ...loadConfig({ BOT_USERNAME: "demo_bot", PRICE_KZT: "9900", OWNER_CHAT_ID: "1", KASPI_DETAILS: "Kaspi +7 700 000 00 00", CONTACT: "@owner" }), ...extra, }); // Мок Telegram: записывает вызовы, повторяет контракт Telegram-клиента. export function mockTelegram({ failDocuments = false } = {}) { const calls = []; return { calls, sent: (chat) => calls.filter((c) => String(c.chat) === String(chat)), sendMessage: async (chat, text, extra) => void calls.push({ type: "message", chat, text, extra }), answerCallbackQuery: async (id, text) => void calls.push({ type: "answer", id, text }), sendDocument: async (chat, path) => { if (failDocuments) throw new Error("Telegram sendDocument: boom"); calls.push({ type: "document", chat, path }); }, }; }