Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

gitLabIssueJson.test.ts

68 lines2.5 KB

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"> &quot;a&quot; &#39;b&#39; &amp; &lt;b&gt; &amp;lt;c&amp;gt;</span></code></p>',
21 `Fix "a" 'b' & <b> &lt;c&gt;`,
22 ],
23 [
24 "legacy partial addition",
25 "changed title from **Fix login** to **Fix login{+ on Linux+}**",
26 "Fix login on Linux",
27 ],
28 [
29 "legacy pure deletion",
30 "changed title from **Fix login{- bug-}** to **Fix login**",
31 "Fix login",
32 ],
33 [
34 "legacy several runs",
35 "changed title from **{-Old-} title {-v1-}** to **{+New+} title {+v2+}**",
36 "New title v2",
37 ],
38 [
39 "legacy title containing to",
40 "changed title from **Move A to B** to **Move A to {+C+}**",
41 "Move A to C",
42 ],
43 [
44 "legacy deleted run containing to",
45 "changed title from **{-A ** to ** B-}** to **{+New+}**",
46 "New",
47 ],
48 ["legacy new title with marker text", "changed title from **{-A-}** to **{+{-x-}+}**", "{-x-}"],
49 ["legacy malformed deletion runs", `changed title from **${"{-x-}".repeat(40)}**`, null],
50 ])("decodes a title change note (%s) into a renamed event", (_label, body, expected) => {
51 const decoded = decodeIssueNotesJson(
52 JSON.stringify([
53 {
54 id: 1,
55 body,
56 author: { username: "theo" },
57 created_at: "2026-07-03T00:00:00Z",
58 system: true,
59 },
60 ]),
61 );
62 expect(Result.isSuccess(decoded)).toBe(true);
63 if (!Result.isSuccess(decoded)) return;
64 expect(decoded.success.events.map((event) => [event.kind, event.detail])).toEqual([
65 ["renamed", expected],
66 ]);
67 });
68});