brendmanager/test/contact.test.js
Peppa 753043756e
All checks were successful
peppa/lint lint: success за 1с
peppa/test test: success за 1с
ci / checks (pull_request) Successful in 6s
deploy / deploy (pull_request) Successful in 14s
BRM-88: настоящий адрес для связи попадает в выкладку
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 21:52:15 +05:00

30 lines
1.9 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.

import test from "node:test";
import assert from "node:assert/strict";
import { homePage, pageHtml, CONTACT_MAIL } from "../src/site.js";
test("Сценарий: способ связи одинаков на главной и на «Рынке», слова про задачу не встречаются", () => {
for (const lang of ["ru", "kk", "en"]) {
// BRM-87: «@» записан кодом (&#64; и %40), чтобы адрес не подменял Cloudflare
const dec = (h) => h.replaceAll("&#64;", "@").replaceAll("%40", "@");
const home = dec(homePage(lang));
const market = dec(pageHtml("market.html", lang));
assert.ok(home.includes(CONTACT_MAIL) && market.includes(CONTACT_MAIL), lang);
assert.ok(home.includes(`href="mailto:${CONTACT_MAIL}"`) && market.includes(`href="mailto:${CONTACT_MAIL}"`), lang);
assert.doesNotMatch(home + market, /к задаче|тапсырмаға|on the task/);
if (lang === "ru") assert.doesNotMatch((home + market).replace(/<[^>]+>/g, " "), /задач|BRM-\d+/i);
}
});
test("Сценарий: с настоящим адресом в окружении пометки «адрес-пример» нет, а без него она остаётся", async () => {
const { execFileSync } = await import("node:child_process");
const run = (env) => execFileSync(process.execPath, ["--input-type=module", "-e",
`import { homePage, pageHtml } from "./src/site.js"; process.stdout.write(homePage("ru") + pageHtml("market.html", "ru"));`],
{ env: { PATH: process.env.PATH, ...env }, encoding: "utf8" });
const real = run({ CONTACT_EMAIL: "hello@brand.example" }).replaceAll("&#64;", "@").replaceAll("%40", "@");
assert.ok(real.includes('href="mailto:hello@brand.example"'));
assert.doesNotMatch(real, /адрес-пример/);
assert.doesNotMatch(real, /mockcontact/);
const mock = run({ CONTACT_EMAIL: "" });
assert.match(mock, /адрес-пример/);
});