Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

38 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { readFileSync, readdirSync } from "node:fs";
3import { DatabaseSync } from "node:sqlite";
4import { test } from "node:test";
5
6const dir = new URL("../migrations/", import.meta.url);
7const MIGRATION = "0008_work_item_cards.sql";
8
9test("cards kept about issues are about work items after the migration, run once or twice", () => {
10 const db = new DatabaseSync(":memory:");
11 for (const file of readdirSync(dir).sort()) {
12 if (file >= MIGRATION) break;
13 db.exec(readFileSync(new URL(file, dir), "utf8"));
14 }
15 db.exec("INSERT INTO channels (id, workspace_id, kind, name, created_by, created_at) VALUES ('chn_1', 'wsp_1', 'channel', 'general', 'g1t', 'now')");
16 const insert = db.prepare(
17 "INSERT INTO messages (id, channel_id, author, kind, body, card, created_at) VALUES (?, 'chn_1', 'g1t', ?, '', ?, 'now')",
18 );
19 insert.run("msg_1", "card", JSON.stringify({ kind: "issue", title: "Header", detail: null, state: "Open", href: null }));
20 insert.run("msg_2", "card", JSON.stringify({ kind: "draft_issue", title: "Draft", detail: null, state: "Draft", href: null }));
21 insert.run("msg_3", "card", JSON.stringify({ kind: "pull", title: "Fix", detail: null, state: null, href: null }));
22 insert.run("msg_4", "text", null);
23 const sql = readFileSync(new URL(MIGRATION, dir), "utf8");
24 db.exec(sql);
25 db.exec(sql);
26 const kinds = db
27 .prepare("SELECT id, json_extract(card, '$.kind') AS kind, json_extract(card, '$.title') AS title FROM messages ORDER BY id")
28 .all();
29 assert.deepEqual(
30 kinds.map((row) => [row.id, row.kind, row.title]),
31 [
32 ["msg_1", "work_item", "Header"],
33 ["msg_2", "draft_work_item", "Draft"],
34 ["msg_3", "pull", "Fix"],
35 ["msg_4", null, null],
36 ],
37 );
38});