@@ -12,6 +12,8 @@ import {
1212} from '../../__mocks__/notifications-mocks' ;
1313import { mockSettings } from '../../__mocks__/state-mocks' ;
1414
15+ import { Constants } from '../../constants' ;
16+
1517import {
1618 type AccountNotifications ,
1719 type GitifyNotification ,
@@ -22,6 +24,7 @@ import {
2224} from '../../types' ;
2325
2426import * as logger from '../../utils/logger' ;
27+ import * as apiClient from '../api/client' ;
2528import {
2629 enrichNotification ,
2730 enrichNotifications ,
@@ -190,5 +193,68 @@ describe('renderer/utils/notifications/notifications.ts', () => {
190193
191194 expect ( result ) . toEqual ( [ ] ) ;
192195 } ) ;
196+
197+ it ( 'should batch notifications by GITHUB_API_MERGE_BATCH_SIZE' , async ( ) => {
198+ const fetchNotificationDetailsForListSpy = jest
199+ . spyOn ( apiClient , 'fetchNotificationDetailsForList' )
200+ . mockResolvedValue ( new Map ( ) ) ;
201+
202+ const notificationCount = Constants . GITHUB_API_MERGE_BATCH_SIZE * 2.5 ;
203+ const notifications = Array . from ( { length : notificationCount } , ( _ , i ) =>
204+ mockPartialGitifyNotification ( {
205+ title : `Notification ${ i } ` ,
206+ type : 'Issue' ,
207+ url : `https://api.github.com/repos/gitify-app/notifications-test/issues/${ i } ` as Link ,
208+ } ) ,
209+ ) as GitifyNotification [ ] ;
210+
211+ const settings : SettingsState = {
212+ ...mockSettings ,
213+ detailedNotifications : true ,
214+ } ;
215+
216+ await enrichNotifications ( notifications , settings ) ;
217+
218+ // Should be called 3 times: batches of 100, 100, 50
219+ expect ( fetchNotificationDetailsForListSpy ) . toHaveBeenCalledTimes ( 3 ) ;
220+
221+ // Verify batch sizes
222+ expect ( fetchNotificationDetailsForListSpy . mock . calls [ 0 ] [ 0 ] ) . toHaveLength (
223+ Constants . GITHUB_API_MERGE_BATCH_SIZE ,
224+ ) ;
225+ expect ( fetchNotificationDetailsForListSpy . mock . calls [ 1 ] [ 0 ] ) . toHaveLength (
226+ Constants . GITHUB_API_MERGE_BATCH_SIZE ,
227+ ) ;
228+ expect ( fetchNotificationDetailsForListSpy . mock . calls [ 2 ] [ 0 ] ) . toHaveLength (
229+ 50 ,
230+ ) ;
231+ } ) ;
232+
233+ it ( 'should handle single batch of notifications' , async ( ) => {
234+ const fetchNotificationDetailsForListSpy = jest
235+ . spyOn ( apiClient , 'fetchNotificationDetailsForList' )
236+ . mockResolvedValue ( new Map ( ) ) ;
237+
238+ const notifications = Array . from ( { length : 50 } , ( _ , i ) =>
239+ mockPartialGitifyNotification ( {
240+ title : `Notification ${ i } ` ,
241+ type : 'Issue' ,
242+ url : `https://api.github.com/repos/gitify-app/notifications-test/issues/${ i } ` as Link ,
243+ } ) ,
244+ ) as GitifyNotification [ ] ;
245+
246+ const settings : SettingsState = {
247+ ...mockSettings ,
248+ detailedNotifications : true ,
249+ } ;
250+
251+ await enrichNotifications ( notifications , settings ) ;
252+
253+ // Should be called once for single batch
254+ expect ( fetchNotificationDetailsForListSpy ) . toHaveBeenCalledTimes ( 1 ) ;
255+ expect ( fetchNotificationDetailsForListSpy . mock . calls [ 0 ] [ 0 ] ) . toHaveLength (
256+ 50 ,
257+ ) ;
258+ } ) ;
193259 } ) ;
194260} ) ;
0 commit comments