88 lines
3.7 KiB
TypeScript
88 lines
3.7 KiB
TypeScript
// PEP-185, spec pick-question: a ready backlog story comes as «Взять в работу?».
|
|
import assert from "node:assert/strict";
|
|
import { after, before, describe, test } from "node:test";
|
|
import { core, db, runner, teardown } from "./helpers.ts";
|
|
|
|
process.env.PEPPA_SECRET = "mock-secret-for-tests";
|
|
before(() => {
|
|
delete process.env.PEPPA_PICK_QUESTION;
|
|
});
|
|
after(async () => {
|
|
process.env.PEPPA_PICK_QUESTION = "off";
|
|
await teardown();
|
|
});
|
|
|
|
let n = 0;
|
|
async function proj() {
|
|
n++;
|
|
return core.createProject(db, { slug: `mock-pick-${n}`, key: `PK${String.fromCharCode(64 + n)}`, name: `Выбор ${n}`, giteaOwner: "peppa-bot", giteaRepo: `mock-pick-${n}`, workspacePath: `/tmp/mock-pick-${n}` });
|
|
}
|
|
const story = (projectId: number, title: string) => core.createTask(db, { projectId, title });
|
|
const open = async (projectId: number) => (await core.pendingQuestions(db, projectId)).filter((q) => q.kind === "question" && q.options?.includes(runner.PICK_TAKE));
|
|
|
|
describe("PEP-185: «Взять в работу?»", () => {
|
|
test("ready story → one question with two options; «Пока нет» is not asked again", async () => {
|
|
const p = await proj();
|
|
const t = await story(p.id, "Каталог");
|
|
await runner.pickQuestionTick(db);
|
|
await runner.pickQuestionTick(db);
|
|
const qs = await open(p.id);
|
|
assert.equal(qs.length, 1);
|
|
assert.deepEqual(qs[0]!.options, [runner.PICK_TAKE, runner.PICK_LATER]);
|
|
assert.equal(qs[0]!.msgType, "question");
|
|
assert.equal(qs[0]!.defaultOption, runner.PICK_TAKE);
|
|
await runner.answerAndDeliver(db, qs[0]!.id, runner.PICK_LATER, "web");
|
|
await runner.pickQuestionTick(db);
|
|
assert.equal((await open(p.id)).length, 0);
|
|
assert.equal((await runner.resolveTaskById(db, t.task.id)).task.status, "backlog");
|
|
});
|
|
|
|
test("story moved by the board button → question closed silently", async () => {
|
|
const p = await proj();
|
|
const t = await story(p.id, "Корзина");
|
|
await runner.pickQuestionTick(db);
|
|
const [q] = await open(p.id);
|
|
assert.ok(q);
|
|
await core.updateTask(db, t, { status: "in_progress" });
|
|
await runner.pickQuestionTick(db);
|
|
assert.equal((await open(p.id)).length, 0);
|
|
const closed = await core.getQuestion(db, q.id);
|
|
assert.equal(closed.answeredVia, "system");
|
|
});
|
|
|
|
test("5 ready stories → 3 open, the 4th after an answer", async () => {
|
|
const p = await proj();
|
|
for (let i = 1; i <= 5; i++) await story(p.id, `Задача ${i}`);
|
|
await runner.pickQuestionTick(db);
|
|
const qs = await open(p.id);
|
|
assert.equal(qs.length, 3);
|
|
await runner.answerAndDeliver(db, qs[0]!.id, runner.PICK_LATER, "web");
|
|
await runner.pickQuestionTick(db);
|
|
assert.equal((await open(p.id)).length, 3);
|
|
});
|
|
|
|
test("paused / blocked / auto projects are not asked", async () => {
|
|
const paused = await proj();
|
|
await story(paused.id, "A");
|
|
await core.setSetting(db, `project.paused:${paused.id}`, { since: Date.now(), by: "x", sessions: [] });
|
|
await runner.pickQuestionTick(db);
|
|
assert.equal((await open(paused.id)).length, 0);
|
|
|
|
const blocked = await proj();
|
|
const first = await story(blocked.id, "Первая");
|
|
const second = await story(blocked.id, "Вторая");
|
|
await core.addDependency(db, second, first);
|
|
await runner.pickQuestionTick(db);
|
|
const qs = await open(blocked.id);
|
|
assert.equal(qs.length, 1);
|
|
assert.equal(qs[0]!.taskId, first.task.id);
|
|
assert.notEqual(qs[0]!.taskId, second.task.id);
|
|
|
|
const auto = await proj();
|
|
await core.setAutonomy(db, auto.id, { level: "auto" });
|
|
await story(auto.id, "B");
|
|
await runner.pickQuestionTick(db);
|
|
assert.equal((await open(auto.id)).length, 0);
|
|
});
|
|
});
|