brendmanager/test/brm154-one-send-reason.test.js
peppa-bot 4efe5de2a2
All checks were successful
peppa/lint lint: success за 2с
peppa/test test: success за 9с
ci / checks (pull_request) Successful in 22s
deploy / deploy (pull_request) Successful in 38s
BRM-154: одна причина выключенной отправки на главной, «Сводке» и «Бот и отчёты», тест и спека
После rebase на main: общая причина — строка «Отправка сводок» из «Бот сейчас» (BRM-180).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 15:41:02 +00:00

41 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// BRM-154: главная, «Сводка» и «Бот и отчёты» объясняют выключенную отправку одним текстом.
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 { createTelegram } from "../src/telegram.js";
async function pages(telegram, lang) {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "brm154-"));
const srv = createApp({ file: path.join(dir, "plan.json"), metricsFile: path.join(dir, "m.json"), oppsFile: path.join(dir, "o.json"), telegram, webhook: "" }).listen(0);
await new Promise((r) => srv.once("listening", r));
const base = `http://127.0.0.1:${srv.address().port}`;
try {
const get = async (u) => (await fetch(base + u + "?lang=" + lang)).text();
return { "главная": await get("/"), "Сводка": await get("/summary.html"), "Бот и отчёты": await get("/bot.html") };
} finally { srv.close(); }
}
const noFetch = async () => { throw new Error("сеть в тесте не нужна"); };
const esc = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
const forbidden = /Секрет|настройках проекта|не передан|TELEGRAM_CHAT_ID|BRAND_BOT_TOKEN|Құпиялар|Secrets/;
// После BRM-180 общая причина — строка «Отправка сводок: выключена — …» из «Бот сейчас» (как ответ бота на «Статус»).
const lineOf = (html) => (html.match(/<li id="nowsend"[^>]*>([^<]+)<\/li>/) || html.match(/<p id="tg"[^>]*>([^<]+)<\/p>/) || [])[1] ?? "";
for (const lang of ["ru", "kk", "en"]) {
for (const [title, token] of [["Бот подключён, чат не выбран", "mock-brand-token"], ["Ключа бота нет", ""]]) {
test(`Сценарий: ${title} — везде одно объяснение (${lang})`, async () => {
const all = await pages(createTelegram({ token, chatId: "", fetchImpl: noFetch }), lang);
const home = lineOf(all["главная"]);
assert.ok(home.length > 0, "главная: нет строки об отправке");
for (const [name, html] of Object.entries(all)) {
assert.ok(lineOf(html).startsWith(home), `${name}: причина отличается от главной`);
assert.doesNotMatch(html, forbidden, name);
assert.ok(!html.includes("mock-brand-token"), name);
}
});
}
}