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'
137 url: servers[ 0 ].url,
138 accessToken: servers[ 0 ].accessToken,
139 username: user.username,
140 password: user.password,
141 videoQuota: 10 * 1000 * 1000
143 userAccessToken = await userLogin(servers[0], user)
145 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
146 await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
147 await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
150 const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
151 socket.on('new-notification', n => userNotifications.push(n))
154 const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
155 socket.on('new-notification', n => adminNotifications.push(n))
158 const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
159 socket.on('new-notification', n => adminNotificationsServer2.push(n))
163 const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
164 channelId = resChannel.body.videoChannels[0].id
168 describe('New video from my subscription notification', function () {
169 let baseParams: CheckerBaseParams
175 socketNotifications: userNotifications,
176 token: userAccessToken
180 it('Should not send notifications if the user does not follow the video publisher', async function () {
183 await uploadVideoByLocalAccount(servers)
185 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
186 expect(notification).to.be.undefined
188 expect(emails).to.have.lengthOf(0)
189 expect(userNotifications).to.have.lengthOf(0)
192 it('Should send a new video notification if the user follows the local video publisher', async function () {
195 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
196 await waitJobs(servers)
198 const { name, uuid } = await uploadVideoByLocalAccount(servers)
199 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
202 it('Should send a new video notification from a remote account', async function () {
203 this.timeout(50000) // Server 2 has transcoding enabled
205 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002')
206 await waitJobs(servers)
208 const { name, uuid } = await uploadVideoByRemoteAccount(servers)
209 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
212 it('Should send a new video notification on a scheduled publication', async function () {
216 let updateAt = new Date(new Date().getTime() + 2000)
219 privacy: VideoPrivacy.PRIVATE,
221 updateAt: updateAt.toISOString(),
222 privacy: VideoPrivacy.PUBLIC
225 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
228 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
231 it('Should send a new video notification on a remote scheduled publication', async function () {
235 let updateAt = new Date(new Date().getTime() + 2000)
238 privacy: VideoPrivacy.PRIVATE,
240 updateAt: updateAt.toISOString(),
241 privacy: VideoPrivacy.PUBLIC
244 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
245 await waitJobs(servers)
248 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
251 it('Should not send a notification before the video is published', async function () {
254 let updateAt = new Date(new Date().getTime() + 1000000)
257 privacy: VideoPrivacy.PRIVATE,
259 updateAt: updateAt.toISOString(),
260 privacy: VideoPrivacy.PUBLIC
263 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
266 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
269 it('Should send a new video notification when a video becomes public', async function () {
272 const data = { privacy: VideoPrivacy.PRIVATE }
273 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
275 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
277 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
280 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
283 it('Should send a new video notification when a remote video becomes public', async function () {
286 const data = { privacy: VideoPrivacy.PRIVATE }
287 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
289 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
291 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
293 await waitJobs(servers)
294 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
297 it('Should not send a new video notification when a video becomes unlisted', async function () {
300 const data = { privacy: VideoPrivacy.PRIVATE }
301 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
303 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
305 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
308 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
311 const data = { privacy: VideoPrivacy.PRIVATE }
312 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
314 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
316 await waitJobs(servers)
317 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
320 it('Should send a new video notification after a video import', async function () {
323 const name = 'video import ' + uuidv4()
328 privacy: VideoPrivacy.PUBLIC,
329 targetUrl: getYoutubeVideoUrl()
331 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
332 const uuid = res.body.video.uuid
334 await waitJobs(servers)
336 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
340 describe('Comment on my video notifications', function () {
341 let baseParams: CheckerBaseParams
347 socketNotifications: userNotifications,
348 token: userAccessToken
352 it('Should not send a new comment notification after a comment on another video', async function () {
355 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
356 const uuid = resVideo.body.video.uuid
358 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
359 const commentId = resComment.body.comment.id
362 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
365 it('Should not send a new comment notification if I comment my own video', async function () {
368 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
369 const uuid = resVideo.body.video.uuid
371 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
372 const commentId = resComment.body.comment.id
375 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
378 it('Should not send a new comment notification if the account is muted', async function () {
381 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
383 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
384 const uuid = resVideo.body.video.uuid
386 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
387 const commentId = resComment.body.comment.id
390 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
392 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
395 it('Should send a new comment notification after a local comment on my video', async function () {
398 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
399 const uuid = resVideo.body.video.uuid
401 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
402 const commentId = resComment.body.comment.id
405 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
408 it('Should send a new comment notification after a remote comment on my video', async function () {
411 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
412 const uuid = resVideo.body.video.uuid
414 await waitJobs(servers)
416 await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
418 await waitJobs(servers)
420 const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
421 expect(resComment.body.data).to.have.lengthOf(1)
422 const commentId = resComment.body.data[0].id
424 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
427 it('Should send a new comment notification after a local reply on my video', async function () {
430 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
431 const uuid = resVideo.body.video.uuid
433 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
434 const threadId = resThread.body.comment.id
436 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
437 const commentId = resComment.body.comment.id
440 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
443 it('Should send a new comment notification after a remote reply on my video', async function () {
446 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
447 const uuid = resVideo.body.video.uuid
448 await waitJobs(servers)
451 const resThread = await addVideoCommentThread(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, 'comment')
452 const threadId = resThread.body.comment.id
453 await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, threadId, 'reply')
456 await waitJobs(servers)
458 const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
459 expect(resThread.body.data).to.have.lengthOf(1)
460 const threadId = resThread.body.data[0].id
462 const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
463 const tree = resComments.body as VideoCommentThreadTree
465 expect(tree.children).to.have.lengthOf(1)
466 const commentId = tree.children[0].comment.id
468 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
472 describe('Mention notifications', function () {
473 let baseParams: CheckerBaseParams
479 socketNotifications: userNotifications,
480 token: userAccessToken
485 accessToken: servers[0].accessToken,
486 displayName: 'super root name'
491 accessToken: servers[1].accessToken,
492 displayName: 'super root 2 name'
496 it('Should not send a new mention comment notification if I mention the video owner', async function () {
499 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
500 const uuid = resVideo.body.video.uuid
502 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
503 const commentId = resComment.body.comment.id
506 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
509 it('Should not send a new mention comment notification if I mention myself', async function () {
512 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
513 const uuid = resVideo.body.video.uuid
515 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
516 const commentId = resComment.body.comment.id
519 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
522 it('Should not send a new mention notification if the account is muted', async function () {
525 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
527 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
528 const uuid = resVideo.body.video.uuid
530 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
531 const commentId = resComment.body.comment.id
534 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
536 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
539 it('Should not send a new mention notification if the remote account mention a local account', async function () {
542 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
543 const uuid = resVideo.body.video.uuid
545 await waitJobs(servers)
546 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
547 const threadId = resThread.body.comment.id
549 await waitJobs(servers)
550 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
553 it('Should send a new mention notification after local comments', async function () {
556 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
557 const uuid = resVideo.body.video.uuid
559 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
560 const threadId = resThread.body.comment.id
563 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
565 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
566 const commentId = resComment.body.comment.id
569 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
572 it('Should send a new mention notification after remote comments', async function () {
575 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
576 const uuid = resVideo.body.video.uuid
578 await waitJobs(servers)
579 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1')
580 const server2ThreadId = resThread.body.comment.id
582 await waitJobs(servers)
584 const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
585 expect(resThread2.body.data).to.have.lengthOf(1)
586 const server1ThreadId = resThread2.body.data[0].id
587 await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
589 const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001'
590 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text)
592 await waitJobs(servers)
594 const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
595 const tree = resComments.body as VideoCommentThreadTree
597 expect(tree.children).to.have.lengthOf(1)
598 const commentId = tree.children[0].comment.id
600 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
604 describe('Video abuse for moderators notification' , function () {
605 let baseParams: CheckerBaseParams
611 socketNotifications: adminNotifications,
612 token: servers[0].accessToken
616 it('Should send a notification to moderators on local video abuse', async function () {
619 const name = 'video for abuse ' + uuidv4()
620 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
621 const uuid = resVideo.body.video.uuid
623 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
625 await waitJobs(servers)
626 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
629 it('Should send a notification to moderators on remote video abuse', async function () {
632 const name = 'video for abuse ' + uuidv4()
633 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
634 const uuid = resVideo.body.video.uuid
636 await waitJobs(servers)
638 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
640 await waitJobs(servers)
641 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
645 describe('Video blacklist on my video', function () {
646 let baseParams: CheckerBaseParams
652 socketNotifications: userNotifications,
653 token: userAccessToken
657 it('Should send a notification to video owner on blacklist', async function () {
660 const name = 'video for abuse ' + uuidv4()
661 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
662 const uuid = resVideo.body.video.uuid
664 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
666 await waitJobs(servers)
667 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
670 it('Should send a notification to video owner on unblacklist', async function () {
673 const name = 'video for abuse ' + uuidv4()
674 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
675 const uuid = resVideo.body.video.uuid
677 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
679 await waitJobs(servers)
680 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
681 await waitJobs(servers)
684 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
688 describe('My video is published', function () {
689 let baseParams: CheckerBaseParams
695 socketNotifications: adminNotificationsServer2,
696 token: servers[1].accessToken
700 it('Should not send a notification if transcoding is not enabled', async function () {
703 const { name, uuid } = await uploadVideoByLocalAccount(servers)
704 await waitJobs(servers)
706 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
709 it('Should not send a notification if the wait transcoding is false', async function () {
712 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
713 await waitJobs(servers)
715 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
717 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
721 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
724 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
725 await waitJobs(servers)
727 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
730 it('Should send a notification with a transcoded video', async function () {
733 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
734 await waitJobs(servers)
736 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
739 it('Should send a notification when an imported video is transcoded', async function () {
742 const name = 'video import ' + uuidv4()
747 privacy: VideoPrivacy.PUBLIC,
748 targetUrl: getYoutubeVideoUrl(),
749 waitTranscoding: true
751 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
752 const uuid = res.body.video.uuid
754 await waitJobs(servers)
755 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
758 it('Should send a notification when the scheduled update has been proceeded', async function () {
762 let updateAt = new Date(new Date().getTime() + 2000)
765 privacy: VideoPrivacy.PRIVATE,
767 updateAt: updateAt.toISOString(),
768 privacy: VideoPrivacy.PUBLIC
771 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
774 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
777 it('Should not send a notification before the video is published', async function () {
780 let updateAt = new Date(new Date().getTime() + 100000)
783 privacy: VideoPrivacy.PRIVATE,
785 updateAt: updateAt.toISOString(),
786 privacy: VideoPrivacy.PUBLIC
789 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
792 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
796 describe('My video is imported', function () {
797 let baseParams: CheckerBaseParams
803 socketNotifications: adminNotifications,
804 token: servers[0].accessToken
808 it('Should send a notification when the video import failed', async function () {
811 const name = 'video import ' + uuidv4()
816 privacy: VideoPrivacy.PRIVATE,
817 targetUrl: getBadVideoUrl()
819 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
820 const uuid = res.body.video.uuid
822 await waitJobs(servers)
823 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
826 it('Should send a notification when the video import succeeded', async function () {
829 const name = 'video import ' + uuidv4()
834 privacy: VideoPrivacy.PRIVATE,
835 targetUrl: getYoutubeVideoUrl()
837 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
838 const uuid = res.body.video.uuid
840 await waitJobs(servers)
841 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
845 describe('New registration', function () {
846 let baseParams: CheckerBaseParams
852 socketNotifications: adminNotifications,
853 token: servers[0].accessToken
857 it('Should send a notification only to moderators when a user registers on the instance', async function () {
860 await registerUser(servers[0].url, 'user_45', 'password')
862 await waitJobs(servers)
864 await checkUserRegistered(baseParams, 'user_45', 'presence')
866 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
867 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
871 describe('New instance follower', function () {
872 let baseParams: CheckerBaseParams
878 socketNotifications: adminNotifications,
879 token: servers[0].accessToken
883 it('Should send a notification only to admin when there is a new instance follower', async function () {
886 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
888 await waitJobs(servers)
890 await checkNewInstanceFollower(baseParams, 'localhost:9003', 'presence')
892 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
893 await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:9003', 'absence')
897 describe('New actor follow', function () {
898 let baseParams: CheckerBaseParams
899 let myChannelName = 'super channel name'
900 let myUserName = 'super user name'
906 socketNotifications: userNotifications,
907 token: userAccessToken
912 accessToken: servers[0].accessToken,
913 displayName: 'super root name'
918 accessToken: userAccessToken,
919 displayName: myUserName
924 accessToken: servers[1].accessToken,
925 displayName: 'super root 2 name'
928 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
931 it('Should notify when a local channel is following one of our channel', async function () {
934 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
935 await waitJobs(servers)
937 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
939 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
942 it('Should notify when a remote channel is following one of our channel', async function () {
945 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
946 await waitJobs(servers)
948 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
950 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
953 it('Should notify when a local account is following one of our channel', async function () {
956 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001')
958 await waitJobs(servers)
960 await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
963 it('Should notify when a remote account is following one of our channel', async function () {
966 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001')
968 await waitJobs(servers)
970 await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
974 describe('Video-related notifications when video auto-blacklist is enabled', function () {
975 let userBaseParams: CheckerBaseParams
976 let adminBaseParamsServer1: CheckerBaseParams
977 let adminBaseParamsServer2: CheckerBaseParams
978 let videoUUID: string
979 let videoName: string
980 let currentCustomConfig: CustomConfig
984 adminBaseParamsServer1 = {
987 socketNotifications: adminNotifications,
988 token: servers[0].accessToken
991 adminBaseParamsServer2 = {
994 socketNotifications: adminNotificationsServer2,
995 token: servers[1].accessToken
1001 socketNotifications: userNotifications,
1002 token: userAccessToken
1005 const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken)
1006 currentCustomConfig = resCustomConfig.body
1007 const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, {
1016 // enable transcoding otherwise own publish notification after transcoding not expected
1017 autoBlacklistTestsCustomConfig.transcoding.enabled = true
1018 await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig)
1020 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
1021 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
1025 it('Should send notification to moderators on new video with auto-blacklist', async function () {
1028 videoName = 'video with auto-blacklist ' + uuidv4()
1029 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
1030 videoUUID = resVideo.body.video.uuid
1032 await waitJobs(servers)
1033 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
1036 it('Should not send video publish notification if auto-blacklisted', async function () {
1037 await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence')
1040 it('Should not send a local user subscription notification if auto-blacklisted', async function () {
1041 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence')
1044 it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
1045 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence')
1048 it('Should send video published and unblacklist after video unblacklisted', async function () {
1051 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID)
1053 await waitJobs(servers)
1055 // FIXME: Can't test as two notifications sent to same user and util only checks last one
1056 // One notification might be better anyways
1057 // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist')
1058 // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence')
1061 it('Should send a local user subscription notification after removed from blacklist', async function () {
1062 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence')
1065 it('Should send a remote user subscription notification after removed from blacklist', async function () {
1066 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence')
1069 it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
1072 let updateAt = new Date(new Date().getTime() + 100000)
1074 const name = 'video with auto-blacklist and future schedule ' + uuidv4()
1078 privacy: VideoPrivacy.PRIVATE,
1080 updateAt: updateAt.toISOString(),
1081 privacy: VideoPrivacy.PUBLIC
1085 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1086 const uuid = resVideo.body.video.uuid
1088 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
1090 await waitJobs(servers)
1091 await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
1093 // FIXME: Can't test absence as two notifications sent to same user and util only checks last one
1094 // One notification might be better anyways
1095 // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1097 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1098 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1101 it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
1105 let updateAt = new Date(new Date().getTime() + 2000)
1107 const name = 'video with schedule done and still auto-blacklisted ' + uuidv4()
1111 privacy: VideoPrivacy.PRIVATE,
1113 updateAt: updateAt.toISOString(),
1114 privacy: VideoPrivacy.PUBLIC
1118 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1119 const uuid = resVideo.body.video.uuid
1122 await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1123 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1124 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1127 it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
1130 const name = 'video without auto-blacklist ' + uuidv4()
1132 // admin with blacklist right will not be auto-blacklisted
1133 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name })
1134 const uuid = resVideo.body.video.uuid
1136 await waitJobs(servers)
1137 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
1141 await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig)
1143 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
1144 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
1148 describe('Mark as read', function () {
1149 it('Should mark as read some notifications', async function () {
1150 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
1151 const ids = res.body.data.map(n => n.id)
1153 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
1156 it('Should have the notifications marked as read', async function () {
1157 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
1159 const notifications = res.body.data as UserNotification[]
1160 expect(notifications[ 0 ].read).to.be.false
1161 expect(notifications[ 1 ].read).to.be.false
1162 expect(notifications[ 2 ].read).to.be.true
1163 expect(notifications[ 3 ].read).to.be.true
1164 expect(notifications[ 4 ].read).to.be.true
1165 expect(notifications[ 5 ].read).to.be.false
1168 it('Should only list read notifications', async function () {
1169 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
1171 const notifications = res.body.data as UserNotification[]
1172 for (const notification of notifications) {
1173 expect(notification.read).to.be.true
1177 it('Should only list unread notifications', async function () {
1178 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1180 const notifications = res.body.data as UserNotification[]
1181 for (const notification of notifications) {
1182 expect(notification.read).to.be.false
1186 it('Should mark as read all notifications', async function () {
1187 await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
1189 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1191 expect(res.body.total).to.equal(0)
1192 expect(res.body.data).to.have.lengthOf(0)
1196 describe('Notification settings', function () {
1197 let baseParams: CheckerBaseParams
1203 socketNotifications: userNotifications,
1204 token: userAccessToken
1208 it('Should not have notifications', async function () {
1211 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1212 newVideoFromSubscription: UserNotificationSettingValue.NONE
1216 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1217 const info = res.body as User
1218 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
1221 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1223 const check = { web: true, mail: true }
1224 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1227 it('Should only have web notifications', async function () {
1230 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1231 newVideoFromSubscription: UserNotificationSettingValue.WEB
1235 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1236 const info = res.body as User
1237 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
1240 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1243 const check = { mail: true, web: false }
1244 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1248 const check = { mail: false, web: true }
1249 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1253 it('Should only have mail notifications', async function () {
1256 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1257 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
1261 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1262 const info = res.body as User
1263 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
1266 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1269 const check = { mail: false, web: true }
1270 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1274 const check = { mail: true, web: false }
1275 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1279 it('Should have email and web notifications', async function () {
1282 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1283 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1287 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1288 const info = res.body as User
1289 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
1290 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1294 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1296 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
1300 after(async function () {
1301 MockSmtpServer.Instance.kill()
1303 killallServers(servers)