1- /**
2- * Unit tests for analytics output formatting functions.
3- *
4- * Tests the data transformation and output formatting for analytics data.
5- * These tests use fixture data and snapshot testing for markdown rendering.
6- *
7- * Test Coverage:
8- * - Repository data formatting (formatDataRepo)
9- * - Organization data formatting (formatDataOrg)
10- * - Markdown rendering (renderMarkdown)
11- * - Alert type aggregation (dynamicRequire, envVars, filesystemAccess, etc.)
12- * - Time series data formatting (critical, high, medium, low alerts)
13- * - Alert counts by severity level
14- * - Top 5 alert types ranking
15- *
16- * Testing Approach:
17- * - Load analytics-fixture.json for realistic test data
18- * - Use inline snapshots to verify formatting output
19- * - Test both org-level and repo-level data transformations
20- * - Verify markdown table generation with proper headers and formatting
21- *
22- * Related Files:
23- * - src/commands/analytics/output-analytics.mts - Implementation
24- * - src/commands/analytics/analytics-fixture.json - Test fixture data
25- * - src/commands/analytics/handle-analytics.mts - Handler that uses output functions
26- */
27-
281import { describe , expect , it } from 'vitest'
292
30- import FIXTURE from '../../../../src/commands/analytics/analytics-fixture.json' with {
31- type : 'json' ,
32- }
3+ import FIXTURE from './analytics-fixture.json' with { type : 'json' }
334import {
345 formatDataOrg ,
356 formatDataRepo ,
367 renderMarkdown ,
37- } from '../../../../src/commands/analytics /output-analytics.mts'
8+ } from './output-analytics.mts'
389
3910describe ( 'output-analytics' , ( ) => {
4011 describe ( 'format data' , ( ) => {
@@ -51,63 +22,75 @@ describe('output-analytics', () => {
5122 "unmaintained": 133,
5223 },
5324 "total_critical_added": {
54- "Apr 18 ": 0,
25+ "Apr 19 ": 0,
5526 "Apr 20": 0,
27+ "Apr 21": 0,
5628 "Apr 22": 0,
5729 },
5830 "total_critical_alerts": {
59- "Apr 18 ": 0,
31+ "Apr 19 ": 0,
6032 "Apr 20": 0,
33+ "Apr 21": 0,
6134 "Apr 22": 0,
6235 },
6336 "total_critical_prevented": {
64- "Apr 18 ": 0,
37+ "Apr 19 ": 0,
6538 "Apr 20": 0,
39+ "Apr 21": 0,
6640 "Apr 22": 0,
6741 },
6842 "total_high_added": {
69- "Apr 18 ": 0,
43+ "Apr 19 ": 0,
7044 "Apr 20": 0,
45+ "Apr 21": 0,
7146 "Apr 22": 0,
7247 },
7348 "total_high_alerts": {
74- "Apr 18 ": 13,
49+ "Apr 19 ": 13,
7550 "Apr 20": 13,
51+ "Apr 21": 13,
7652 "Apr 22": 10,
7753 },
7854 "total_high_prevented": {
79- "Apr 18 ": 0,
55+ "Apr 19 ": 0,
8056 "Apr 20": 0,
57+ "Apr 21": 0,
8158 "Apr 22": 0,
8259 },
8360 "total_low_added": {
84- "Apr 18 ": 0,
61+ "Apr 19 ": 0,
8562 "Apr 20": 0,
63+ "Apr 21": 0,
8664 "Apr 22": 0,
8765 },
8866 "total_low_alerts": {
89- "Apr 18 ": 1054,
67+ "Apr 19 ": 1054,
9068 "Apr 20": 1060,
69+ "Apr 21": 1066,
9170 "Apr 22": 1059,
9271 },
9372 "total_low_prevented": {
94- "Apr 18 ": 0,
73+ "Apr 19 ": 0,
9574 "Apr 20": 0,
75+ "Apr 21": 0,
9676 "Apr 22": 0,
9777 },
9878 "total_medium_added": {
99- "Apr 18 ": 0,
79+ "Apr 19 ": 0,
10080 "Apr 20": 0,
81+ "Apr 21": 0,
10182 "Apr 22": 0,
10283 },
10384 "total_medium_alerts": {
104- "Apr 18 ": 206,
85+ "Apr 19 ": 206,
10586 "Apr 20": 207,
87+ "Apr 21": 209,
10688 "Apr 22": 206,
10789 },
10890 "total_medium_prevented": {
109- "Apr 18 ": 0,
91+ "Apr 19 ": 0,
11092 "Apr 20": 0,
93+ "Apr 21": 0,
11194 "Apr 22": 0,
11295 },
11396 }
@@ -127,63 +110,75 @@ describe('output-analytics', () => {
127110 "unmaintained": 532,
128111 },
129112 "total_critical_added": {
130- "Apr 18 ": 0,
113+ "Apr 19 ": 0,
131114 "Apr 20": 0,
115+ "Apr 21": 0,
132116 "Apr 22": 0,
133117 },
134118 "total_critical_alerts": {
135- "Apr 18 ": 0,
119+ "Apr 19 ": 0,
136120 "Apr 20": 0,
121+ "Apr 21": 0,
137122 "Apr 22": 0,
138123 },
139124 "total_critical_prevented": {
140- "Apr 18 ": 0,
125+ "Apr 19 ": 0,
141126 "Apr 20": 0,
127+ "Apr 21": 0,
142128 "Apr 22": 0,
143129 },
144130 "total_high_added": {
145- "Apr 18 ": 0,
131+ "Apr 19 ": 0,
146132 "Apr 20": 0,
133+ "Apr 21": 0,
147134 "Apr 22": 0,
148135 },
149136 "total_high_alerts": {
150- "Apr 18": 13,
151- "Apr 20": 26,
137+ "Apr 19": 13,
138+ "Apr 20": 13,
139+ "Apr 21": 13,
152140 "Apr 22": 10,
153141 },
154142 "total_high_prevented": {
155- "Apr 18 ": 0,
143+ "Apr 19 ": 0,
156144 "Apr 20": 0,
145+ "Apr 21": 0,
157146 "Apr 22": 0,
158147 },
159148 "total_low_added": {
160- "Apr 18 ": 0,
149+ "Apr 19 ": 0,
161150 "Apr 20": 0,
151+ "Apr 21": 0,
162152 "Apr 22": 0,
163153 },
164154 "total_low_alerts": {
165- "Apr 18": 1054,
166- "Apr 20": 2126,
155+ "Apr 19": 1054,
156+ "Apr 20": 1060,
157+ "Apr 21": 1066,
167158 "Apr 22": 1059,
168159 },
169160 "total_low_prevented": {
170- "Apr 18 ": 0,
161+ "Apr 19 ": 0,
171162 "Apr 20": 0,
163+ "Apr 21": 0,
172164 "Apr 22": 0,
173165 },
174166 "total_medium_added": {
175- "Apr 18 ": 0,
167+ "Apr 19 ": 0,
176168 "Apr 20": 0,
169+ "Apr 21": 0,
177170 "Apr 22": 0,
178171 },
179172 "total_medium_alerts": {
180- "Apr 18": 206,
181- "Apr 20": 416,
173+ "Apr 19": 206,
174+ "Apr 20": 207,
175+ "Apr 21": 209,
182176 "Apr 22": 206,
183177 },
184178 "total_medium_prevented": {
185- "Apr 18 ": 0,
179+ "Apr 19 ": 0,
186180 "Apr 20": 0,
181+ "Apr 21": 0,
187182 "Apr 22": 0,
188183 },
189184 }
@@ -205,7 +200,8 @@ describe('output-analytics', () => {
205200
206201 | Date | Counts |
207202 | ------ | ------ |
208- | Apr 18 | 0 |
203+ | Apr 19 | 0 |
204+ | Apr 21 | 0 |
209205 | Apr 20 | 0 |
210206 | Apr 22 | 0 |
211207 | ------ | ------ |
@@ -214,7 +210,8 @@ describe('output-analytics', () => {
214210
215211 | Date | Counts |
216212 | ------ | ------ |
217- | Apr 18 | 13 |
213+ | Apr 19 | 13 |
214+ | Apr 21 | 13 |
218215 | Apr 20 | 13 |
219216 | Apr 22 | 10 |
220217 | ------ | ------ |
@@ -223,7 +220,8 @@ describe('output-analytics', () => {
223220
224221 | Date | Counts |
225222 | ------ | ------ |
226- | Apr 18 | 0 |
223+ | Apr 19 | 0 |
224+ | Apr 21 | 0 |
227225 | Apr 20 | 0 |
228226 | Apr 22 | 0 |
229227 | ------ | ------ |
@@ -232,7 +230,8 @@ describe('output-analytics', () => {
232230
233231 | Date | Counts |
234232 | ------ | ------ |
235- | Apr 18 | 0 |
233+ | Apr 19 | 0 |
234+ | Apr 21 | 0 |
236235 | Apr 20 | 0 |
237236 | Apr 22 | 0 |
238237 | ------ | ------ |
@@ -241,7 +240,8 @@ describe('output-analytics', () => {
241240
242241 | Date | Counts |
243242 | ------ | ------ |
244- | Apr 18 | 0 |
243+ | Apr 19 | 0 |
244+ | Apr 21 | 0 |
245245 | Apr 20 | 0 |
246246 | Apr 22 | 0 |
247247 | ------ | ------ |
@@ -250,7 +250,8 @@ describe('output-analytics', () => {
250250
251251 | Date | Counts |
252252 | ------ | ------ |
253- | Apr 18 | 0 |
253+ | Apr 19 | 0 |
254+ | Apr 21 | 0 |
254255 | Apr 20 | 0 |
255256 | Apr 22 | 0 |
256257 | ------ | ------ |
@@ -259,7 +260,8 @@ describe('output-analytics', () => {
259260
260261 | Date | Counts |
261262 | ------ | ------ |
262- | Apr 18 | 0 |
263+ | Apr 19 | 0 |
264+ | Apr 21 | 0 |
263265 | Apr 20 | 0 |
264266 | Apr 22 | 0 |
265267 | ------ | ------ |
@@ -268,7 +270,8 @@ describe('output-analytics', () => {
268270
269271 | Date | Counts |
270272 | ------ | ------ |
271- | Apr 18 | 0 |
273+ | Apr 19 | 0 |
274+ | Apr 21 | 0 |
272275 | Apr 20 | 0 |
273276 | Apr 22 | 0 |
274277 | ------ | ------ |
0 commit comments