Repository navigation
Expand file tree
/
Copy pathreportDownloads.test.ts
More file actions
92 lines (82 loc) · 3.64 KB
/
Copy pathreportDownloads.test.ts
File metadata and controls
92 lines (82 loc) · 3.64 KB
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
import { describe, expect, it, vi } from "vitest";
import { buildReportCsvDownload, downloadReportCsv } from "./reportDownloads";
import { downloadTextFile } from "./downloads";
vi.mock("./downloads", async (importOriginal) => {
const actual = await importOriginal<typeof import("./downloads")>();
return {
...actual,
downloadTextFile: vi.fn(),
};
});
describe("reportDownloads", () => {
it("builds a Tag Health CSV download for Tag Report outputs", () => {
const download = buildReportCsvDownload({
reportId: "tag-report",
datasetName: "tags",
loadedAt: "2026-07-08T14:30:00.000Z",
source: "live-api",
periodRole: "current",
records: [
{
tagName: "python",
totalPageViews: 500,
tagWatchers: 20,
totalSmes: 0,
questionCount: 8,
articleCount: 4,
totalUniqueContributors: 12,
answerCount: 11,
questionsNoAnswers: 1,
medianFirstAnswerHours: 12,
},
],
});
expect(download.fileName).toBe("tag-report-tag-health-current-2026-07-08.csv");
expect(download.mimeType).toBe("text/csv;charset=utf-8");
expect(download.contents).toBe(
[
"tag_name,tag_id,tag_creation_date,last_used,health_status,page_views,question_count,article_count,unique_contributors,answer_count,sme_count,watcher_count,unanswered_questions,median_first_answer_hours,recommended_action,webhooks,communities,median_first_response_hours,unique_askers,unique_answerers,unique_commenters,unique_article_contributors,question_score,question_comments,questions_accepted_answer,questions_self_answered,sme_answers,answer_score,answer_comments,article_score,article_comments",
"python,,,,Needs SME coverage,500,8,4,12,11,0,20,1,12,Assign or confirm SMEs for this tag.,,,,,,,,,,,,,,,,",
].join("\n"),
);
});
it("uses comparison in the filename for comparison report output", () => {
const download = buildReportCsvDownload({
reportId: "tag-report",
datasetName: "tags",
loadedAt: "2026-07-08T14:30:00.000Z",
source: "upload",
periodRole: "comparison",
records: [],
});
expect(download.fileName).toBe("tag-report-tag-health-comparison-2026-07-08.csv");
});
it("keeps Tag Health headers for empty CSV downloads", () => {
const download = buildReportCsvDownload({
reportId: "tag-report",
datasetName: "tags",
loadedAt: "2026-07-08T14:30:00.000Z",
source: "upload",
periodRole: "current",
records: [],
});
expect(download.contents).toBe(
"tag_name,tag_id,tag_creation_date,last_used,health_status,page_views,question_count,article_count,unique_contributors,answer_count,sme_count,watcher_count,unanswered_questions,median_first_answer_hours,recommended_action,webhooks,communities,median_first_response_hours,unique_askers,unique_answerers,unique_commenters,unique_article_contributors,question_score,question_comments,questions_accepted_answer,questions_self_answered,sme_answers,answer_score,answer_comments,article_score,article_comments",
);
});
it("downloads report CSVs through the shared text download helper", () => {
downloadReportCsv({
reportId: "tag-report",
datasetName: "tags",
loadedAt: "2026-07-08T14:30:00.000Z",
source: "live-api",
periodRole: "current",
records: [{ tagName: "python", totalPageViews: 10 }],
});
expect(downloadTextFile).toHaveBeenCalledWith(
"tag-report-tag-health-current-2026-07-08.csv",
expect.stringContaining("tag_name,tag_id,tag_creation_date,last_used,health_status,page_views"),
"text/csv;charset=utf-8",
);
});
});