@@ -16,6 +16,7 @@ import {
1616 createCollectionDTO ,
1717 deleteCollectionViaApi
1818} from '../../testHelpers/collections/collectionHelper'
19+ import { NotificationSubset } from '../../../src/notifications/domain/models/NotificationSubset'
1920
2021describe ( 'NotificationsRepository' , ( ) => {
2122 const sut : NotificationsRepository = new NotificationsRepository ( )
@@ -36,12 +37,12 @@ describe('NotificationsRepository', () => {
3637 await publishDatasetViaApi ( testDatasetIds . numericId )
3738 await waitForNoLocks ( testDatasetIds . numericId , 10 )
3839
39- const notifications : Notification [ ] = await sut . getAllNotificationsByUser ( )
40+ const notificationSubset : NotificationSubset = await sut . getAllNotificationsByUser ( )
4041
41- expect ( Array . isArray ( notifications ) ) . toBe ( true )
42- expect ( notifications . length ) . toBeGreaterThan ( 0 )
42+ expect ( Array . isArray ( notificationSubset . notifications ) ) . toBe ( true )
43+ expect ( notificationSubset . notifications . length ) . toBeGreaterThan ( 0 )
4344
44- const publishedNotification = notifications . find (
45+ const publishedNotification = notificationSubset . notifications . find (
4546 ( n ) => n . type === NotificationType . PUBLISHEDDS
4647 ) as Notification
4748
@@ -62,14 +63,14 @@ describe('NotificationsRepository', () => {
6263 } )
6364
6465 test ( 'should delete a notification by ID' , async ( ) => {
65- const notifications : Notification [ ] = await sut . getAllNotificationsByUser ( )
66+ const notificationSubset : NotificationSubset = await sut . getAllNotificationsByUser ( )
6667
67- const notificationToDelete = notifications [ 0 ]
68+ const notificationToDelete = notificationSubset . notifications [ 0 ]
6869
6970 await sut . deleteNotification ( notificationToDelete . id )
7071
71- const notificationsAfterDelete : Notification [ ] = await sut . getAllNotificationsByUser ( )
72- const deletedNotification = notificationsAfterDelete . find (
72+ const notificationsAfterDelete : NotificationSubset = await sut . getAllNotificationsByUser ( )
73+ const deletedNotification = notificationsAfterDelete . notifications . find (
7374 ( n ) => n . id === notificationToDelete . id
7475 )
7576 expect ( deletedNotification ) . toBeUndefined ( )
@@ -86,27 +87,26 @@ describe('NotificationsRepository', () => {
8687 } )
8788
8889 test ( 'should return notifications with basic properties when inAppNotificationFormat is true' , async ( ) => {
89- const notifications : Notification [ ] = await sut . getAllNotificationsByUser ( true )
90+ const notificationSubset : NotificationSubset = await sut . getAllNotificationsByUser ( true )
9091
91- const notification = notifications [ 0 ]
92+ const notification = notificationSubset . notifications [ 0 ]
9293 expect ( notification ) . toHaveProperty ( 'id' )
9394 expect ( notification ) . toHaveProperty ( 'type' )
9495 expect ( notification ) . toHaveProperty ( 'sentTimestamp' )
9596 expect ( notification ) . toHaveProperty ( 'displayAsRead' )
9697 } )
9798
9899 test ( 'should find notification with ASSIGNROLE type that has not been deleted' , async ( ) => {
99- const notifications : Notification [ ] = await sut . getAllNotificationsByUser ( true )
100+ const notificationSubset : NotificationSubset = await sut . getAllNotificationsByUser ( true )
100101
101- const assignRoleNotification = notifications . find (
102+ const assignRoleNotification = notificationSubset . notifications . find (
102103 ( n ) => n . type === NotificationType . ASSIGNROLE && ! n . objectDeleted
103104 )
104105
105106 expect ( assignRoleNotification ) . toBeDefined ( )
106107 expect ( assignRoleNotification ?. type ) . toBe ( NotificationType . ASSIGNROLE )
107108 expect ( assignRoleNotification ?. sentTimestamp ) . toBeDefined ( )
108109 expect ( assignRoleNotification ?. displayAsRead ) . toBeDefined ( )
109- expect ( assignRoleNotification ?. collectionDisplayName ) . toBeDefined ( )
110110
111111 expect ( assignRoleNotification ?. roleAssignments ) . toBeDefined ( )
112112 expect ( assignRoleNotification ?. roleAssignments ?. length ) . toBeGreaterThan ( 0 )
@@ -125,11 +125,11 @@ describe('NotificationsRepository', () => {
125125 expect ( createdCollectionId ) . toBeDefined ( )
126126 expect ( createdCollectionId ) . toBeGreaterThan ( 0 )
127127
128- const notifications : Notification [ ] = await sut . getAllNotificationsByUser ( true )
129- expect ( Array . isArray ( notifications ) ) . toBe ( true )
130- expect ( notifications . length ) . toBeGreaterThan ( 0 )
128+ const notificationSubset : NotificationSubset = await sut . getAllNotificationsByUser ( true , true )
129+ expect ( Array . isArray ( notificationSubset . notifications ) ) . toBe ( true )
130+ expect ( notificationSubset . notifications . length ) . toBeGreaterThan ( 0 )
131131
132- const createdvNotification = notifications . find (
132+ const createdvNotification = notificationSubset . notifications . find (
133133 ( n ) => n . collectionAlias === testCollectionAlias
134134 )
135135
@@ -145,9 +145,9 @@ describe('NotificationsRepository', () => {
145145 } )
146146
147147 test ( 'should return array when inAppNotificationFormat is false' , async ( ) => {
148- const notifications : Notification [ ] = await sut . getAllNotificationsByUser ( false )
148+ const notificationSubset : NotificationSubset = await sut . getAllNotificationsByUser ( false )
149149
150- expect ( Array . isArray ( notifications ) ) . toBe ( true )
150+ expect ( Array . isArray ( notificationSubset . notifications ) ) . toBe ( true )
151151 } )
152152
153153 test ( 'should return unread count' , async ( ) => {
@@ -158,16 +158,18 @@ describe('NotificationsRepository', () => {
158158 } )
159159
160160 test ( 'should mark notification as read successfully' , async ( ) => {
161- const notifications : Notification [ ] = await sut . getAllNotificationsByUser ( )
161+ const notificationSubset : NotificationSubset = await sut . getAllNotificationsByUser ( )
162162
163- expect ( notifications . length ) . toBeGreaterThan ( 0 )
163+ expect ( notificationSubset . notifications . length ) . toBeGreaterThan ( 0 )
164164
165- const unreadNotification = notifications [ 0 ]
165+ const unreadNotification = notificationSubset . notifications [ 0 ]
166166
167167 await expect ( sut . markNotificationAsRead ( unreadNotification . id ) ) . resolves . toBeUndefined ( )
168168
169- const updatedNotifications : Notification [ ] = await sut . getAllNotificationsByUser ( )
170- const updatedNotification = updatedNotifications . find ( ( n ) => n . id === unreadNotification . id )
169+ const updatedNotificationSubset : NotificationSubset = await sut . getAllNotificationsByUser ( )
170+ const updatedNotification = updatedNotificationSubset . notifications . find (
171+ ( n ) => n . id === unreadNotification . id
172+ )
171173
172174 expect ( updatedNotification ?. displayAsRead ) . toBe ( true )
173175 } )
@@ -184,25 +186,40 @@ describe('NotificationsRepository', () => {
184186 )
185187 } )
186188 test ( 'should only return unread notifications when onlyUnread is true' , async ( ) => {
187- const notifications : Notification [ ] = await sut . getAllNotificationsByUser ( true , true )
189+ const notificationSubset : NotificationSubset = await sut . getAllNotificationsByUser ( true , true )
188190
189- expect ( Array . isArray ( notifications ) ) . toBe ( true )
190- const originalUnreadCount = notifications . length
191- expect ( notifications . length ) . toBeGreaterThanOrEqual ( 0 )
191+ expect ( Array . isArray ( notificationSubset . notifications ) ) . toBe ( true )
192+ const originalUnreadCount = notificationSubset . totalNotificationCount
193+ expect ( notificationSubset . notifications . length ) . toBeGreaterThanOrEqual ( 0 )
192194
193- await expect ( sut . markNotificationAsRead ( notifications [ 0 ] . id ) ) . resolves . toBeUndefined ( )
195+ await expect (
196+ sut . markNotificationAsRead ( notificationSubset . notifications [ 0 ] . id )
197+ ) . resolves . toBeUndefined ( )
194198
195- const updatedNotifications : Notification [ ] = await sut . getAllNotificationsByUser ( true , true )
196- expect ( updatedNotifications . length ) . toBe ( originalUnreadCount - 1 )
199+ const updatedNotifications : NotificationSubset = await sut . getAllNotificationsByUser (
200+ true ,
201+ true ,
202+ 10 ,
203+ 0
204+ )
205+ expect ( updatedNotifications . totalNotificationCount ) . toBe ( originalUnreadCount - 1 )
197206
198- const hasReadNotifications = notifications . some ( ( n ) => n . displayAsRead === true )
207+ const hasReadNotifications = notificationSubset . notifications . some (
208+ ( n ) => n . displayAsRead === true
209+ )
199210 expect ( hasReadNotifications ) . toBe ( false )
200211 } )
201212 test ( 'should return limited number of notifications when limit is set' , async ( ) => {
202213 const limit = 1
203- const notifications : Notification [ ] = await sut . getAllNotificationsByUser ( true , false , limit , 0 )
214+ const notificationSubset : NotificationSubset = await sut . getAllNotificationsByUser (
215+ true ,
216+ false ,
217+ limit ,
218+ 0
219+ )
204220
205- expect ( Array . isArray ( notifications ) ) . toBe ( true )
206- expect ( notifications . length ) . toBeLessThanOrEqual ( limit )
221+ expect ( Array . isArray ( notificationSubset . notifications ) ) . toBe ( true )
222+ expect ( notificationSubset . notifications . length ) . toBeLessThanOrEqual ( limit )
223+ expect ( notificationSubset . totalNotificationCount ) . toBeGreaterThanOrEqual ( limit )
207224 } )
208225} )
0 commit comments