@@ -61,6 +61,8 @@ describe('EventService', () => {
6161
6262 notificationsServiceMock = {
6363 createNotification : jest . fn ( ) . mockResolvedValue ( undefined ) ,
64+ getNotificationByUserId : jest . fn ( ) . mockResolvedValue ( undefined ) ,
65+ resolveNotification : jest . fn ( ) . mockResolvedValue ( undefined ) ,
6466 } ;
6567
6668 const module : TestingModule = await Test . createTestingModule ( {
@@ -171,15 +173,56 @@ describe('EventService', () => {
171173 } ) ;
172174
173175 describe ( 'approveEvent' , ( ) => {
174- it ( 'should approve an event' , async ( ) => {
175- eventModelMock . findByIdAndUpdate . mockResolvedValueOnce ( mockEvent ) ; // direct return
176- const result = await service . approveEvent ( mockEvent . _id . toString ( ) ) ;
176+ it ( 'should approve an event and resolve notification' , async ( ) => {
177+ const admin_id = 'admin_id' ;
178+ const message = 'event approved' ;
179+
180+ // Mock findByIdAndUpdate to resolve with updated event
181+ eventModelMock . findByIdAndUpdate = jest . fn ( ) . mockResolvedValue ( mockEvent ) ;
182+
183+ // Mock findById to return the same event
184+ eventModelMock . findById = jest . fn ( ) . mockResolvedValue ( mockEvent ) ;
185+
186+ // Mock notifications
187+ notificationsServiceMock . getNotificationByUserId = jest
188+ . fn ( )
189+ . mockResolvedValue ( { _id : 'notif_id' } ) ;
190+ notificationsServiceMock . resolveNotification = jest
191+ . fn ( )
192+ . mockResolvedValue ( undefined ) ;
193+
194+ const result = await service . approveEvent (
195+ mockEvent . _id . toString ( ) ,
196+ admin_id ,
197+ message ,
198+ ) ;
199+
177200 expect ( result ) . toEqual ( mockEvent ) ;
178201 expect ( eventModelMock . findByIdAndUpdate ) . toHaveBeenCalledWith (
179202 mockEvent . _id . toString ( ) ,
180203 { status : Status . APPROVED } ,
181204 { new : true } ,
182205 ) ;
206+ expect ( eventModelMock . findById ) . toHaveBeenCalledWith ( {
207+ _id : mockEvent . _id . toString ( ) ,
208+ } ) ;
209+ expect (
210+ notificationsServiceMock . getNotificationByUserId ,
211+ ) . toHaveBeenCalledWith ( mockEvent . host , mockEvent . _id . toString ( ) ) ;
212+ expect ( notificationsServiceMock . resolveNotification ) . toHaveBeenCalledWith (
213+ 'notif_id' ,
214+ admin_id ,
215+ message ,
216+ 'APPROVED' ,
217+ ) ;
218+ } ) ;
219+
220+ it ( 'should throw NotFoundException if event not found' , async ( ) => {
221+ eventModelMock . findByIdAndUpdate = jest . fn ( ) . mockResolvedValue ( null ) ;
222+
223+ await expect (
224+ service . approveEvent ( mockEvent . _id . toString ( ) , 'admin_id' ) ,
225+ ) . rejects . toThrow ( NotFoundException ) ;
183226 } ) ;
184227 } ) ;
185228} ) ;
0 commit comments