70 lines
4.1 KiB
TypeScript
70 lines
4.1 KiB
TypeScript
// PEP-111: «Ваш продукт» — where the project's result lives and how releases are said to a PM.
|
|
import assert from "node:assert/strict";
|
|
import { after, describe, test } from "node:test";
|
|
import { releases } from "@peppa/db";
|
|
import { core, db, teardown } from "./helpers.ts";
|
|
|
|
after(teardown);
|
|
let n = 0;
|
|
const proj = async () => {
|
|
n++;
|
|
return core.createProject(db, { slug: `mock-prod-${n}`, key: `MPR${String.fromCharCode(64 + n)}`, name: `Продукт ${n}`, giteaOwner: "x", workspacePath: `/tmp/mock-prod-${n}` });
|
|
};
|
|
const rel = (projectId: number, env: "preview" | "staging" | "prod", sha: string, status: "healthy" | "removed" | "failed" = "healthy", tasks: string[] = []) =>
|
|
db.insert(releases).values({ projectId, env, sha, status, host: `${env}.mock.test`, tasks }).returning().then((r) => r[0]!);
|
|
|
|
describe("PEP-111: the project's product", () => {
|
|
test("nothing deployed: no versions, only the count of accepted stories", async () => {
|
|
const p = await proj();
|
|
const t = await core.createTask(db, { projectId: p.id, title: "Первая" });
|
|
assert.deepEqual(await core.projectProduct(db, p.id), { live: null, check: null, doneStories: 0 });
|
|
await core.updateTask(db, t, { status: "done" });
|
|
assert.equal((await core.projectProduct(db, p.id)).doneStories, 1);
|
|
assert.equal((await core.productUrls(db, [p.id])).size, 0);
|
|
});
|
|
|
|
test("staging only → the version to check; prod → the working product; a newer staging is offered again", async () => {
|
|
const p = await proj();
|
|
await rel(p.id, "preview", "aaa1111", "removed");
|
|
await rel(p.id, "staging", "bbb2222", "healthy", ["X-1"]);
|
|
let v = await core.projectProduct(db, p.id);
|
|
assert.equal(v.live, null);
|
|
assert.equal(v.check?.url, "https://staging.mock.test");
|
|
assert.deepEqual((await core.productUrls(db, [p.id])).get(p.id), { url: "https://staging.mock.test", live: false });
|
|
|
|
await rel(p.id, "prod", "bbb2222", "healthy", ["X-1"]);
|
|
v = await core.projectProduct(db, p.id);
|
|
assert.equal(v.live?.url, "https://prod.mock.test");
|
|
assert.deepEqual(v.live?.stories, ["X-1"]);
|
|
assert.equal(v.check, null, "the same commit is already live");
|
|
assert.deepEqual((await core.productUrls(db, [p.id])).get(p.id), { url: "https://prod.mock.test", live: true });
|
|
|
|
await rel(p.id, "staging", "ccc3333", "healthy", ["X-2"]);
|
|
v = await core.projectProduct(db, p.id);
|
|
assert.equal(v.live?.url, "https://prod.mock.test");
|
|
assert.deepEqual(v.check?.stories, ["X-2"], "a newer version waits to be shown to everyone");
|
|
});
|
|
|
|
test("the chat says releases in plain words and keeps the draft stands out", async () => {
|
|
const p = await proj();
|
|
await rel(p.id, "preview", "ddd4444", "healthy");
|
|
await rel(p.id, "preview", "ddd4445", "removed");
|
|
await rel(p.id, "preview", "ddd4446", "failed");
|
|
await rel(p.id, "staging", "eee5555", "healthy", ["Y-1"]);
|
|
await rel(p.id, "prod", "eee5555", "healthy", ["Y-1"]);
|
|
await core.syncChats(db);
|
|
const chat = await core.ensureProjectChat(db, p.id);
|
|
const texts = (await core.chatMessagesView(db, chat.id, {})).map((m) => m.text);
|
|
assert.deepEqual(texts, ["❌ Черновой стенд стори: не выкатилась", "🚀 Версия для проверки: работает · стори: Y-1", "🚀 Рабочая версия продукта: работает · стори: Y-1"]);
|
|
assert.ok(texts.every((t) => !/[0-9a-f]{7}/.test(t)), "no commit hashes for a product manager");
|
|
});
|
|
|
|
test("the Home page carries the product link of each project", async () => {
|
|
const owner = await core.registerEgovUser(db, { iin: "880808400011", name: "ПРОДАКТ ТЕСТОВЫЙ" });
|
|
const p = await core.createProject(db, { slug: "mock-prod-home", key: "MPRH", name: "Домой", giteaOwner: "x", workspacePath: "/tmp/mock-prod-home", ownerId: owner.id });
|
|
await rel(p.id, "prod", "fff6666");
|
|
const o = await core.progressOverview(db, owner.id);
|
|
assert.deepEqual(o.mine.find((x) => x.key === "MPRH")?.product, { url: "https://prod.mock.test", live: true });
|
|
});
|
|
});
|