66 lines
3.2 KiB
TypeScript
66 lines
3.2 KiB
TypeScript
import { beforeEach, describe, expect, it } from "vitest";
|
||
import { redact } from "../src/app.js";
|
||
import { setup } from "./helpers.js";
|
||
|
||
let t: Awaited<ReturnType<typeof setup>>;
|
||
beforeEach(async () => { t = await setup(); });
|
||
|
||
describe("Requirement: Режимы полномочий", () => {
|
||
it("Scenario: Режим C без одобрения", async () => {
|
||
const res = await t.call("POST", "/actions/set_public_positioning", { payload: { text: "x" } });
|
||
expect(res.statusCode).toBe(403);
|
||
const approvals = (await t.call("GET", "/approvals")).json();
|
||
expect(approvals).toHaveLength(1);
|
||
expect(approvals[0].status).toBe("pending");
|
||
});
|
||
|
||
it("Scenario: Режим C с одобрением", async () => {
|
||
const { approval_id } = (await t.call("POST", "/actions/set_public_positioning", {})).json();
|
||
await t.call("POST", `/approvals/${approval_id}/decision`, { decision: "approved" });
|
||
const res = await t.call("POST", "/actions/set_public_positioning", { approval_id });
|
||
expect(res.statusCode).toBe(200);
|
||
// одобрение одноразовое
|
||
expect((await t.call("POST", "/actions/set_public_positioning", { approval_id })).statusCode).toBe(403);
|
||
});
|
||
|
||
it("Scenario: Отклонённое согласование не открывает действие", async () => {
|
||
const { approval_id } = (await t.call("POST", "/actions/send_commercial_offer", {})).json();
|
||
await t.call("POST", `/approvals/${approval_id}/decision`, { decision: "rejected" });
|
||
expect((await t.call("POST", "/actions/send_commercial_offer", { approval_id })).statusCode).toBe(403);
|
||
});
|
||
|
||
it("Scenario: Режим A", async () => {
|
||
const res = await t.call("POST", "/actions/create_hypothesis", {});
|
||
expect(res.statusCode).toBe(200);
|
||
});
|
||
|
||
it("Scenario: неизвестное действие — 404", async () => {
|
||
expect((await t.call("POST", "/actions/nope", {})).statusCode).toBe(404);
|
||
});
|
||
});
|
||
|
||
describe("Requirement: Журнал действий", () => {
|
||
it("Scenario: Изменение пишет журнал", async () => {
|
||
const c = (await t.call("POST", "/career", { organization: "X", position: "Директор" })).json();
|
||
await t.call("PATCH", `/career/${c.id}`, { position: "Генеральный директор" });
|
||
const logs = (await t.call("GET", "/audit")).json();
|
||
const upd = logs.find((l: { entity: string; action: string }) => l.entity === `career_history/${c.id}` && l.action === "update");
|
||
expect(upd.before.position).toBe("Директор");
|
||
expect(upd.after.position).toBe("Генеральный директор");
|
||
});
|
||
|
||
it("Scenario: Без токена", async () => {
|
||
const res = await t.call("POST", "/cases", { title: "x" }, null);
|
||
expect(res.statusCode).toBe(401);
|
||
expect(await t.db.query("select * from audit_logs")).toHaveLength(0);
|
||
});
|
||
|
||
it("Scenario: секреты не попадают в журнал", () => {
|
||
expect(redact({ api_token: "abc", nested: { password: "p", ok: 1 } })).toEqual({ api_token: "[redacted]", nested: { password: "[redacted]", ok: 1 } });
|
||
});
|
||
|
||
it("healthz открыт без токена", async () => {
|
||
expect((await t.call("GET", "/healthz", undefined, null)).statusCode).toBe(200);
|
||
});
|
||
});
|