freetravel/test/filters.test.ts
Peppa 2835b75e2d
All checks were successful
peppa/lint lint: success за 2с
peppa/typecheck typecheck: success за 3с
peppa/test test: success за 1с
deploy / deploy (pull_request) Successful in 23s
peppa/build build: success за 2с
ci / checks (pull_request) Successful in 29s
FRTVL-16: настоящий бот на стендах, понятная причина ненастроенного бота
- ключи бота перенесены в секреты Actions репозитория (не в файлах)
- /api/settings отдаёт telegramProblem; экран показывает причину и «Подробнее»
- привязка-пример сбрасывается при старте с настоящим ботом

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 17:04:29 +05:00

91 lines
4.9 KiB
TypeScript
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 { describe, expect, it } from "vitest";
import { applyFilters, countriesOf, emptyMessage, isExample, runSummary } from "../public/filters.js";
const cards = [
{ country: "Швейцария", language: "russian" },
{ country: "Турция", language: "russian" },
];
describe("Requirement: Фильтры", () => {
it("Scenario: Фильтр по стране", () => {
expect(applyFilters(cards, { country: "Турция" })).toEqual([{ country: "Турция", language: "russian" }]);
});
it("Scenario: Фильтр без совпадений", () => {
const shown = applyFilters(cards, { language: "not_required" });
expect(shown).toEqual([]);
expect(emptyMessage(cards.length, shown.length)).toBe("Нет стажировок под выбранные фильтры — выберите «Все» или другую страну");
});
it("без фильтров показывает всё, страны — по алфавиту", () => {
expect(applyFilters(cards, {})).toHaveLength(2);
expect(countriesOf(cards)).toEqual(["Турция", "Швейцария"]);
});
});
describe("Requirement: Список стажировок", () => {
it("Scenario: Пустой каталог", () => {
expect(emptyMessage(0, 0)).toBe("Пока ничего не найдено — нажмите «Найти новые»");
});
});
describe("Requirement: Запуск поиска со страницы — отчёт", () => {
it("показывает итог запуска и ошибку", () => {
expect(runSummary({ status: "ok", found: 3, added: 2, rejected: 1 })).toBe("найдено: 3, новых: 2, отброшено: 1");
expect(runSummary({ status: "error", found: 0, added: 0, rejected: 0, error: "нет сети" })).toBe(
"Поиск завершился ошибкой: нет сети",
);
expect(runSummary(null)).toBe("Поиск ещё не запускался");
});
});
import { settingsErrorMessage, telegramDetail, telegramState } from "../public/filters.js";
describe("Requirement: Состояние Телеграма (FRTVL-8)", () => {
it("Scenario: три шага привязки", () => {
expect(telegramState({ linked: false }).step).toBe("unlinked");
expect(telegramState({ linked: false, linkUrl: "https://t.me/x" }).step).toBe("pending");
expect(telegramState({ linked: true }).status).toBe("Телеграм привязан");
});
it("Scenario: ошибки простыми словами", () => {
expect(settingsErrorMessage(401, undefined)).toContain("Неверный код доступа");
expect(settingsErrorMessage(500, "boom")).not.toContain("boom");
expect(settingsErrorMessage(409, "Нет действующего кода привязки")).toContain("Нет действующего кода привязки");
});
});
describe("Requirement: Примеры помечены", () => {
it("Scenario: пример — источник на example.org, настоящая — нет", () => {
expect(isExample({ sourceUrl: "https://example.org/mock/a" })).toBe(true);
expect(isExample({ sourceUrl: "https://hotel.com/jobs" })).toBe(false);
expect(isExample({ sourceUrl: "не адрес" })).toBe(false);
});
});
describe("Requirement: Бот не настроен (FRTVL-13)", () => {
it("Scenario: настоящий режим без имени бота — понятная подсказка", () => {
expect(telegramState({ linked: false, telegram: "telegram", botUsername: "" }).note).toContain("Бот не настроен");
expect(telegramState({ linked: false, telegram: "telegram", botUsername: "nternships_bot" }).note).toContain("Привязать Телеграм");
});
});
describe("Requirement: Понятная причина, почему бот не настроен (FRTVL-16)", () => {
it("Scenario: Ключ не дошёл до сервиса", () => {
const tg = telegramState({ linked: false, telegram: "mock", telegramProblem: "no_token" });
expect(tg.note).toContain("Бот ещё не настроен: ключ Телеграм-бота не дошёл до сервиса");
expect(tg.detail).toBe("Нет TELEGRAM_BOT_TOKEN в окружении сервиса.");
});
it("Scenario: Ключ не подошёл", () => {
const tg = telegramState({ linked: false, telegram: "telegram", botUsername: "", telegramProblem: "bad_token" });
expect(tg.note).toContain("владельцу сервиса нужно проверить ключ Телеграм-бота");
expect(tg.detail).toBe("Телеграм не принял TELEGRAM_BOT_TOKEN (getMe).");
});
it("Scenario: Бот работает — подробностей нет", () => {
expect(telegramState({ linked: false, telegram: "telegram", botUsername: "nternships_bot", telegramProblem: null }).detail).toBe("");
expect(telegramDetail(undefined)).toBe("");
});
});