1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
9 flushAndRunMultipleServers,
14 removeVideoFromBlacklist,
22 updateCustomConfig, getVideoThreadComments, getVideoCommentThreads, follow
23 } from '../../../../shared/utils'
24 import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index'
25 import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
26 import { waitJobs } from '../../../../shared/utils/server/jobs'
27 import { getUserNotificationSocket } from '../../../../shared/utils/socket/socket-io'
31 checkMyVideoImportIsFinished,
33 checkNewBlacklistOnMyVideo,
34 checkNewCommentOnMyVideo,
35 checkNewVideoAbuseForModerators,
36 checkVideoAutoBlacklistForModerators,
37 checkNewVideoFromSubscription,
39 checkVideoIsPublished,
42 markAsReadNotifications,
43 updateMyNotificationSettings,
44 markAsReadAllNotifications, checkNewInstanceFollower
45 } from '../../../../shared/utils/users/user-notifications'
49 UserNotificationSetting,
50 UserNotificationSettingValue,
52 } from '../../../../shared/models/users'
53 import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
54 import { addUserSubscription, removeUserSubscription } from '../../../../shared/utils/users/user-subscriptions'
55 import { VideoPrivacy } from '../../../../shared/models/videos'
56 import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports'
57 import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments'
58 import * as uuidv4 from 'uuid/v4'
59 import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist'
60 import { CustomConfig } from '../../../../shared/models/server'
61 import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
63 const expect = chai.expect
65 async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) {
66 const name = 'remote video ' + uuidv4()
68 const data = Object.assign({ name }, additionalParams)
69 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data)
71 await waitJobs(servers)
73 return { uuid: res.body.video.uuid, name }
76 async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) {
77 const name = 'local video ' + uuidv4()
79 const data = Object.assign({ name }, additionalParams)
80 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data)
82 await waitJobs(servers)
84 return { uuid: res.body.video.uuid, name }
87 describe('Test users notifications', function () {
88 let servers: ServerInfo[] = []
89 let userAccessToken: string
90 let userNotifications: UserNotification[] = []
91 let adminNotifications: UserNotification[] = []
92 let adminNotificationsServer2: UserNotification[] = []
93 const emails: object[] = []
96 const allNotificationSettings: UserNotificationSetting = {
97 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
98 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
99 videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
100 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
101 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
102 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
103 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
104 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
105 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
106 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
107 newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
110 before(async function () {
113 await MockSmtpServer.Instance.collectEmails(emails)
117 const overrideConfig = {
119 hostname: 'localhost'
122 servers = await flushAndRunMultipleServers(3, overrideConfig)
124 // Get the access tokens
125 await setAccessTokensToServers(servers)
127 // Server 1 and server 2 follow each other
128 await doubleFollow(servers[0], servers[1])
130 await waitJobs(servers)
134 password: 'super password'
136 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000)
137 userAccessToken = await userLogin(servers[0], user)
139 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
140 await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
141 await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
144 const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
145 socket.on('new-notification', n => userNotifications.push(n))
148 const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
149 socket.on('new-notification', n => adminNotifications.push(n))
152 const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
153 socket.on('new-notification', n => adminNotificationsServer2.push(n))
157 const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
158 channelId = resChannel.body.videoChannels[0].id
162 describe('New video from my subscription notification', function () {
163 let baseParams: CheckerBaseParams
169 socketNotifications: userNotifications,
170 token: userAccessToken
174 it('Should not send notifications if the user does not follow the video publisher', async function () {
177 await uploadVideoByLocalAccount(servers)
179 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
180 expect(notification).to.be.undefined
182 expect(emails).to.have.lengthOf(0)
183 expect(userNotifications).to.have.lengthOf(0)
186 it('Should send a new video notification if the user follows the local video publisher', async function () {
189 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
190 await waitJobs(servers)
192 const { name, uuid } = await uploadVideoByLocalAccount(servers)
193 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
196 it('Should send a new video notification from a remote account', async function () {
197 this.timeout(50000) // Server 2 has transcoding enabled
199 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002')
200 await waitJobs(servers)
202 const { name, uuid } = await uploadVideoByRemoteAccount(servers)
203 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
206 it('Should send a new video notification on a scheduled publication', async function () {
210 let updateAt = new Date(new Date().getTime() + 2000)
213 privacy: VideoPrivacy.PRIVATE,
215 updateAt: updateAt.toISOString(),
216 privacy: VideoPrivacy.PUBLIC
219 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
222 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
225 it('Should send a new video notification on a remote scheduled publication', async function () {
229 let updateAt = new Date(new Date().getTime() + 2000)
232 privacy: VideoPrivacy.PRIVATE,
234 updateAt: updateAt.toISOString(),
235 privacy: VideoPrivacy.PUBLIC
238 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
239 await waitJobs(servers)
242 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
245 it('Should not send a notification before the video is published', async function () {
248 let updateAt = new Date(new Date().getTime() + 1000000)
251 privacy: VideoPrivacy.PRIVATE,
253 updateAt: updateAt.toISOString(),
254 privacy: VideoPrivacy.PUBLIC
257 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
260 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
263 it('Should send a new video notification when a video becomes public', async function () {
266 const data = { privacy: VideoPrivacy.PRIVATE }
267 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
269 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
271 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
274 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
277 it('Should send a new video notification when a remote video becomes public', async function () {
280 const data = { privacy: VideoPrivacy.PRIVATE }
281 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
283 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
285 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
287 await waitJobs(servers)
288 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
291 it('Should not send a new video notification when a video becomes unlisted', async function () {
294 const data = { privacy: VideoPrivacy.PRIVATE }
295 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
297 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
299 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
302 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
305 const data = { privacy: VideoPrivacy.PRIVATE }
306 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
308 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
310 await waitJobs(servers)
311 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
314 it('Should send a new video notification after a video import', async function () {
317 const name = 'video import ' + uuidv4()
322 privacy: VideoPrivacy.PUBLIC,
323 targetUrl: getYoutubeVideoUrl()
325 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
326 const uuid = res.body.video.uuid
328 await waitJobs(servers)
330 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
334 describe('Comment on my video notifications', function () {
335 let baseParams: CheckerBaseParams
341 socketNotifications: userNotifications,
342 token: userAccessToken
346 it('Should not send a new comment notification after a comment on another video', async function () {
349 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
350 const uuid = resVideo.body.video.uuid
352 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
353 const commentId = resComment.body.comment.id
356 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
359 it('Should not send a new comment notification if I comment my own video', async function () {
362 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
363 const uuid = resVideo.body.video.uuid
365 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
366 const commentId = resComment.body.comment.id
369 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
372 it('Should not send a new comment notification if the account is muted', async function () {
375 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
377 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
378 const uuid = resVideo.body.video.uuid
380 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
381 const commentId = resComment.body.comment.id
384 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
386 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
389 it('Should send a new comment notification after a local comment on my video', async function () {
392 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
393 const uuid = resVideo.body.video.uuid
395 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
396 const commentId = resComment.body.comment.id
399 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
402 it('Should send a new comment notification after a remote comment on my video', async function () {
405 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
406 const uuid = resVideo.body.video.uuid
408 await waitJobs(servers)
410 await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
412 await waitJobs(servers)
414 const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
415 expect(resComment.body.data).to.have.lengthOf(1)
416 const commentId = resComment.body.data[0].id
418 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
421 it('Should send a new comment notification after a local reply on my video', async function () {
424 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
425 const uuid = resVideo.body.video.uuid
427 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
428 const threadId = resThread.body.comment.id
430 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
431 const commentId = resComment.body.comment.id
434 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
437 it('Should send a new comment notification after a remote reply on my video', async function () {
440 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
441 const uuid = resVideo.body.video.uuid
442 await waitJobs(servers)
445 const resThread = await addVideoCommentThread(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, 'comment')
446 const threadId = resThread.body.comment.id
447 await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, threadId, 'reply')
450 await waitJobs(servers)
452 const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
453 expect(resThread.body.data).to.have.lengthOf(1)
454 const threadId = resThread.body.data[0].id
456 const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
457 const tree = resComments.body as VideoCommentThreadTree
459 expect(tree.children).to.have.lengthOf(1)
460 const commentId = tree.children[0].comment.id
462 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
466 describe('Mention notifications', function () {
467 let baseParams: CheckerBaseParams
473 socketNotifications: userNotifications,
474 token: userAccessToken
479 accessToken: servers[0].accessToken,
480 displayName: 'super root name'
485 accessToken: servers[1].accessToken,
486 displayName: 'super root 2 name'
490 it('Should not send a new mention comment notification if I mention the video owner', async function () {
493 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
494 const uuid = resVideo.body.video.uuid
496 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
497 const commentId = resComment.body.comment.id
500 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
503 it('Should not send a new mention comment notification if I mention myself', async function () {
506 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
507 const uuid = resVideo.body.video.uuid
509 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
510 const commentId = resComment.body.comment.id
513 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
516 it('Should not send a new mention notification if the account is muted', async function () {
519 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
521 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
522 const uuid = resVideo.body.video.uuid
524 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
525 const commentId = resComment.body.comment.id
528 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
530 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
533 it('Should not send a new mention notification if the remote account mention a local account', async function () {
536 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
537 const uuid = resVideo.body.video.uuid
539 await waitJobs(servers)
540 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
541 const threadId = resThread.body.comment.id
543 await waitJobs(servers)
544 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
547 it('Should send a new mention notification after local comments', async function () {
550 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
551 const uuid = resVideo.body.video.uuid
553 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
554 const threadId = resThread.body.comment.id
557 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
559 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
560 const commentId = resComment.body.comment.id
563 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
566 it('Should send a new mention notification after remote comments', async function () {
569 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
570 const uuid = resVideo.body.video.uuid
572 await waitJobs(servers)
573 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1')
574 const server2ThreadId = resThread.body.comment.id
576 await waitJobs(servers)
578 const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
579 expect(resThread2.body.data).to.have.lengthOf(1)
580 const server1ThreadId = resThread2.body.data[0].id
581 await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
583 const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001'
584 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text)
586 await waitJobs(servers)
588 const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
589 const tree = resComments.body as VideoCommentThreadTree
591 expect(tree.children).to.have.lengthOf(1)
592 const commentId = tree.children[0].comment.id
594 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
598 describe('Video abuse for moderators notification' , function () {
599 let baseParams: CheckerBaseParams
605 socketNotifications: adminNotifications,
606 token: servers[0].accessToken
610 it('Should send a notification to moderators on local video abuse', async function () {
613 const name = 'video for abuse ' + uuidv4()
614 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
615 const uuid = resVideo.body.video.uuid
617 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
619 await waitJobs(servers)
620 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
623 it('Should send a notification to moderators on remote video abuse', async function () {
626 const name = 'video for abuse ' + uuidv4()
627 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
628 const uuid = resVideo.body.video.uuid
630 await waitJobs(servers)
632 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
634 await waitJobs(servers)
635 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
639 describe('Video blacklist on my video', function () {
640 let baseParams: CheckerBaseParams
646 socketNotifications: userNotifications,
647 token: userAccessToken
651 it('Should send a notification to video owner on blacklist', async function () {
654 const name = 'video for abuse ' + uuidv4()
655 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
656 const uuid = resVideo.body.video.uuid
658 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
660 await waitJobs(servers)
661 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
664 it('Should send a notification to video owner on unblacklist', async function () {
667 const name = 'video for abuse ' + uuidv4()
668 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
669 const uuid = resVideo.body.video.uuid
671 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
673 await waitJobs(servers)
674 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
675 await waitJobs(servers)
678 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
682 describe('My video is published', function () {
683 let baseParams: CheckerBaseParams
689 socketNotifications: adminNotificationsServer2,
690 token: servers[1].accessToken
694 it('Should not send a notification if transcoding is not enabled', async function () {
697 const { name, uuid } = await uploadVideoByLocalAccount(servers)
698 await waitJobs(servers)
700 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
703 it('Should not send a notification if the wait transcoding is false', async function () {
706 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
707 await waitJobs(servers)
709 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
711 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
715 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
718 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
719 await waitJobs(servers)
721 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
724 it('Should send a notification with a transcoded video', async function () {
727 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
728 await waitJobs(servers)
730 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
733 it('Should send a notification when an imported video is transcoded', async function () {
736 const name = 'video import ' + uuidv4()
741 privacy: VideoPrivacy.PUBLIC,
742 targetUrl: getYoutubeVideoUrl(),
743 waitTranscoding: true
745 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
746 const uuid = res.body.video.uuid
748 await waitJobs(servers)
749 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
752 it('Should send a notification when the scheduled update has been proceeded', async function () {
756 let updateAt = new Date(new Date().getTime() + 2000)
759 privacy: VideoPrivacy.PRIVATE,
761 updateAt: updateAt.toISOString(),
762 privacy: VideoPrivacy.PUBLIC
765 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
768 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
771 it('Should not send a notification before the video is published', async function () {
774 let updateAt = new Date(new Date().getTime() + 100000)
777 privacy: VideoPrivacy.PRIVATE,
779 updateAt: updateAt.toISOString(),
780 privacy: VideoPrivacy.PUBLIC
783 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
786 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
790 describe('My video is imported', function () {
791 let baseParams: CheckerBaseParams
797 socketNotifications: adminNotifications,
798 token: servers[0].accessToken
802 it('Should send a notification when the video import failed', async function () {
805 const name = 'video import ' + uuidv4()
810 privacy: VideoPrivacy.PRIVATE,
811 targetUrl: getBadVideoUrl()
813 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
814 const uuid = res.body.video.uuid
816 await waitJobs(servers)
817 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
820 it('Should send a notification when the video import succeeded', async function () {
823 const name = 'video import ' + uuidv4()
828 privacy: VideoPrivacy.PRIVATE,
829 targetUrl: getYoutubeVideoUrl()
831 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
832 const uuid = res.body.video.uuid
834 await waitJobs(servers)
835 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
839 describe('New registration', function () {
840 let baseParams: CheckerBaseParams
846 socketNotifications: adminNotifications,
847 token: servers[0].accessToken
851 it('Should send a notification only to moderators when a user registers on the instance', async function () {
854 await registerUser(servers[0].url, 'user_45', 'password')
856 await waitJobs(servers)
858 await checkUserRegistered(baseParams, 'user_45', 'presence')
860 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
861 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
865 describe('New instance follower', function () {
866 let baseParams: CheckerBaseParams
872 socketNotifications: adminNotifications,
873 token: servers[0].accessToken
877 it('Should send a notification only to admin when there is a new instance follower', async function () {
880 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
882 await waitJobs(servers)
884 await checkNewInstanceFollower(baseParams, 'localhost:9003', 'presence')
886 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
887 await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:9003', 'absence')
891 describe('New actor follow', function () {
892 let baseParams: CheckerBaseParams
893 let myChannelName = 'super channel name'
894 let myUserName = 'super user name'
900 socketNotifications: userNotifications,
901 token: userAccessToken
906 accessToken: servers[0].accessToken,
907 displayName: 'super root name'
912 accessToken: userAccessToken,
913 displayName: myUserName
918 accessToken: servers[1].accessToken,
919 displayName: 'super root 2 name'
922 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
925 it('Should notify when a local channel is following one of our channel', async function () {
928 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
929 await waitJobs(servers)
931 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
933 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
936 it('Should notify when a remote channel is following one of our channel', async function () {
939 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
940 await waitJobs(servers)
942 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
944 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
947 it('Should notify when a local account is following one of our channel', async function () {
950 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001')
952 await waitJobs(servers)
954 await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
957 it('Should notify when a remote account is following one of our channel', async function () {
960 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001')
962 await waitJobs(servers)
964 await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
968 describe('Video-related notifications when video auto-blacklist is enabled', function () {
969 let userBaseParams: CheckerBaseParams
970 let adminBaseParamsServer1: CheckerBaseParams
971 let adminBaseParamsServer2: CheckerBaseParams
972 let videoUUID: string
973 let videoName: string
974 let currentCustomConfig: CustomConfig
978 adminBaseParamsServer1 = {
981 socketNotifications: adminNotifications,
982 token: servers[0].accessToken
985 adminBaseParamsServer2 = {
988 socketNotifications: adminNotificationsServer2,
989 token: servers[1].accessToken
995 socketNotifications: userNotifications,
996 token: userAccessToken
999 const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken)
1000 currentCustomConfig = resCustomConfig.body
1001 const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, {
1010 // enable transcoding otherwise own publish notification after transcoding not expected
1011 autoBlacklistTestsCustomConfig.transcoding.enabled = true
1012 await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig)
1014 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
1015 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
1019 it('Should send notification to moderators on new video with auto-blacklist', async function () {
1022 videoName = 'video with auto-blacklist ' + uuidv4()
1023 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
1024 videoUUID = resVideo.body.video.uuid
1026 await waitJobs(servers)
1027 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
1030 it('Should not send video publish notification if auto-blacklisted', async function () {
1031 await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence')
1034 it('Should not send a local user subscription notification if auto-blacklisted', async function () {
1035 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence')
1038 it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
1039 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence')
1042 it('Should send video published and unblacklist after video unblacklisted', async function () {
1045 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID)
1047 await waitJobs(servers)
1049 // FIXME: Can't test as two notifications sent to same user and util only checks last one
1050 // One notification might be better anyways
1051 // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist')
1052 // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence')
1055 it('Should send a local user subscription notification after removed from blacklist', async function () {
1056 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence')
1059 it('Should send a remote user subscription notification after removed from blacklist', async function () {
1060 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence')
1063 it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
1066 let updateAt = new Date(new Date().getTime() + 100000)
1068 const name = 'video with auto-blacklist and future schedule ' + uuidv4()
1072 privacy: VideoPrivacy.PRIVATE,
1074 updateAt: updateAt.toISOString(),
1075 privacy: VideoPrivacy.PUBLIC
1079 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1080 const uuid = resVideo.body.video.uuid
1082 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
1084 await waitJobs(servers)
1085 await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
1087 // FIXME: Can't test absence as two notifications sent to same user and util only checks last one
1088 // One notification might be better anyways
1089 // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1091 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1092 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1095 it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
1099 let updateAt = new Date(new Date().getTime() + 2000)
1101 const name = 'video with schedule done and still auto-blacklisted ' + uuidv4()
1105 privacy: VideoPrivacy.PRIVATE,
1107 updateAt: updateAt.toISOString(),
1108 privacy: VideoPrivacy.PUBLIC
1112 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1113 const uuid = resVideo.body.video.uuid
1116 await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1117 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1118 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1121 it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
1124 const name = 'video without auto-blacklist ' + uuidv4()
1126 // admin with blacklist right will not be auto-blacklisted
1127 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name })
1128 const uuid = resVideo.body.video.uuid
1130 await waitJobs(servers)
1131 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
1135 await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig)
1137 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
1138 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
1142 describe('Mark as read', function () {
1143 it('Should mark as read some notifications', async function () {
1144 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
1145 const ids = res.body.data.map(n => n.id)
1147 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
1150 it('Should have the notifications marked as read', async function () {
1151 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
1153 const notifications = res.body.data as UserNotification[]
1154 expect(notifications[ 0 ].read).to.be.false
1155 expect(notifications[ 1 ].read).to.be.false
1156 expect(notifications[ 2 ].read).to.be.true
1157 expect(notifications[ 3 ].read).to.be.true
1158 expect(notifications[ 4 ].read).to.be.true
1159 expect(notifications[ 5 ].read).to.be.false
1162 it('Should only list read notifications', async function () {
1163 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
1165 const notifications = res.body.data as UserNotification[]
1166 for (const notification of notifications) {
1167 expect(notification.read).to.be.true
1171 it('Should only list unread notifications', async function () {
1172 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1174 const notifications = res.body.data as UserNotification[]
1175 for (const notification of notifications) {
1176 expect(notification.read).to.be.false
1180 it('Should mark as read all notifications', async function () {
1181 await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
1183 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1185 expect(res.body.total).to.equal(0)
1186 expect(res.body.data).to.have.lengthOf(0)
1190 describe('Notification settings', function () {
1191 let baseParams: CheckerBaseParams
1197 socketNotifications: userNotifications,
1198 token: userAccessToken
1202 it('Should not have notifications', async function () {
1205 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1206 newVideoFromSubscription: UserNotificationSettingValue.NONE
1210 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1211 const info = res.body as User
1212 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
1215 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1217 const check = { web: true, mail: true }
1218 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1221 it('Should only have web notifications', async function () {
1224 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1225 newVideoFromSubscription: UserNotificationSettingValue.WEB
1229 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1230 const info = res.body as User
1231 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
1234 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1237 const check = { mail: true, web: false }
1238 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1242 const check = { mail: false, web: true }
1243 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1247 it('Should only have mail notifications', async function () {
1250 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1251 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
1255 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1256 const info = res.body as User
1257 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
1260 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1263 const check = { mail: false, web: true }
1264 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1268 const check = { mail: true, web: false }
1269 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1273 it('Should have email and web notifications', async function () {
1276 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1277 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1281 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1282 const info = res.body as User
1283 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
1284 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1288 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1290 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
1294 after(async function () {
1295 MockSmtpServer.Instance.kill()
1297 killallServers(servers)