1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
9 flushAndRunMultipleServers,
14 removeVideoFromBlacklist,
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
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'
62 const expect = chai.expect
64 async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) {
65 const name = 'remote video ' + uuidv4()
67 const data = Object.assign({ name }, additionalParams)
68 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data)
70 await waitJobs(servers)
72 return { uuid: res.body.video.uuid, name }
75 async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) {
76 const name = 'local video ' + uuidv4()
78 const data = Object.assign({ name }, additionalParams)
79 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data)
81 await waitJobs(servers)
83 return { uuid: res.body.video.uuid, name }
86 describe('Test users notifications', function () {
87 let servers: ServerInfo[] = []
88 let userAccessToken: string
89 let userNotifications: UserNotification[] = []
90 let adminNotifications: UserNotification[] = []
91 let adminNotificationsServer2: UserNotification[] = []
92 const emails: object[] = []
95 const allNotificationSettings: UserNotificationSetting = {
96 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
97 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
98 videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
99 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
100 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
101 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
102 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
103 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
104 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
105 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
108 before(async function () {
111 await MockSmtpServer.Instance.collectEmails(emails)
115 const overrideConfig = {
117 hostname: 'localhost'
120 servers = await flushAndRunMultipleServers(2, overrideConfig)
122 // Get the access tokens
123 await setAccessTokensToServers(servers)
125 // Server 1 and server 2 follow each other
126 await doubleFollow(servers[0], servers[1])
128 await waitJobs(servers)
132 password: 'super password'
134 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000)
135 userAccessToken = await userLogin(servers[0], user)
137 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
138 await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
139 await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
142 const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
143 socket.on('new-notification', n => userNotifications.push(n))
146 const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
147 socket.on('new-notification', n => adminNotifications.push(n))
150 const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
151 socket.on('new-notification', n => adminNotificationsServer2.push(n))
155 const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
156 channelId = resChannel.body.videoChannels[0].id
160 describe('New video from my subscription notification', function () {
161 let baseParams: CheckerBaseParams
167 socketNotifications: userNotifications,
168 token: userAccessToken
172 it('Should not send notifications if the user does not follow the video publisher', async function () {
175 await uploadVideoByLocalAccount(servers)
177 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
178 expect(notification).to.be.undefined
180 expect(emails).to.have.lengthOf(0)
181 expect(userNotifications).to.have.lengthOf(0)
184 it('Should send a new video notification if the user follows the local video publisher', async function () {
187 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
188 await waitJobs(servers)
190 const { name, uuid } = await uploadVideoByLocalAccount(servers)
191 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
194 it('Should send a new video notification from a remote account', async function () {
195 this.timeout(50000) // Server 2 has transcoding enabled
197 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002')
198 await waitJobs(servers)
200 const { name, uuid } = await uploadVideoByRemoteAccount(servers)
201 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
204 it('Should send a new video notification on a scheduled publication', async function () {
208 let updateAt = new Date(new Date().getTime() + 2000)
211 privacy: VideoPrivacy.PRIVATE,
213 updateAt: updateAt.toISOString(),
214 privacy: VideoPrivacy.PUBLIC
217 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
220 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
223 it('Should send a new video notification on a remote scheduled publication', async function () {
227 let updateAt = new Date(new Date().getTime() + 2000)
230 privacy: VideoPrivacy.PRIVATE,
232 updateAt: updateAt.toISOString(),
233 privacy: VideoPrivacy.PUBLIC
236 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
237 await waitJobs(servers)
240 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
243 it('Should not send a notification before the video is published', async function () {
246 let updateAt = new Date(new Date().getTime() + 1000000)
249 privacy: VideoPrivacy.PRIVATE,
251 updateAt: updateAt.toISOString(),
252 privacy: VideoPrivacy.PUBLIC
255 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
258 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
261 it('Should send a new video notification when a video becomes public', async function () {
264 const data = { privacy: VideoPrivacy.PRIVATE }
265 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
267 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
269 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
272 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
275 it('Should send a new video notification when a remote video becomes public', async function () {
278 const data = { privacy: VideoPrivacy.PRIVATE }
279 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
281 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
283 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
285 await waitJobs(servers)
286 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
289 it('Should not send a new video notification when a video becomes unlisted', async function () {
292 const data = { privacy: VideoPrivacy.PRIVATE }
293 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
295 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
297 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
300 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
303 const data = { privacy: VideoPrivacy.PRIVATE }
304 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
306 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
308 await waitJobs(servers)
309 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
312 it('Should send a new video notification after a video import', async function () {
315 const name = 'video import ' + uuidv4()
320 privacy: VideoPrivacy.PUBLIC,
321 targetUrl: getYoutubeVideoUrl()
323 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
324 const uuid = res.body.video.uuid
326 await waitJobs(servers)
328 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
332 describe('Comment on my video notifications', function () {
333 let baseParams: CheckerBaseParams
339 socketNotifications: userNotifications,
340 token: userAccessToken
344 it('Should not send a new comment notification after a comment on another video', async function () {
347 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
348 const uuid = resVideo.body.video.uuid
350 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
351 const commentId = resComment.body.comment.id
354 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
357 it('Should not send a new comment notification if I comment my own video', async function () {
360 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
361 const uuid = resVideo.body.video.uuid
363 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
364 const commentId = resComment.body.comment.id
367 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
370 it('Should not send a new comment notification if the account is muted', async function () {
373 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
375 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
376 const uuid = resVideo.body.video.uuid
378 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
379 const commentId = resComment.body.comment.id
382 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
384 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
387 it('Should send a new comment notification after a local comment on my video', async function () {
390 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
391 const uuid = resVideo.body.video.uuid
393 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
394 const commentId = resComment.body.comment.id
397 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
400 it('Should send a new comment notification after a remote comment on my video', async function () {
403 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
404 const uuid = resVideo.body.video.uuid
406 await waitJobs(servers)
408 const resComment = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
409 const commentId = resComment.body.comment.id
411 await waitJobs(servers)
412 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
415 it('Should send a new comment notification after a local reply on my video', async function () {
418 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
419 const uuid = resVideo.body.video.uuid
421 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
422 const threadId = resThread.body.comment.id
424 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
425 const commentId = resComment.body.comment.id
428 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
431 it('Should send a new comment notification after a remote reply on my video', async function () {
434 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
435 const uuid = resVideo.body.video.uuid
436 await waitJobs(servers)
438 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
439 const threadId = resThread.body.comment.id
441 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply')
442 const commentId = resComment.body.comment.id
444 await waitJobs(servers)
445 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
449 describe('Mention notifications', function () {
450 let baseParams: CheckerBaseParams
456 socketNotifications: userNotifications,
457 token: userAccessToken
462 accessToken: servers[0].accessToken,
463 displayName: 'super root name'
468 accessToken: servers[1].accessToken,
469 displayName: 'super root 2 name'
473 it('Should not send a new mention comment notification if I mention the video owner', async function () {
476 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
477 const uuid = resVideo.body.video.uuid
479 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
480 const commentId = resComment.body.comment.id
483 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
486 it('Should not send a new mention comment notification if I mention myself', async function () {
489 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
490 const uuid = resVideo.body.video.uuid
492 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
493 const commentId = resComment.body.comment.id
496 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
499 it('Should not send a new mention notification if the account is muted', async function () {
502 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
504 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
505 const uuid = resVideo.body.video.uuid
507 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
508 const commentId = resComment.body.comment.id
511 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
513 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
516 it('Should not send a new mention notification if the remote account mention a local account', async function () {
519 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
520 const uuid = resVideo.body.video.uuid
522 await waitJobs(servers)
523 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
524 const threadId = resThread.body.comment.id
526 await waitJobs(servers)
527 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
530 it('Should send a new mention notification after local comments', async function () {
533 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
534 const uuid = resVideo.body.video.uuid
536 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
537 const threadId = resThread.body.comment.id
540 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
542 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
543 const commentId = resComment.body.comment.id
546 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
549 it('Should send a new mention notification after remote comments', async function () {
552 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
553 const uuid = resVideo.body.video.uuid
555 await waitJobs(servers)
556 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1')
557 const threadId = resThread.body.comment.id
559 await waitJobs(servers)
560 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'presence')
562 const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001'
563 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, text)
564 const commentId = resComment.body.comment.id
566 await waitJobs(servers)
567 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root 2 name', 'presence')
571 describe('Video abuse for moderators notification' , function () {
572 let baseParams: CheckerBaseParams
578 socketNotifications: adminNotifications,
579 token: servers[0].accessToken
583 it('Should send a notification to moderators on local video abuse', async function () {
586 const name = 'video for abuse ' + uuidv4()
587 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
588 const uuid = resVideo.body.video.uuid
590 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
592 await waitJobs(servers)
593 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
596 it('Should send a notification to moderators on remote video abuse', async function () {
599 const name = 'video for abuse ' + uuidv4()
600 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
601 const uuid = resVideo.body.video.uuid
603 await waitJobs(servers)
605 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
607 await waitJobs(servers)
608 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
612 describe('Video blacklist on my video', function () {
613 let baseParams: CheckerBaseParams
619 socketNotifications: userNotifications,
620 token: userAccessToken
624 it('Should send a notification to video owner on blacklist', async function () {
627 const name = 'video for abuse ' + uuidv4()
628 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
629 const uuid = resVideo.body.video.uuid
631 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
633 await waitJobs(servers)
634 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
637 it('Should send a notification to video owner on unblacklist', async function () {
640 const name = 'video for abuse ' + uuidv4()
641 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
642 const uuid = resVideo.body.video.uuid
644 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
646 await waitJobs(servers)
647 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
648 await waitJobs(servers)
651 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
655 describe('My video is published', function () {
656 let baseParams: CheckerBaseParams
662 socketNotifications: adminNotificationsServer2,
663 token: servers[1].accessToken
667 it('Should not send a notification if transcoding is not enabled', async function () {
670 const { name, uuid } = await uploadVideoByLocalAccount(servers)
671 await waitJobs(servers)
673 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
676 it('Should not send a notification if the wait transcoding is false', async function () {
679 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
680 await waitJobs(servers)
682 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
684 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
688 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
691 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
692 await waitJobs(servers)
694 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
697 it('Should send a notification with a transcoded video', async function () {
700 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
701 await waitJobs(servers)
703 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
706 it('Should send a notification when an imported video is transcoded', async function () {
709 const name = 'video import ' + uuidv4()
714 privacy: VideoPrivacy.PUBLIC,
715 targetUrl: getYoutubeVideoUrl(),
716 waitTranscoding: true
718 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
719 const uuid = res.body.video.uuid
721 await waitJobs(servers)
722 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
725 it('Should send a notification when the scheduled update has been proceeded', async function () {
729 let updateAt = new Date(new Date().getTime() + 2000)
732 privacy: VideoPrivacy.PRIVATE,
734 updateAt: updateAt.toISOString(),
735 privacy: VideoPrivacy.PUBLIC
738 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
741 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
744 it('Should not send a notification before the video is published', async function () {
747 let updateAt = new Date(new Date().getTime() + 100000)
750 privacy: VideoPrivacy.PRIVATE,
752 updateAt: updateAt.toISOString(),
753 privacy: VideoPrivacy.PUBLIC
756 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
759 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
763 describe('My video is imported', function () {
764 let baseParams: CheckerBaseParams
770 socketNotifications: adminNotifications,
771 token: servers[0].accessToken
775 it('Should send a notification when the video import failed', async function () {
778 const name = 'video import ' + uuidv4()
783 privacy: VideoPrivacy.PRIVATE,
784 targetUrl: getBadVideoUrl()
786 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
787 const uuid = res.body.video.uuid
789 await waitJobs(servers)
790 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
793 it('Should send a notification when the video import succeeded', async function () {
796 const name = 'video import ' + uuidv4()
801 privacy: VideoPrivacy.PRIVATE,
802 targetUrl: getYoutubeVideoUrl()
804 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
805 const uuid = res.body.video.uuid
807 await waitJobs(servers)
808 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
812 describe('New registration', function () {
813 let baseParams: CheckerBaseParams
819 socketNotifications: adminNotifications,
820 token: servers[0].accessToken
824 it('Should send a notification only to moderators when a user registers on the instance', async function () {
827 await registerUser(servers[0].url, 'user_45', 'password')
829 await waitJobs(servers)
831 await checkUserRegistered(baseParams, 'user_45', 'presence')
833 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
834 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
838 describe('New actor follow', function () {
839 let baseParams: CheckerBaseParams
840 let myChannelName = 'super channel name'
841 let myUserName = 'super user name'
847 socketNotifications: userNotifications,
848 token: userAccessToken
853 accessToken: servers[0].accessToken,
854 displayName: 'super root name'
859 accessToken: userAccessToken,
860 displayName: myUserName
865 accessToken: servers[1].accessToken,
866 displayName: 'super root 2 name'
869 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
872 it('Should notify when a local channel is following one of our channel', async function () {
875 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
876 await waitJobs(servers)
878 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
880 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
883 it('Should notify when a remote channel is following one of our channel', async function () {
886 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
887 await waitJobs(servers)
889 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
891 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
894 it('Should notify when a local account is following one of our channel', async function () {
897 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001')
899 await waitJobs(servers)
901 await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
904 it('Should notify when a remote account is following one of our channel', async function () {
907 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001')
909 await waitJobs(servers)
911 await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
915 describe('Video-related notifications when video auto-blacklist is enabled', function () {
916 let userBaseParams: CheckerBaseParams
917 let adminBaseParamsServer1: CheckerBaseParams
918 let adminBaseParamsServer2: CheckerBaseParams
919 let videoUUID: string
920 let videoName: string
921 let currentCustomConfig: CustomConfig
925 adminBaseParamsServer1 = {
928 socketNotifications: adminNotifications,
929 token: servers[0].accessToken
932 adminBaseParamsServer2 = {
935 socketNotifications: adminNotificationsServer2,
936 token: servers[1].accessToken
942 socketNotifications: userNotifications,
943 token: userAccessToken
946 const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken)
947 currentCustomConfig = resCustomConfig.body
948 const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, {
957 // enable transcoding otherwise own publish notification after transcoding not expected
958 autoBlacklistTestsCustomConfig.transcoding.enabled = true
959 await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig)
961 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
962 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
966 it('Should send notification to moderators on new video with auto-blacklist', async function () {
969 videoName = 'video with auto-blacklist ' + uuidv4()
970 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
971 videoUUID = resVideo.body.video.uuid
973 await waitJobs(servers)
974 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
977 it('Should not send video publish notification if auto-blacklisted', async function () {
978 await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence')
981 it('Should not send a local user subscription notification if auto-blacklisted', async function () {
982 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence')
985 it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
986 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence')
989 it('Should send video published and unblacklist after video unblacklisted', async function () {
992 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID)
994 await waitJobs(servers)
996 // FIXME: Can't test as two notifications sent to same user and util only checks last one
997 // One notification might be better anyways
998 // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist')
999 // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence')
1002 it('Should send a local user subscription notification after removed from blacklist', async function () {
1003 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence')
1006 it('Should send a remote user subscription notification after removed from blacklist', async function () {
1007 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence')
1010 it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
1013 let updateAt = new Date(new Date().getTime() + 100000)
1015 const name = 'video with auto-blacklist and future schedule ' + uuidv4()
1019 privacy: VideoPrivacy.PRIVATE,
1021 updateAt: updateAt.toISOString(),
1022 privacy: VideoPrivacy.PUBLIC
1026 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1027 const uuid = resVideo.body.video.uuid
1029 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
1031 await waitJobs(servers)
1032 await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
1034 // FIXME: Can't test absence as two notifications sent to same user and util only checks last one
1035 // One notification might be better anyways
1036 // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1038 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1039 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1042 it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
1046 let updateAt = new Date(new Date().getTime() + 2000)
1048 const name = 'video with schedule done and still auto-blacklisted ' + uuidv4()
1052 privacy: VideoPrivacy.PRIVATE,
1054 updateAt: updateAt.toISOString(),
1055 privacy: VideoPrivacy.PUBLIC
1059 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1060 const uuid = resVideo.body.video.uuid
1063 await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1064 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1065 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1068 it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
1071 const name = 'video without auto-blacklist ' + uuidv4()
1073 // admin with blacklist right will not be auto-blacklisted
1074 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name })
1075 const uuid = resVideo.body.video.uuid
1077 await waitJobs(servers)
1078 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
1082 await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig)
1084 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
1085 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
1089 describe('Mark as read', function () {
1090 it('Should mark as read some notifications', async function () {
1091 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
1092 const ids = res.body.data.map(n => n.id)
1094 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
1097 it('Should have the notifications marked as read', async function () {
1098 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
1100 const notifications = res.body.data as UserNotification[]
1101 expect(notifications[ 0 ].read).to.be.false
1102 expect(notifications[ 1 ].read).to.be.false
1103 expect(notifications[ 2 ].read).to.be.true
1104 expect(notifications[ 3 ].read).to.be.true
1105 expect(notifications[ 4 ].read).to.be.true
1106 expect(notifications[ 5 ].read).to.be.false
1109 it('Should only list read notifications', async function () {
1110 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
1112 const notifications = res.body.data as UserNotification[]
1113 for (const notification of notifications) {
1114 expect(notification.read).to.be.true
1118 it('Should only list unread notifications', async function () {
1119 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1121 const notifications = res.body.data as UserNotification[]
1122 for (const notification of notifications) {
1123 expect(notification.read).to.be.false
1127 it('Should mark as read all notifications', async function () {
1128 await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
1130 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1132 expect(res.body.total).to.equal(0)
1133 expect(res.body.data).to.have.lengthOf(0)
1137 describe('Notification settings', function () {
1138 let baseParams: CheckerBaseParams
1144 socketNotifications: userNotifications,
1145 token: userAccessToken
1149 it('Should not have notifications', async function () {
1152 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1153 newVideoFromSubscription: UserNotificationSettingValue.NONE
1157 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1158 const info = res.body as User
1159 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
1162 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1164 const check = { web: true, mail: true }
1165 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1168 it('Should only have web notifications', async function () {
1171 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1172 newVideoFromSubscription: UserNotificationSettingValue.WEB
1176 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1177 const info = res.body as User
1178 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
1181 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1184 const check = { mail: true, web: false }
1185 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1189 const check = { mail: false, web: true }
1190 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1194 it('Should only have mail notifications', async function () {
1197 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1198 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
1202 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1203 const info = res.body as User
1204 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
1207 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1210 const check = { mail: false, web: true }
1211 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1215 const check = { mail: true, web: false }
1216 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1220 it('Should have email and web notifications', async function () {
1223 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1224 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1228 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1229 const info = res.body as User
1230 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
1231 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1235 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1237 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
1241 after(async function () {
1242 MockSmtpServer.Instance.kill()
1244 killallServers(servers)