1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
10 flushAndRunMultipleServers,
14 getVideoCommentThreads,
15 getVideoThreadComments,
18 removeVideoFromBlacklist,
26 } from '../../../../shared/extra-utils'
27 import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
28 import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
29 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
30 import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io'
34 checkMyVideoImportIsFinished,
36 checkNewBlacklistOnMyVideo,
37 checkNewCommentOnMyVideo,
38 checkNewInstanceFollower,
39 checkNewVideoAbuseForModerators,
40 checkNewVideoFromSubscription,
42 checkVideoAutoBlacklistForModerators,
43 checkVideoIsPublished,
46 markAsReadAllNotifications,
47 markAsReadNotifications,
48 updateMyNotificationSettings
49 } from '../../../../shared/extra-utils/users/user-notifications'
53 UserNotificationSetting,
54 UserNotificationSettingValue,
56 } from '../../../../shared/models/users'
57 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
58 import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions'
59 import { VideoPrivacy } from '../../../../shared/models/videos'
60 import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
61 import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
62 import * as uuidv4 from 'uuid/v4'
63 import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/extra-utils/users/blocklist'
64 import { CustomConfig } from '../../../../shared/models/server'
65 import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
67 const expect = chai.expect
69 async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) {
70 const name = 'remote video ' + uuidv4()
72 const data = Object.assign({ name }, additionalParams)
73 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data)
75 await waitJobs(servers)
77 return { uuid: res.body.video.uuid, name }
80 async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) {
81 const name = 'local video ' + uuidv4()
83 const data = Object.assign({ name }, additionalParams)
84 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data)
86 await waitJobs(servers)
88 return { uuid: res.body.video.uuid, name }
91 describe('Test users notifications', function () {
92 let servers: ServerInfo[] = []
93 let userAccessToken: string
94 let userNotifications: UserNotification[] = []
95 let adminNotifications: UserNotification[] = []
96 let adminNotificationsServer2: UserNotification[] = []
97 const emails: object[] = []
100 const allNotificationSettings: UserNotificationSetting = {
101 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
102 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
103 videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
104 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
105 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
106 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
107 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
108 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
109 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
110 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
111 newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
114 before(async function () {
117 const port = await MockSmtpServer.Instance.collectEmails(emails)
119 const overrideConfig = {
121 hostname: 'localhost',
125 servers = await flushAndRunMultipleServers(3, overrideConfig)
127 // Get the access tokens
128 await setAccessTokensToServers(servers)
130 // Server 1 and server 2 follow each other
131 await doubleFollow(servers[0], servers[1])
133 await waitJobs(servers)
137 password: 'super password'
140 url: servers[ 0 ].url,
141 accessToken: servers[ 0 ].accessToken,
142 username: user.username,
143 password: user.password,
144 videoQuota: 10 * 1000 * 1000
146 userAccessToken = await userLogin(servers[0], user)
148 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
149 await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
150 await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
153 const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
154 socket.on('new-notification', n => userNotifications.push(n))
157 const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
158 socket.on('new-notification', n => adminNotifications.push(n))
161 const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
162 socket.on('new-notification', n => adminNotificationsServer2.push(n))
166 const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
167 channelId = resChannel.body.videoChannels[0].id
171 describe('New video from my subscription notification', function () {
172 let baseParams: CheckerBaseParams
178 socketNotifications: userNotifications,
179 token: userAccessToken
183 it('Should not send notifications if the user does not follow the video publisher', async function () {
186 await uploadVideoByLocalAccount(servers)
188 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
189 expect(notification).to.be.undefined
191 expect(emails).to.have.lengthOf(0)
192 expect(userNotifications).to.have.lengthOf(0)
195 it('Should send a new video notification if the user follows the local video publisher', async function () {
198 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port)
199 await waitJobs(servers)
201 const { name, uuid } = await uploadVideoByLocalAccount(servers)
202 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
205 it('Should send a new video notification from a remote account', async function () {
206 this.timeout(50000) // Server 2 has transcoding enabled
208 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[1].port)
209 await waitJobs(servers)
211 const { name, uuid } = await uploadVideoByRemoteAccount(servers)
212 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
215 it('Should send a new video notification on a scheduled publication', async function () {
219 let updateAt = new Date(new Date().getTime() + 2000)
222 privacy: VideoPrivacy.PRIVATE,
224 updateAt: updateAt.toISOString(),
225 privacy: VideoPrivacy.PUBLIC
228 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
231 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
234 it('Should send a new video notification on a remote scheduled publication', async function () {
238 let updateAt = new Date(new Date().getTime() + 2000)
241 privacy: VideoPrivacy.PRIVATE,
243 updateAt: updateAt.toISOString(),
244 privacy: VideoPrivacy.PUBLIC
247 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
248 await waitJobs(servers)
251 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
254 it('Should not send a notification before the video is published', async function () {
257 let updateAt = new Date(new Date().getTime() + 1000000)
260 privacy: VideoPrivacy.PRIVATE,
262 updateAt: updateAt.toISOString(),
263 privacy: VideoPrivacy.PUBLIC
266 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
269 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
272 it('Should send a new video notification when a video becomes public', async function () {
275 const data = { privacy: VideoPrivacy.PRIVATE }
276 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
278 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
280 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
283 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
286 it('Should send a new video notification when a remote video becomes public', async function () {
289 const data = { privacy: VideoPrivacy.PRIVATE }
290 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
292 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
294 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
296 await waitJobs(servers)
297 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
300 it('Should not send a new video notification when a video becomes unlisted', async function () {
303 const data = { privacy: VideoPrivacy.PRIVATE }
304 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
306 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
308 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
311 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
314 const data = { privacy: VideoPrivacy.PRIVATE }
315 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
317 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
319 await waitJobs(servers)
320 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
323 it('Should send a new video notification after a video import', async function () {
326 const name = 'video import ' + uuidv4()
331 privacy: VideoPrivacy.PUBLIC,
332 targetUrl: getYoutubeVideoUrl()
334 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
335 const uuid = res.body.video.uuid
337 await waitJobs(servers)
339 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
343 describe('Comment on my video notifications', function () {
344 let baseParams: CheckerBaseParams
350 socketNotifications: userNotifications,
351 token: userAccessToken
355 it('Should not send a new comment notification after a comment on another video', async function () {
358 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
359 const uuid = resVideo.body.video.uuid
361 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
362 const commentId = resComment.body.comment.id
365 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
368 it('Should not send a new comment notification if I comment my own video', async function () {
371 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
372 const uuid = resVideo.body.video.uuid
374 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
375 const commentId = resComment.body.comment.id
378 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
381 it('Should not send a new comment notification if the account is muted', async function () {
384 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
386 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
387 const uuid = resVideo.body.video.uuid
389 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
390 const commentId = resComment.body.comment.id
393 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
395 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
398 it('Should send a new comment notification after a local comment on my video', async function () {
401 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
402 const uuid = resVideo.body.video.uuid
404 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
405 const commentId = resComment.body.comment.id
408 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
411 it('Should send a new comment notification after a remote comment on my video', async function () {
414 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
415 const uuid = resVideo.body.video.uuid
417 await waitJobs(servers)
419 await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
421 await waitJobs(servers)
423 const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
424 expect(resComment.body.data).to.have.lengthOf(1)
425 const commentId = resComment.body.data[0].id
427 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
430 it('Should send a new comment notification after a local reply on my video', async function () {
433 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
434 const uuid = resVideo.body.video.uuid
436 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
437 const threadId = resThread.body.comment.id
439 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
440 const commentId = resComment.body.comment.id
443 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
446 it('Should send a new comment notification after a remote reply on my video', async function () {
449 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
450 const uuid = resVideo.body.video.uuid
451 await waitJobs(servers)
454 const resThread = await addVideoCommentThread(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, 'comment')
455 const threadId = resThread.body.comment.id
456 await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, threadId, 'reply')
459 await waitJobs(servers)
461 const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
462 expect(resThread.body.data).to.have.lengthOf(1)
463 const threadId = resThread.body.data[0].id
465 const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
466 const tree = resComments.body as VideoCommentThreadTree
468 expect(tree.children).to.have.lengthOf(1)
469 const commentId = tree.children[0].comment.id
471 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
475 describe('Mention notifications', function () {
476 let baseParams: CheckerBaseParams
482 socketNotifications: userNotifications,
483 token: userAccessToken
488 accessToken: servers[0].accessToken,
489 displayName: 'super root name'
494 accessToken: servers[1].accessToken,
495 displayName: 'super root 2 name'
499 it('Should not send a new mention comment notification if I mention the video owner', async function () {
502 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
503 const uuid = resVideo.body.video.uuid
505 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
506 const commentId = resComment.body.comment.id
509 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
512 it('Should not send a new mention comment notification if I mention myself', async function () {
515 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
516 const uuid = resVideo.body.video.uuid
518 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
519 const commentId = resComment.body.comment.id
522 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
525 it('Should not send a new mention notification if the account is muted', async function () {
528 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
530 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
531 const uuid = resVideo.body.video.uuid
533 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
534 const commentId = resComment.body.comment.id
537 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
539 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
542 it('Should not send a new mention notification if the remote account mention a local account', async function () {
545 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
546 const uuid = resVideo.body.video.uuid
548 await waitJobs(servers)
549 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
550 const threadId = resThread.body.comment.id
552 await waitJobs(servers)
553 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
556 it('Should send a new mention notification after local comments', async function () {
559 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
560 const uuid = resVideo.body.video.uuid
562 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
563 const threadId = resThread.body.comment.id
566 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
568 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
569 const commentId = resComment.body.comment.id
572 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
575 it('Should send a new mention notification after remote comments', async function () {
578 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
579 const uuid = resVideo.body.video.uuid
581 await waitJobs(servers)
583 const text1 = `hello @user_1@localhost:${servers[ 0 ].port} 1`
584 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, text1)
585 const server2ThreadId = resThread.body.comment.id
587 await waitJobs(servers)
589 const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
590 expect(resThread2.body.data).to.have.lengthOf(1)
591 const server1ThreadId = resThread2.body.data[0].id
592 await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
594 const text2 = `@user_1@localhost:${servers[ 0 ].port} hello 2 @root@localhost:${servers[ 0 ].port}`
595 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text2)
597 await waitJobs(servers)
599 const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
600 const tree = resComments.body as VideoCommentThreadTree
602 expect(tree.children).to.have.lengthOf(1)
603 const commentId = tree.children[0].comment.id
605 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
609 describe('Video abuse for moderators notification' , function () {
610 let baseParams: CheckerBaseParams
616 socketNotifications: adminNotifications,
617 token: servers[0].accessToken
621 it('Should send a notification to moderators on local video abuse', async function () {
624 const name = 'video for abuse ' + uuidv4()
625 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
626 const uuid = resVideo.body.video.uuid
628 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
630 await waitJobs(servers)
631 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
634 it('Should send a notification to moderators on remote video abuse', async function () {
637 const name = 'video for abuse ' + uuidv4()
638 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
639 const uuid = resVideo.body.video.uuid
641 await waitJobs(servers)
643 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
645 await waitJobs(servers)
646 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
650 describe('Video blacklist on my video', function () {
651 let baseParams: CheckerBaseParams
657 socketNotifications: userNotifications,
658 token: userAccessToken
662 it('Should send a notification to video owner on blacklist', async function () {
665 const name = 'video for abuse ' + uuidv4()
666 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
667 const uuid = resVideo.body.video.uuid
669 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
671 await waitJobs(servers)
672 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
675 it('Should send a notification to video owner on unblacklist', async function () {
678 const name = 'video for abuse ' + uuidv4()
679 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
680 const uuid = resVideo.body.video.uuid
682 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
684 await waitJobs(servers)
685 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
686 await waitJobs(servers)
689 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
693 describe('My video is published', function () {
694 let baseParams: CheckerBaseParams
700 socketNotifications: adminNotificationsServer2,
701 token: servers[1].accessToken
705 it('Should not send a notification if transcoding is not enabled', async function () {
708 const { name, uuid } = await uploadVideoByLocalAccount(servers)
709 await waitJobs(servers)
711 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
714 it('Should not send a notification if the wait transcoding is false', async function () {
717 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
718 await waitJobs(servers)
720 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
722 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
726 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
729 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
730 await waitJobs(servers)
732 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
735 it('Should send a notification with a transcoded video', async function () {
738 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
739 await waitJobs(servers)
741 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
744 it('Should send a notification when an imported video is transcoded', async function () {
747 const name = 'video import ' + uuidv4()
752 privacy: VideoPrivacy.PUBLIC,
753 targetUrl: getYoutubeVideoUrl(),
754 waitTranscoding: true
756 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
757 const uuid = res.body.video.uuid
759 await waitJobs(servers)
760 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
763 it('Should send a notification when the scheduled update has been proceeded', async function () {
767 let updateAt = new Date(new Date().getTime() + 2000)
770 privacy: VideoPrivacy.PRIVATE,
772 updateAt: updateAt.toISOString(),
773 privacy: VideoPrivacy.PUBLIC
776 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
779 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
782 it('Should not send a notification before the video is published', async function () {
785 let updateAt = new Date(new Date().getTime() + 1000000)
788 privacy: VideoPrivacy.PRIVATE,
790 updateAt: updateAt.toISOString(),
791 privacy: VideoPrivacy.PUBLIC
794 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
797 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
801 describe('My video is imported', function () {
802 let baseParams: CheckerBaseParams
808 socketNotifications: adminNotifications,
809 token: servers[0].accessToken
813 it('Should send a notification when the video import failed', async function () {
816 const name = 'video import ' + uuidv4()
821 privacy: VideoPrivacy.PRIVATE,
822 targetUrl: getBadVideoUrl()
824 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
825 const uuid = res.body.video.uuid
827 await waitJobs(servers)
828 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
831 it('Should send a notification when the video import succeeded', async function () {
834 const name = 'video import ' + uuidv4()
839 privacy: VideoPrivacy.PRIVATE,
840 targetUrl: getYoutubeVideoUrl()
842 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
843 const uuid = res.body.video.uuid
845 await waitJobs(servers)
846 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
850 describe('New registration', function () {
851 let baseParams: CheckerBaseParams
857 socketNotifications: adminNotifications,
858 token: servers[0].accessToken
862 it('Should send a notification only to moderators when a user registers on the instance', async function () {
865 await registerUser(servers[0].url, 'user_45', 'password')
867 await waitJobs(servers)
869 await checkUserRegistered(baseParams, 'user_45', 'presence')
871 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
872 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
876 describe('New instance follower', function () {
877 let baseParams: CheckerBaseParams
883 socketNotifications: adminNotifications,
884 token: servers[0].accessToken
888 it('Should send a notification only to admin when there is a new instance follower', async function () {
891 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
893 await waitJobs(servers)
895 await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence')
897 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
898 await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence')
902 describe('New actor follow', function () {
903 let baseParams: CheckerBaseParams
904 let myChannelName = 'super channel name'
905 let myUserName = 'super user name'
911 socketNotifications: userNotifications,
912 token: userAccessToken
917 accessToken: servers[0].accessToken,
918 displayName: 'super root name'
923 accessToken: userAccessToken,
924 displayName: myUserName
929 accessToken: servers[1].accessToken,
930 displayName: 'super root 2 name'
933 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
936 it('Should notify when a local channel is following one of our channel', async function () {
939 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
940 await waitJobs(servers)
942 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
944 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
947 it('Should notify when a remote channel is following one of our channel', async function () {
950 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
951 await waitJobs(servers)
953 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
955 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
958 it('Should notify when a local account is following one of our channel', async function () {
961 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port)
963 await waitJobs(servers)
965 await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
968 it('Should notify when a remote account is following one of our channel', async function () {
971 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port)
973 await waitJobs(servers)
975 await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
979 describe('Video-related notifications when video auto-blacklist is enabled', function () {
980 let userBaseParams: CheckerBaseParams
981 let adminBaseParamsServer1: CheckerBaseParams
982 let adminBaseParamsServer2: CheckerBaseParams
983 let videoUUID: string
984 let videoName: string
985 let currentCustomConfig: CustomConfig
989 adminBaseParamsServer1 = {
992 socketNotifications: adminNotifications,
993 token: servers[0].accessToken
996 adminBaseParamsServer2 = {
999 socketNotifications: adminNotificationsServer2,
1000 token: servers[1].accessToken
1006 socketNotifications: userNotifications,
1007 token: userAccessToken
1010 const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken)
1011 currentCustomConfig = resCustomConfig.body
1012 const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, {
1021 // enable transcoding otherwise own publish notification after transcoding not expected
1022 autoBlacklistTestsCustomConfig.transcoding.enabled = true
1023 await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig)
1025 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
1026 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
1030 it('Should send notification to moderators on new video with auto-blacklist', async function () {
1033 videoName = 'video with auto-blacklist ' + uuidv4()
1034 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
1035 videoUUID = resVideo.body.video.uuid
1037 await waitJobs(servers)
1038 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
1041 it('Should not send video publish notification if auto-blacklisted', async function () {
1042 await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence')
1045 it('Should not send a local user subscription notification if auto-blacklisted', async function () {
1046 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence')
1049 it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
1050 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence')
1053 it('Should send video published and unblacklist after video unblacklisted', async function () {
1056 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID)
1058 await waitJobs(servers)
1060 // FIXME: Can't test as two notifications sent to same user and util only checks last one
1061 // One notification might be better anyways
1062 // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist')
1063 // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence')
1066 it('Should send a local user subscription notification after removed from blacklist', async function () {
1067 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence')
1070 it('Should send a remote user subscription notification after removed from blacklist', async function () {
1071 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence')
1074 it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
1077 let updateAt = new Date(new Date().getTime() + 1000000)
1079 const name = 'video with auto-blacklist and future schedule ' + uuidv4()
1083 privacy: VideoPrivacy.PRIVATE,
1085 updateAt: updateAt.toISOString(),
1086 privacy: VideoPrivacy.PUBLIC
1090 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1091 const uuid = resVideo.body.video.uuid
1093 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
1095 await waitJobs(servers)
1096 await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
1098 // FIXME: Can't test absence as two notifications sent to same user and util only checks last one
1099 // One notification might be better anyways
1100 // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1102 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1103 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1106 it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
1110 let updateAt = new Date(new Date().getTime() + 2000)
1112 const name = 'video with schedule done and still auto-blacklisted ' + uuidv4()
1116 privacy: VideoPrivacy.PRIVATE,
1118 updateAt: updateAt.toISOString(),
1119 privacy: VideoPrivacy.PUBLIC
1123 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1124 const uuid = resVideo.body.video.uuid
1127 await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1128 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1129 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1132 it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
1135 const name = 'video without auto-blacklist ' + uuidv4()
1137 // admin with blacklist right will not be auto-blacklisted
1138 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name })
1139 const uuid = resVideo.body.video.uuid
1141 await waitJobs(servers)
1142 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
1146 await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig)
1148 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
1149 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
1153 describe('Mark as read', function () {
1154 it('Should mark as read some notifications', async function () {
1155 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
1156 const ids = res.body.data.map(n => n.id)
1158 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
1161 it('Should have the notifications marked as read', async function () {
1162 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
1164 const notifications = res.body.data as UserNotification[]
1165 expect(notifications[ 0 ].read).to.be.false
1166 expect(notifications[ 1 ].read).to.be.false
1167 expect(notifications[ 2 ].read).to.be.true
1168 expect(notifications[ 3 ].read).to.be.true
1169 expect(notifications[ 4 ].read).to.be.true
1170 expect(notifications[ 5 ].read).to.be.false
1173 it('Should only list read notifications', async function () {
1174 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
1176 const notifications = res.body.data as UserNotification[]
1177 for (const notification of notifications) {
1178 expect(notification.read).to.be.true
1182 it('Should only list unread notifications', async function () {
1183 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1185 const notifications = res.body.data as UserNotification[]
1186 for (const notification of notifications) {
1187 expect(notification.read).to.be.false
1191 it('Should mark as read all notifications', async function () {
1192 await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
1194 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1196 expect(res.body.total).to.equal(0)
1197 expect(res.body.data).to.have.lengthOf(0)
1201 describe('Notification settings', function () {
1202 let baseParams: CheckerBaseParams
1208 socketNotifications: userNotifications,
1209 token: userAccessToken
1213 it('Should not have notifications', async function () {
1216 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1217 newVideoFromSubscription: UserNotificationSettingValue.NONE
1221 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1222 const info = res.body as User
1223 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
1226 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1228 const check = { web: true, mail: true }
1229 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1232 it('Should only have web notifications', async function () {
1235 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1236 newVideoFromSubscription: UserNotificationSettingValue.WEB
1240 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1241 const info = res.body as User
1242 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
1245 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1248 const check = { mail: true, web: false }
1249 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1253 const check = { mail: false, web: true }
1254 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1258 it('Should only have mail notifications', async function () {
1261 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1262 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
1266 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1267 const info = res.body as User
1268 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
1271 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1274 const check = { mail: false, web: true }
1275 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1279 const check = { mail: true, web: false }
1280 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1284 it('Should have email and web notifications', async function () {
1287 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1288 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1292 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1293 const info = res.body as User
1294 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
1295 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1299 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1301 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
1305 after(async function () {
1306 MockSmtpServer.Instance.kill()
1308 await cleanupTests(servers)