import { describe, expect, it } from "vitest"; import { buildApp } from "../src/app.js"; import { openDb } from "../src/db.js"; import { computePlan, dailyReport } from "../src/funnel.js"; describe("hiring-funnel", () => { it.each([ [10, [0.05], 10, 200, 20], [3, [0.1], 4, 30, 8], ])("Scenario Outline: цель %i, конв %j, дней %i → %i резюме, %i в день", (t, c, d, r, p) => { expect(computePlan(t, c, d)).toMatchObject({ resumes: r, perDay: p }); }); it("Scenario: Нулевая конверсия — ошибка валидации", () => { expect(() => computePlan(10, [0.5, 0], 10)).toThrow("конверсии"); }); it("Scenario: Ежедневный отчёт — 25 из 20", () => { const db = openDb(); db.prepare("INSERT INTO vacancies (title, target_count) VALUES ('V', 1)").run(); db.prepare("INSERT INTO runs (vacancy_id, found) VALUES (1, 25)").run(); db.prepare("INSERT INTO candidates (vacancy_id, full_name, status) VALUES (1, 'Анна', 'qualified')").run(); const r = dailyReport(db, 1, 20); expect(r.summary).toBe("25 из 20"); expect(r.suitable).toHaveLength(1); }); it("API: план по умолчанию (5%) и ошибка нулевой конверсии (400)", async () => { const app = buildApp({ db: openDb(), apiToken: "t" }); const h = { authorization: "Bearer t" }; await app.inject({ method: "POST", url: "/api/vacancies", headers: h, payload: { title: "V", targetCount: 10 } }); const plan = await app.inject({ method: "GET", url: "/api/vacancies/1/plan?days=10", headers: h }); expect(plan.json()).toMatchObject({ resumes: 200, perDay: 20 }); const bad = await app.inject({ method: "PUT", url: "/api/vacancies/1/conversions", headers: h, payload: { conversions: [0.5, 0] } }); expect(bad.statusCode).toBe(400); }); });