aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/utils/users/user-notifications.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/utils/users/user-notifications.ts')
-rw-r--r--shared/utils/users/user-notifications.ts113
1 files changed, 107 insertions, 6 deletions
diff --git a/shared/utils/users/user-notifications.ts b/shared/utils/users/user-notifications.ts
index 75d52023a..1222899e7 100644
--- a/shared/utils/users/user-notifications.ts
+++ b/shared/utils/users/user-notifications.ts
@@ -98,9 +98,11 @@ async function checkNotification (
98 }) 98 })
99 99
100 if (checkType === 'presence') { 100 if (checkType === 'presence') {
101 expect(socketNotification, 'The socket notification is absent. ' + inspect(base.socketNotifications)).to.not.be.undefined 101 const obj = inspect(base.socketNotifications, { depth: 5 })
102 expect(socketNotification, 'The socket notification is absent. ' + obj).to.not.be.undefined
102 } else { 103 } else {
103 expect(socketNotification, 'The socket notification is present. ' + inspect(socketNotification)).to.be.undefined 104 const obj = inspect(socketNotification, { depth: 5 })
105 expect(socketNotification, 'The socket notification is present. ' + obj).to.be.undefined
104 } 106 }
105 } 107 }
106 108
@@ -131,10 +133,9 @@ function checkVideo (video: any, videoName?: string, videoUUID?: string) {
131 expect(video.id).to.be.a('number') 133 expect(video.id).to.be.a('number')
132} 134}
133 135
134function checkActor (channel: any) { 136function checkActor (actor: any) {
135 expect(channel.id).to.be.a('number') 137 expect(actor.displayName).to.be.a('string')
136 expect(channel.displayName).to.be.a('string') 138 expect(actor.displayName).to.not.be.empty
137 expect(channel.displayName).to.not.be.empty
138} 139}
139 140
140function checkComment (comment: any, commentId: number, threadId: number) { 141function checkComment (comment: any, commentId: number, threadId: number) {
@@ -220,6 +221,103 @@ async function checkMyVideoImportIsFinished (
220 await checkNotification(base, notificationChecker, emailFinder, type) 221 await checkNotification(base, notificationChecker, emailFinder, type)
221} 222}
222 223
224async function checkUserRegistered (base: CheckerBaseParams, username: string, type: CheckerType) {
225 const notificationType = UserNotificationType.NEW_USER_REGISTRATION
226
227 function notificationChecker (notification: UserNotification, type: CheckerType) {
228 if (type === 'presence') {
229 expect(notification).to.not.be.undefined
230 expect(notification.type).to.equal(notificationType)
231
232 checkActor(notification.account)
233 expect(notification.account.name).to.equal(username)
234 } else {
235 expect(notification).to.satisfy(n => n.type !== notificationType || n.account.name !== username)
236 }
237 }
238
239 function emailFinder (email: object) {
240 const text: string = email[ 'text' ]
241
242 return text.includes(' registered ') && text.includes(username)
243 }
244
245 await checkNotification(base, notificationChecker, emailFinder, type)
246}
247
248async function checkNewActorFollow (
249 base: CheckerBaseParams,
250 followType: 'channel' | 'account',
251 followerName: string,
252 followerDisplayName: string,
253 followingDisplayName: string,
254 type: CheckerType
255) {
256 const notificationType = UserNotificationType.NEW_FOLLOW
257
258 function notificationChecker (notification: UserNotification, type: CheckerType) {
259 if (type === 'presence') {
260 expect(notification).to.not.be.undefined
261 expect(notification.type).to.equal(notificationType)
262
263 checkActor(notification.actorFollow.follower)
264 expect(notification.actorFollow.follower.displayName).to.equal(followerDisplayName)
265 expect(notification.actorFollow.follower.name).to.equal(followerName)
266
267 checkActor(notification.actorFollow.following)
268 expect(notification.actorFollow.following.displayName).to.equal(followingDisplayName)
269 expect(notification.actorFollow.following.type).to.equal(followType)
270 } else {
271 expect(notification).to.satisfy(n => {
272 return n.type !== notificationType ||
273 (n.actorFollow.follower.name !== followerName && n.actorFollow.following !== followingDisplayName)
274 })
275 }
276 }
277
278 function emailFinder (email: object) {
279 const text: string = email[ 'text' ]
280
281 return text.includes('Your ' + followType) && text.includes(followingDisplayName) && text.includes(followerDisplayName)
282 }
283
284 await checkNotification(base, notificationChecker, emailFinder, type)
285}
286
287async function checkCommentMention (
288 base: CheckerBaseParams,
289 uuid: string,
290 commentId: number,
291 threadId: number,
292 byAccountDisplayName: string,
293 type: CheckerType
294) {
295 const notificationType = UserNotificationType.COMMENT_MENTION
296
297 function notificationChecker (notification: UserNotification, type: CheckerType) {
298 if (type === 'presence') {
299 expect(notification).to.not.be.undefined
300 expect(notification.type).to.equal(notificationType)
301
302 checkComment(notification.comment, commentId, threadId)
303 checkActor(notification.comment.account)
304 expect(notification.comment.account.displayName).to.equal(byAccountDisplayName)
305
306 checkVideo(notification.comment.video, undefined, uuid)
307 } else {
308 expect(notification).to.satisfy(n => n.type !== notificationType || n.comment.id !== commentId)
309 }
310 }
311
312 function emailFinder (email: object) {
313 const text: string = email[ 'text' ]
314
315 return text.includes(' mentioned ') && text.includes(uuid) && text.includes(byAccountDisplayName)
316 }
317
318 await checkNotification(base, notificationChecker, emailFinder, type)
319}
320
223let lastEmailCount = 0 321let lastEmailCount = 0
224async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string, commentId: number, threadId: number, type: CheckerType) { 322async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string, commentId: number, threadId: number, type: CheckerType) {
225 const notificationType = UserNotificationType.NEW_COMMENT_ON_MY_VIDEO 323 const notificationType = UserNotificationType.NEW_COMMENT_ON_MY_VIDEO
@@ -312,10 +410,13 @@ export {
312 CheckerType, 410 CheckerType,
313 checkNotification, 411 checkNotification,
314 checkMyVideoImportIsFinished, 412 checkMyVideoImportIsFinished,
413 checkUserRegistered,
315 checkVideoIsPublished, 414 checkVideoIsPublished,
316 checkNewVideoFromSubscription, 415 checkNewVideoFromSubscription,
416 checkNewActorFollow,
317 checkNewCommentOnMyVideo, 417 checkNewCommentOnMyVideo,
318 checkNewBlacklistOnMyVideo, 418 checkNewBlacklistOnMyVideo,
419 checkCommentMention,
319 updateMyNotificationSettings, 420 updateMyNotificationSettings,
320 checkNewVideoAbuseForModerators, 421 checkNewVideoAbuseForModerators,
321 getUserNotifications, 422 getUserNotifications,