// BRM-180: одни строки состояния бота в боте, на «Бот и отчёты» и на главной; ваш продукт не отправляет // в версию для проверки; кнопки привязки и личного чата; «работает» — только после подтверждённой доставки. import test from "node:test"; import assert from "node:assert/strict"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { createApp } from "../src/server.js"; import { mockTelegramApi } from "../src/telegram.js"; import { WEBHOOK_PATH } from "../src/bot-identity.js"; import { t } from "../src/i18n.js"; const TATIANA = 555; const WORD = "секрет-слово"; const PROD = "https://brendmanager-prod.telecom.quest"; const STAGING = "https://brendmanager-staging.telecom.quest"; const plain = (html) => html.replace(/<[^>]+>/g, ""); async function startApp({ site = PROD, receiver = PROD, chatId = null, webhook } = {}) { const dir = fs.mkdtempSync(path.join(os.tmpdir(), "brm180-")); const telegram = mockTelegramApi({ chatAware: true, chatId, webhook: { url: receiver + WEBHOOK_PATH, allowed_updates: [] }, me: { id: 900, is_bot: true, username: "TanyaBrandManagerBot" } }); const hookUrl = webhook !== undefined ? webhook : site === receiver ? site + WEBHOOK_PATH : null; const srv = createApp({ file: path.join(dir, "plan.json"), telegram, ownerCode: WORD, webhookSecret: "mock-secret", webhook: hookUrl, siteUrl: site }).listen(0); await new Promise((r) => srv.once("listening", r)); const base = `http://127.0.0.1:${srv.address().port}`; const hook = (u) => fetch(base + WEBHOOK_PATH, { method: "POST", headers: { "content-type": "application/json", "x-telegram-bot-api-secret-token": "mock-secret" }, body: JSON.stringify(u) }); const say = (text) => hook({ message: { from: { id: TATIANA, first_name: "Татьяна" }, chat: { id: TATIANA }, text } }); const toTatiana = () => telegram.posts[String(TATIANA)] ?? []; const get = async (u) => (await fetch(base + u)).text(); return { srv, telegram, say, toTatiana, last: () => toTatiana().at(-1), page: () => get("/bot.html"), home: () => get("/"), summary: () => get("/summary.html"), post: (u) => fetch(base + u, { method: "POST", redirect: "manual" }), close: () => srv.close(), }; } const nowItems = (html) => [...html.matchAll(/