All checks were successful
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
4.9 KiB
TypeScript
89 lines
4.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
||
import { buildApp } from "../src/app.js";
|
||
import { openDb } from "../src/db.js";
|
||
import { runSearch, saveFind } from "../src/digest.js";
|
||
import { hhSearchUrl } from "../src/cabinet.js";
|
||
import { HhResumeSource, mockHhFetch } from "../src/resume-sources.js";
|
||
|
||
function setup(configured: string[] = []) {
|
||
const db = openDb();
|
||
const app = buildApp({ db, apiToken: "t0ken", digest: { sources: [], configured, tg: () => undefined } });
|
||
return { db, app };
|
||
}
|
||
async function open(app: ReturnType<typeof setup>["app"], url = "/team/resumes") {
|
||
const res = await app.inject({ method: "POST", url: "/team/login", headers: { "content-type": "application/x-www-form-urlencoded" }, payload: "key=t0ken" });
|
||
const cookie = String(res.headers["set-cookie"]).split(";")[0]!;
|
||
return app.inject({ method: "GET", url, headers: { cookie } });
|
||
}
|
||
const section = (body: string, title: string) => body.split("<section>").find((s) => s.includes(`<h2>${title}`)) ?? "";
|
||
|
||
describe("resume-cabinet", () => {
|
||
it("Scenario: Резюме из Кокшетау в офисе Астаны", async () => {
|
||
const { db, app } = setup(["hh"]);
|
||
saveFind(db, { url: "https://hh.kz/resume/abc123", source: "hh", city: "kokshetau", title: "Оператор call-центра", age: 22 });
|
||
const page = await open(app);
|
||
expect(page.statusCode).toBe(200);
|
||
const astana = section(page.body, "Астана");
|
||
expect(astana).toContain('href="https://hh.kz/resume/abc123"');
|
||
expect(astana).toContain("Кокшетау");
|
||
expect(astana).toContain("Язык (казахский, русский): нужно уточнить");
|
||
expect(astana).toContain("Ожидания по оплате: нужно уточнить");
|
||
expect(section(page.body, "Алматы")).not.toContain("abc123");
|
||
});
|
||
|
||
it("Scenario: Без входа", async () => {
|
||
const { db, app } = setup(["hh"]);
|
||
saveFind(db, { url: "https://hh.kz/resume/abc123", source: "hh", city: "almaty" });
|
||
const page = await app.inject({ method: "GET", url: "/team/resumes" });
|
||
expect(page.body).toContain("Ключ доступа");
|
||
expect(page.body).not.toContain("abc123");
|
||
const forged = await app.inject({ method: "GET", url: "/team/resumes", headers: { cookie: "team_session=abc" } });
|
||
expect(forged.body).not.toContain("abc123");
|
||
});
|
||
|
||
it("Scenario: Нет ключа кабинета работодателя hh.kz", async () => {
|
||
const { app } = setup([]);
|
||
const aktobe = section((await open(app)).body, "Актобе");
|
||
expect(aktobe).toContain("нужен ключ кабинета работодателя hh.kz");
|
||
expect(aktobe).toContain(hhSearchUrl("aktobe").replace(/&/g, "&"));
|
||
expect(hhSearchUrl("aktobe")).toMatch(/^https:\/\/hh\.kz\/search\/resume\?.*area=154$/);
|
||
expect(hhSearchUrl("almaty")).toContain("area=160&area=188");
|
||
expect(aktobe).toContain("https://www.enbek.kz/ru/search/resume");
|
||
});
|
||
|
||
it("Scenario: Поиск работает, новых резюме нет", async () => {
|
||
const { db, app } = setup(["hh"]);
|
||
await runSearch(db, [new HhResumeSource("tok", mockHhFetch([]))], () => {});
|
||
const body = (await open(app)).body;
|
||
for (const o of ["Алматы", "Актобе", "Астана"]) expect(section(body, o)).toContain("За последние 30 дней новых резюме нет.");
|
||
});
|
||
|
||
it("ключ отклонён — причина видна", async () => {
|
||
const { db, app } = setup(["hh"]);
|
||
await runSearch(db, [new HhResumeSource("tok", mockHhFetch([], 403))], () => {});
|
||
expect(section((await open(app)).body, "Астана")).toContain("hh.kz отклонил ключ");
|
||
});
|
||
|
||
it("Scenario: Примеры при пустом списке", async () => {
|
||
const body = (await open(setup().app)).body;
|
||
expect(body).toContain("Пример — не настоящее резюме");
|
||
const ex = body.slice(body.indexOf('class="example"'));
|
||
expect(ex).not.toContain("href=");
|
||
});
|
||
|
||
it("Scenario: Есть настоящее резюме", async () => {
|
||
const { db, app } = setup(["hh"]);
|
||
saveFind(db, { url: "https://hh.kz/resume/xyz", source: "hh", city: "almaty" });
|
||
const body = (await open(app)).body;
|
||
expect(body).not.toContain("Пример — не настоящее резюме");
|
||
expect(section(body, "Алматы")).toContain("Найдено резюме: 1.");
|
||
});
|
||
|
||
it("ссылка из кабинета на странице команды и тексты на казахском и английском", async () => {
|
||
const { app } = setup();
|
||
expect((await open(app, "/team")).body).toContain('href="/team/resumes?lang=ru"');
|
||
expect((await open(app, "/team/resumes?lang=kk")).body).toContain("нақтылау керек");
|
||
expect((await open(app, "/team/resumes?lang=en")).body).toContain("Example — not a real resume");
|
||
});
|
||
});
|