shablony-prodavanam/test/helpers.js
Peppa 27a8c00cf5
Some checks failed
peppa/install install: failure за 0с
ci / checks (pull_request) Failing after 4s
deploy / deploy (pull_request) Successful in 18s
SP-1: лендинг, бот с ручным подтверждением Kaspi, генератор финмодели
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 16:16:49 +05:00

26 lines
1.1 KiB
JavaScript

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