1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
import { describe, it, expect } from "bun:test";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { countRowsToMap } from "../lib/issue-counts";
const REPO_A = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
const REPO_B = "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb";
describe("countRowsToMap", () => {
it("coerces bigint counts that arrive as strings", () => {
const map = countRowsToMap([
{ repositoryId: REPO_A, n: "3" },
{ repositoryId: REPO_B, n: "5" },
]);
expect(map.get(REPO_A)).toBe(3);
expect(map.get(REPO_B)).toBe(5);
});
it("produces totals that ADD rather than concatenate", () => {
const map = countRowsToMap([
{ repositoryId: REPO_A, n: "3" },
{ repositoryId: REPO_B, n: "5" },
]);
let total = 0;
for (const n of map.values()) total += n;
expect(total).toBe(8);
expect(total).not.toBe("35");
});
it("accepts counts that already arrive as numbers", () => {
const map = countRowsToMap([{ repositoryId: REPO_A, n: 7 }]);
expect(map.get(REPO_A)).toBe(7);
});
it("never yields NaN, which would poison a sum", () => {
const map = countRowsToMap([
{ repositoryId: REPO_A, n: null },
{ repositoryId: REPO_B, n: "not-a-number" },
]);
expect(map.get(REPO_A)).toBe(0);
expect(map.get(REPO_B)).toBe(0);
let total = 0;
for (const n of map.values()) total += n;
expect(Number.isNaN(total)).toBe(false);
expect(total).toBe(0);
});
it("skips rows with no repository", () => {
const map = countRowsToMap([{ repositoryId: null, n: "4" }]);
expect(map.size).toBe(0);
});
it("returns an empty map for no rows", () => {
expect(countRowsToMap([]).size).toBe(0);
});
});
function source(...rel: string[]): string {
const raw = readFileSync(join(import.meta.dir, "..", ...rel), "utf8");
const stripped = raw
.split("\n")
.filter((l) => !l.trim().startsWith("//") && !l.trim().startsWith("*"))
.join("\n");
expect(stripped.length).toBeGreaterThan(0);
return stripped;
}
describe("the dashboard shows computed open issues", () => {
const src = source("routes", "dashboard.tsx");
it("calls totalOpenIssues", () => {
expect(src).toContain("totalOpenIssues(");
});
it("no longer sums the stored counter into the stat card", () => {
expect(src).not.toContain("value={String(repos.reduce((s, r) => s + r.issueCount, 0))}");
});
it("still labels the card Open Issues, so the fix targets the right stat", () => {
expect(src).toContain('label="Open Issues"');
expect(src).toContain("value={String(openIssuesTotal)}");
});
});
describe("the REST repo listing serves computed open issues", () => {
const src = source("routes", "api.ts");
it("calls openIssueCountsByRepo", () => {
expect(src).toContain("openIssueCountsByRepo(");
});
it("overwrites issueCount on the serialized rows", () => {
expect(src).toContain("row.issueCount = counts.get(");
});
it("keeps serving the field when the count query fails", () => {
const at = src.indexOf("openIssueCountsByRepo(");
expect(at).toBeGreaterThan(-1);
const after = src.slice(at, at + 600);
expect(after.length).toBeGreaterThan(0);
expect(after).toContain("catch");
});
});
|