peppa/packages/testkit/test/platform-dashboard.test.ts
2026-11-16 15:31:58 +05:00

47 lines
2.6 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.

// PEP-167: the superadmin's dashboard — totals, a row per user and per project, what needs attention.
import assert from "node:assert/strict";
import { after, before, describe, test } from "node:test";
import { tasks } from "@peppa/db";
import { eq } from "drizzle-orm";
import { core, db, teardown } from "./helpers.ts";
process.env.PEPPA_SECRET ??= "mock-secret-for-tests";
after(teardown);
let ownerId = 0;
let loneId = 0;
before(async () => {
const owner = await core.upsertUserFromGitea(db, { id: 167, login: "mock-dash-owner" }, { access_token: "x" });
const lone = await core.upsertUserFromGitea(db, { id: 168, login: "mock-dash-lone" }, { access_token: "x" });
ownerId = owner.id;
loneId = lone.id;
const p = await core.createProject(db, { slug: "mock-dash", key: "MDASH", name: "Dash", ownerId: owner.id, giteaOwner: "mock", workspacePath: "/tmp/mock-dash" });
const a = await core.createTask(db, { projectId: p.id, title: "Готовая" });
const b = await core.createTask(db, { projectId: p.id, title: "На приёмке" });
await core.createTask(db, { projectId: p.id, title: "В бэклоге" });
await db.update(tasks).set({ status: "done" }).where(eq(tasks.id, a.task.id));
// «Принять» waits for two days.
await db.update(tasks).set({ status: "review", updatedAt: new Date(Date.now() - 48 * 3600_000) }).where(eq(tasks.id, b.task.id));
});
describe("PEP-167: дашборд суперадмина", () => {
test("итоги, строка пользователя и проекта", async () => {
const d = await core.platformDashboard(db);
const p = d.projects.find((x) => x.key === "MDASH")!;
assert.deepEqual({ done: p.done, review: p.review, backlog: p.backlog, total: p.total, owner: p.ownerLogin }, { done: 1, review: 1, backlog: 1, total: 3, owner: "mock-dash-owner" });
const u = d.users.find((x) => x.id === ownerId)!;
assert.deepEqual(u.projects, ["MDASH"]);
assert.equal(u.done, 1);
assert.ok(d.totals.total >= 3 && d.totals.users >= 2);
});
test("«Требует внимания»: «Принять» ждёт дольше суток; пользователь без проекта — через час", async () => {
const d = await core.platformDashboard(db);
assert.ok(d.attention.some((a) => a.kind === "review" && a.text.includes("MDASH")));
assert.ok(!d.attention.some((a) => a.kind === "no_project" && a.who === "mock-dash-lone"), "just signed up — not yet");
const later = await core.platformDashboard(db, new Date(Date.now() + 2 * 3600_000));
assert.ok(later.attention.some((a) => a.kind === "no_project" && a.who === "mock-dash-lone"));
void loneId;
});
});