Open History to see the last commit
1import { describe, expect, it } from "@effect/vitest";
2import * as Result from "effect/Result";
3
4import { decodeIssueNotesJson } from "./gitLabIssueJson.ts";
5
6describe("decodeIssueNotesJson", () => {
7 it.each([
8 [
9 "HTML partial addition",
10 '<p>changed title from <code class="idiff">Fix login</code> to <code class="idiff">Fix login<span class="idiff left right addition"> on Linux</span></code></p>',
11 "Fix login on Linux",
12 ],
13 [
14 "HTML several runs",
15 '<p>changed title from <code class="idiff"><span class="idiff left deletion">Old</span> title <span class="idiff right deletion">v1</span></code> to <code class="idiff"><span class="idiff left addition">New</span> title <span class="idiff right addition">v2</span></code></p>',
16 "New title v2",
17 ],
18 [
19 "HTML entities",
20 '<p>changed title from <code class="idiff">Fix</code> to <code class="idiff">Fix<span class="idiff left right addition"> "a" 'b' & <b> &lt;c&gt;</span></code></p>',
21 `Fix "a" 'b' & <b> <c>`,
22 ],
23 [
24 "HTML multiline title",
25 '<p>changed title from <code class="idiff">Fix\nlogin</code> to <code class="idiff">Fix\nlogin<span class="idiff left right addition">!</span></code></p>',
26 "Fix\nlogin!",
27 ],
28 [
29 "legacy partial addition",
30 "changed title from **Fix login** to **Fix login{+ on Linux+}**",
31 "Fix login on Linux",
32 ],
33 [
34 "legacy pure deletion",
35 "changed title from **Fix login{- bug-}** to **Fix login**",
36 "Fix login",
37 ],
38 [
39 "legacy several runs",
40 "changed title from **{-Old-} title {-v1-}** to **{+New+} title {+v2+}**",
41 "New title v2",
42 ],
43 [
44 "legacy title containing to",
45 "changed title from **Move A to B** to **Move A to {+C+}**",
46 "Move A to C",
47 ],
48 [
49 "legacy deleted run containing to",
50 "changed title from **{-A ** to ** B-}** to **{+New+}**",
51 "New",
52 ],
53 ["legacy new title with marker text", "changed title from **{-A-}** to **{+{-x-}+}**", "{-x-}"],
54 ["legacy malformed deletion runs", `changed title from **${"{-x-}".repeat(40)}**`, null],
55 ])("decodes a title change note (%s) into a renamed event", (_label, body, expected) => {
56 const decoded = decodeIssueNotesJson(
57 JSON.stringify([
58 {
59 id: 1,
60 body,
61 author: { username: "theo" },
62 created_at: "2026-07-03T00:00:00Z",
63 system: true,
64 },
65 ]),
66 );
67 expect(Result.isSuccess(decoded)).toBe(true);
68 if (!Result.isSuccess(decoded)) return;
69 expect(decoded.success.events.map((event) => [event.kind, event.detail])).toEqual([
70 ["renamed", expected],
71 ]);
72 });
73});