Сервер на Hono, клиент Google и его мок, переводы ru/kk/en, тесты по сценариям, проверки и деплой (Dockerfile, /healthz). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
import { readFileSync } from "node:fs";
|
||
import { describe, expect, it } from "vitest";
|
||
import en from "../src/locales/en.json" with { type: "json" };
|
||
import kk from "../src/locales/kk.json" with { type: "json" };
|
||
import ru from "../src/locales/ru.json" with { type: "json" };
|
||
|
||
/** Слова из колонки «Нельзя» словаря docs/glossary.md. */
|
||
function bannedWords(): string[] {
|
||
const lines = readFileSync(new URL("../docs/glossary.md", import.meta.url), "utf8").split("\n");
|
||
return lines
|
||
.filter(
|
||
(line) => line.startsWith("|") && !line.startsWith("|---") && !line.startsWith("| Понятие"),
|
||
)
|
||
.flatMap((line) => (line.split("|")[3] ?? "").split(","))
|
||
.map((word) => word.trim())
|
||
.filter(Boolean);
|
||
}
|
||
|
||
function findBanned(text: string, banned: string[]): string[] {
|
||
return banned.filter((word) => {
|
||
const escaped = word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||
return new RegExp(`(?<![\\p{L}\\p{N}])${escaped}(?![\\p{L}\\p{N}])`, "iu").test(text);
|
||
});
|
||
}
|
||
|
||
describe("тексты экрана и словарь", () => {
|
||
const banned = bannedWords();
|
||
|
||
it("словарь читается", () => {
|
||
expect(banned).toContain("стори");
|
||
expect(banned).toContain("мок");
|
||
});
|
||
|
||
it.each([
|
||
["ru", ru],
|
||
["kk", kk],
|
||
["en", en],
|
||
])("в текстах %s нет слов из колонки «Нельзя»", (_name, file) => {
|
||
for (const [key, value] of Object.entries(file)) {
|
||
expect(findBanned(value, banned), `${key}: ${value}`).toEqual([]);
|
||
}
|
||
});
|
||
|
||
it("русские тексты обращаются на «вы» со строчной буквы", () => {
|
||
for (const value of Object.values(ru)) expect(value).not.toMatch(/(?<![.!?] |^)Вы(?![\p{L}])/u);
|
||
});
|
||
});
|