brendmanager/tests/knowledge-base.test.ts
2026-11-15 14:39:33 +05:00

55 lines
3.1 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 { beforeEach, describe, expect, it } from "vitest";
import { setup } from "./helpers.js";
let t: Awaited<ReturnType<typeof setup>>;
beforeEach(async () => { t = await setup(); });
describe("Requirement: Факты со статусом достоверности", () => {
it("Scenario: Создание факта с источником", async () => {
const src = (await t.call("POST", "/sources", { title: "LinkedIn-профиль" })).json();
const res = await t.call("POST", "/career", { organization: "Казахтелеком", status: "hypothesis", source_evidence_id: src.id });
expect(res.statusCode).toBe(201);
const body = res.json();
expect(body.created_at).toBeTruthy();
expect(body.updated_at).toBeTruthy();
expect(body.source_evidence_id).toBe(src.id);
});
it("Scenario: Недопустимый статус", async () => {
const res = await t.call("POST", "/cases", { title: "Кейс", status: "точно правда" });
expect(res.statusCode).toBe(422);
expect((await t.call("GET", "/cases")).json()).toHaveLength(0);
});
it("Scenario: несуществующий источник — 422", async () => {
const res = await t.call("POST", "/career", { organization: "X", source_evidence_id: 999 });
expect(res.statusCode).toBe(422);
});
});
describe("Requirement: Публичный вывод только подтверждённого", () => {
it("Scenario: Гипотеза скрыта", async () => {
await t.call("POST", "/career", { organization: "Казпочта", status: "public_confirmed" });
await t.call("POST", "/career", { organization: "Грант", status: "hypothesis" });
const rows = (await t.call("GET", "/career?audience=public")).json();
expect(rows.map((r: { organization: string }) => r.organization)).toEqual(["Казпочта"]);
});
it("Scenario: Кейс без разрешения", async () => {
await t.call("POST", "/cases", { title: "Закрытый", status: "public_confirmed", public_use_permitted: false });
await t.call("POST", "/cases", { title: "Открытый", status: "public_confirmed", public_use_permitted: true });
const rows = (await t.call("GET", "/cases?audience=public")).json();
expect(rows.map((r: { title: string }) => r.title)).toEqual(["Открытый"]);
});
});
describe("Requirement: Историческая роль не текущая", () => {
it("Scenario: Прошлая должность", async () => {
await t.call("POST", "/career", { organization: "Телеконтакт", position: "генеральный директор", is_current: false, status: "public_confirmed" });
await t.call("POST", "/career", { organization: "Grow Consulting", is_current: true, status: "public_confirmed" });
const body = (await t.call("GET", "/public-profile")).json();
expect(body.current_roles.map((r: { organization: string }) => r.organization)).toEqual(["Grow Consulting"]);
expect(body.past_roles.map((r: { organization: string }) => r.organization)).toEqual(["Телеконтакт"]);
});
});