@@ -1146,6 +1146,46 @@ describe('GET /api/streak', () => {
11461146 expect ( body ) . toContain ( 'COMMITS THIS MONTH' ) ;
11471147 } ) ;
11481148
1149+ it ( 'automatically overrides or widens the query bounds to encompass the start of the previous month when view=monthly is requested with custom from/to params' , async ( ) => {
1150+ vi . useFakeTimers ( ) ;
1151+ vi . setSystemTime ( new Date ( '2026-06-02T12:00:00Z' ) ) ;
1152+
1153+ vi . mocked ( fetchGitHubContributions ) . mockResolvedValueOnce ( {
1154+ calendar : {
1155+ totalContributions : 25 ,
1156+ weeks : [
1157+ {
1158+ contributionDays : [
1159+ { date : '2026-05-01' , contributionCount : 0 } ,
1160+ { date : '2026-05-15' , contributionCount : 10 } ,
1161+ { date : '2026-06-01' , contributionCount : 15 } ,
1162+ { date : '2026-06-02' , contributionCount : 0 } ,
1163+ ] ,
1164+ } ,
1165+ ] ,
1166+ } as ContributionCalendar ,
1167+ repoContributions : [ ] ,
1168+ } as unknown as ExtendedContributionData ) ;
1169+
1170+ try {
1171+ const response = await GET (
1172+ makeRequest ( { user : 'octocat' , view : 'monthly' , from : '2026-06-01' , to : '2026-06-02' } )
1173+ ) ;
1174+
1175+ expect ( response . status ) . toBe ( 200 ) ;
1176+ // The expected prev month (May 2026) start is 2026-05-01.
1177+ // So 'from' should be widened to 2026-05-01T00:00:00Z.
1178+ // 'to' should be today's date in ISO: 2026-06-02T12:00:00.000Z.
1179+ expect ( fetchGitHubContributions ) . toHaveBeenCalledWith ( 'octocat' , {
1180+ bypassCache : false ,
1181+ from : '2026-05-01T00:00:00Z' ,
1182+ to : '2026-06-02T12:00:00.000Z' ,
1183+ } ) ;
1184+ } finally {
1185+ vi . useRealTimers ( ) ;
1186+ }
1187+ } ) ;
1188+
11491189 it ( 'uses the selected year when generating archived monthly stats' , async ( ) => {
11501190 vi . useFakeTimers ( ) ;
11511191 vi . setSystemTime ( new Date ( '2026-05-20T12:00:00Z' ) ) ;
@@ -1154,8 +1194,14 @@ describe('GET /api/streak', () => {
11541194 calendar : {
11551195 totalContributions : 25 ,
11561196 weeks : [
1157- { contributionDays : [ { date : '2024-11-15' , contributionCount : 10 } ] } ,
1158- { contributionDays : [ { date : '2024-12-15' , contributionCount : 15 } ] } ,
1197+ {
1198+ contributionDays : [
1199+ { date : '2024-11-01' , contributionCount : 0 } ,
1200+ { date : '2024-11-15' , contributionCount : 10 } ,
1201+ { date : '2024-12-15' , contributionCount : 15 } ,
1202+ { date : '2024-12-31' , contributionCount : 0 } ,
1203+ ] ,
1204+ } ,
11591205 ] ,
11601206 } as ContributionCalendar ,
11611207 repoContributions : [ ] ,
@@ -1248,8 +1294,14 @@ describe('GET /api/streak', () => {
12481294 calendar : {
12491295 totalContributions : 150 ,
12501296 weeks : [
1251- { contributionDays : [ { date : '2026-04-15' , contributionCount : 10 } ] } ,
1252- { contributionDays : [ { date : '2026-05-15' , contributionCount : 15 } ] } ,
1297+ {
1298+ contributionDays : [
1299+ { date : '2026-04-01' , contributionCount : 0 } ,
1300+ { date : '2026-04-15' , contributionCount : 10 } ,
1301+ { date : '2026-05-15' , contributionCount : 15 } ,
1302+ { date : '2026-05-20' , contributionCount : 0 } ,
1303+ ] ,
1304+ } ,
12531305 ] ,
12541306 } as ContributionCalendar ,
12551307 repoContributions : [ ] ,
@@ -1275,8 +1327,14 @@ describe('GET /api/streak', () => {
12751327 calendar : {
12761328 totalContributions : 150 ,
12771329 weeks : [
1278- { contributionDays : [ { date : '2026-04-15' , contributionCount : 10 } ] } ,
1279- { contributionDays : [ { date : '2026-05-15' , contributionCount : 15 } ] } ,
1330+ {
1331+ contributionDays : [
1332+ { date : '2026-04-01' , contributionCount : 0 } ,
1333+ { date : '2026-04-15' , contributionCount : 10 } ,
1334+ { date : '2026-05-15' , contributionCount : 15 } ,
1335+ { date : '2026-05-20' , contributionCount : 0 } ,
1336+ ] ,
1337+ } ,
12801338 ] ,
12811339 } as ContributionCalendar ,
12821340 repoContributions : [ ] ,
0 commit comments