@@ -1337,4 +1337,54 @@ describe('GET /api/streak', () => {
13371337 expect ( body ) . toContain ( 'strictly for organizations' ) ;
13381338 } ) ;
13391339 } ) ;
1340+
1341+ describe ( 'JSON output mode (format=json)' , ( ) => {
1342+ it ( 'returns JSON with correct Content-Type when format=json is set' , async ( ) => {
1343+ const response = await GET ( makeRequest ( { user : 'octocat' , format : 'json' } ) ) ;
1344+ expect ( response . status ) . toBe ( 200 ) ;
1345+ expect ( response . headers . get ( 'Content-Type' ) ) . toContain ( 'application/json' ) ;
1346+ } ) ;
1347+
1348+ it ( 'returns stats, monthlyStats, and calendar in JSON response' , async ( ) => {
1349+ const response = await GET ( makeRequest ( { user : 'octocat' , format : 'json' } ) ) ;
1350+ const data = await response . json ( ) ;
1351+
1352+ expect ( data . user ) . toBe ( 'octocat' ) ;
1353+ expect ( data . stats ) . toBeDefined ( ) ;
1354+ expect ( data . stats . currentStreak ) . toBeDefined ( ) ;
1355+ expect ( data . stats . longestStreak ) . toBeDefined ( ) ;
1356+ expect ( data . stats . totalContributions ) . toBeDefined ( ) ;
1357+ expect ( data . monthlyStats ) . toBeDefined ( ) ;
1358+ expect ( data . monthlyStats . currentMonthTotal ) . toBeDefined ( ) ;
1359+ expect ( data . calendar ) . toBeDefined ( ) ;
1360+ expect ( data . calendar . totalContributions ) . toBe ( 10 ) ;
1361+ expect ( data . calendar . weeks ) . toHaveLength ( 2 ) ;
1362+ } ) ;
1363+
1364+ it ( 'includes Cache-Control header in JSON response' , async ( ) => {
1365+ const response = await GET ( makeRequest ( { user : 'octocat' , format : 'json' } ) ) ;
1366+ expect ( response . headers . get ( 'Cache-Control' ) ) . toContain ( 's-maxage=' ) ;
1367+ } ) ;
1368+
1369+ it ( 'includes X-Cache-Status header in JSON response' , async ( ) => {
1370+ const response = await GET ( makeRequest ( { user : 'octocat' , format : 'json' } ) ) ;
1371+ expect ( response . headers . get ( 'X-Cache-Status' ) ) . toBe ( 'HIT' ) ;
1372+ } ) ;
1373+
1374+ it ( 'returns SVG when format is not set (default)' , async ( ) => {
1375+ const response = await GET ( makeRequest ( { user : 'octocat' } ) ) ;
1376+ expect ( response . headers . get ( 'Content-Type' ) ) . toBe ( 'image/svg+xml' ) ;
1377+ } ) ;
1378+
1379+ it ( 'falls back to SVG for invalid format values' , async ( ) => {
1380+ const response = await GET ( makeRequest ( { user : 'octocat' , format : 'xml' } ) ) ;
1381+ expect ( response . headers . get ( 'Content-Type' ) ) . toBe ( 'image/svg+xml' ) ;
1382+ } ) ;
1383+
1384+ it ( 'uses org name as user field when org parameter is provided' , async ( ) => {
1385+ const response = await GET ( makeRequest ( { user : 'octocat' , org : 'github' , format : 'json' } ) ) ;
1386+ const data = await response . json ( ) ;
1387+ expect ( data . user ) . toBe ( 'github' ) ;
1388+ } ) ;
1389+ } ) ;
13401390} ) ;
0 commit comments