1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
10 flushAndRunMultipleServers,
14 getVideoCommentThreads,
15 getVideoThreadComments,
18 removeVideoFromBlacklist,
26 } from '../../../../shared/extra-utils'
27 import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
28 import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
29 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
30 import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io'
34 checkMyVideoImportIsFinished,
36 checkNewBlacklistOnMyVideo,
37 checkNewCommentOnMyVideo,
38 checkNewInstanceFollower,
39 checkNewVideoAbuseForModerators,
40 checkNewVideoFromSubscription,
42 checkVideoAutoBlacklistForModerators,
43 checkVideoIsPublished,
46 markAsReadAllNotifications,
47 markAsReadNotifications,
48 updateMyNotificationSettings
49 } from '../../../../shared/extra-utils/users/user-notifications'
53 UserNotificationSetting,
54 UserNotificationSettingValue,
56 } from '../../../../shared/models/users'
57 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
58 import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions'
59 import { VideoPrivacy } from '../../../../shared/models/videos'
60 import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
61 import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
62 import * as uuidv4 from 'uuid/v4'
63 import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/extra-utils/users/blocklist'
64 import { CustomConfig } from '../../../../shared/models/server'
65 import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
67 const expect = chai.expect
69 async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) {
70 const name = 'remote video ' + uuidv4()
72 const data = Object.assign({ name }, additionalParams)
73 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data)
75 await waitJobs(servers)
77 return { uuid: res.body.video.uuid, name }
80 async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) {
81 const name = 'local video ' + uuidv4()
83 const data = Object.assign({ name }, additionalParams)
84 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data)
86 await waitJobs(servers)
88 return { uuid: res.body.video.uuid, name }
91 describe('Test users notifications', function () {
92 let servers: ServerInfo[] = []
93 let userAccessToken: string
94 let userNotifications: UserNotification[] = []
95 let adminNotifications: UserNotification[] = []
96 let adminNotificationsServer2: UserNotification[] = []
97 const emails: object[] = []
100 const allNotificationSettings: UserNotificationSetting = {
101 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
102 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
103 videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
104 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
105 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
106 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
107 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
108 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
109 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
110 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
111 newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
114 before(async function () {
117 await MockSmtpServer.Instance.collectEmails(emails)
119 const overrideConfig = {
121 hostname: 'localhost'
124 servers = await flushAndRunMultipleServers(3, overrideConfig)
126 // Get the access tokens
127 await setAccessTokensToServers(servers)
129 // Server 1 and server 2 follow each other
130 await doubleFollow(servers[0], servers[1])
132 await waitJobs(servers)
136 password: 'super password'
139 url: servers[ 0 ].url,
140 accessToken: servers[ 0 ].accessToken,
141 username: user.username,
142 password: user.password,
143 videoQuota: 10 * 1000 * 1000
145 userAccessToken = await userLogin(servers[0], user)
147 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
148 await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
149 await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
152 const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
153 socket.on('new-notification', n => userNotifications.push(n))
156 const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
157 socket.on('new-notification', n => adminNotifications.push(n))
160 const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
161 socket.on('new-notification', n => adminNotificationsServer2.push(n))
165 const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
166 channelId = resChannel.body.videoChannels[0].id
170 describe('New video from my subscription notification', function () {
171 let baseParams: CheckerBaseParams
177 socketNotifications: userNotifications,
178 token: userAccessToken
182 it('Should not send notifications if the user does not follow the video publisher', async function () {
185 await uploadVideoByLocalAccount(servers)
187 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
188 expect(notification).to.be.undefined
190 expect(emails).to.have.lengthOf(0)
191 expect(userNotifications).to.have.lengthOf(0)
194 it('Should send a new video notification if the user follows the local video publisher', async function () {
197 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
198 await waitJobs(servers)
200 const { name, uuid } = await uploadVideoByLocalAccount(servers)
201 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
204 it('Should send a new video notification from a remote account', async function () {
205 this.timeout(50000) // Server 2 has transcoding enabled
207 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002')
208 await waitJobs(servers)
210 const { name, uuid } = await uploadVideoByRemoteAccount(servers)
211 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
214 it('Should send a new video notification on a scheduled publication', async function () {
218 let updateAt = new Date(new Date().getTime() + 2000)
221 privacy: VideoPrivacy.PRIVATE,
223 updateAt: updateAt.toISOString(),
224 privacy: VideoPrivacy.PUBLIC
227 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
230 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
233 it('Should send a new video notification on a remote scheduled publication', async function () {
237 let updateAt = new Date(new Date().getTime() + 2000)
240 privacy: VideoPrivacy.PRIVATE,
242 updateAt: updateAt.toISOString(),
243 privacy: VideoPrivacy.PUBLIC
246 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
247 await waitJobs(servers)
250 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
253 it('Should not send a notification before the video is published', async function () {
256 let updateAt = new Date(new Date().getTime() + 1000000)
259 privacy: VideoPrivacy.PRIVATE,
261 updateAt: updateAt.toISOString(),
262 privacy: VideoPrivacy.PUBLIC
265 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
268 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
271 it('Should send a new video notification when a video becomes public', async function () {
274 const data = { privacy: VideoPrivacy.PRIVATE }
275 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
277 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
279 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
282 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
285 it('Should send a new video notification when a remote video becomes public', async function () {
288 const data = { privacy: VideoPrivacy.PRIVATE }
289 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
291 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
293 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
295 await waitJobs(servers)
296 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
299 it('Should not send a new video notification when a video becomes unlisted', async function () {
302 const data = { privacy: VideoPrivacy.PRIVATE }
303 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
305 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
307 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
310 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
313 const data = { privacy: VideoPrivacy.PRIVATE }
314 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
316 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
318 await waitJobs(servers)
319 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
322 it('Should send a new video notification after a video import', async function () {
325 const name = 'video import ' + uuidv4()
330 privacy: VideoPrivacy.PUBLIC,
331 targetUrl: getYoutubeVideoUrl()
333 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
334 const uuid = res.body.video.uuid
336 await waitJobs(servers)
338 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
342 describe('Comment on my video notifications', function () {
343 let baseParams: CheckerBaseParams
349 socketNotifications: userNotifications,
350 token: userAccessToken
354 it('Should not send a new comment notification after a comment on another video', async function () {
357 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
358 const uuid = resVideo.body.video.uuid
360 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
361 const commentId = resComment.body.comment.id
364 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
367 it('Should not send a new comment notification if I comment my own video', async function () {
370 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
371 const uuid = resVideo.body.video.uuid
373 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
374 const commentId = resComment.body.comment.id
377 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
380 it('Should not send a new comment notification if the account is muted', async function () {
383 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
385 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
386 const uuid = resVideo.body.video.uuid
388 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
389 const commentId = resComment.body.comment.id
392 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
394 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
397 it('Should send a new comment notification after a local comment on my video', async function () {
400 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
401 const uuid = resVideo.body.video.uuid
403 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
404 const commentId = resComment.body.comment.id
407 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
410 it('Should send a new comment notification after a remote comment on my video', async function () {
413 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
414 const uuid = resVideo.body.video.uuid
416 await waitJobs(servers)
418 await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
420 await waitJobs(servers)
422 const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
423 expect(resComment.body.data).to.have.lengthOf(1)
424 const commentId = resComment.body.data[0].id
426 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
429 it('Should send a new comment notification after a local reply on my video', async function () {
432 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
433 const uuid = resVideo.body.video.uuid
435 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
436 const threadId = resThread.body.comment.id
438 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
439 const commentId = resComment.body.comment.id
442 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
445 it('Should send a new comment notification after a remote reply on my video', async function () {
448 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
449 const uuid = resVideo.body.video.uuid
450 await waitJobs(servers)
453 const resThread = await addVideoCommentThread(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, 'comment')
454 const threadId = resThread.body.comment.id
455 await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, threadId, 'reply')
458 await waitJobs(servers)
460 const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
461 expect(resThread.body.data).to.have.lengthOf(1)
462 const threadId = resThread.body.data[0].id
464 const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
465 const tree = resComments.body as VideoCommentThreadTree
467 expect(tree.children).to.have.lengthOf(1)
468 const commentId = tree.children[0].comment.id
470 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
474 describe('Mention notifications', function () {
475 let baseParams: CheckerBaseParams
481 socketNotifications: userNotifications,
482 token: userAccessToken
487 accessToken: servers[0].accessToken,
488 displayName: 'super root name'
493 accessToken: servers[1].accessToken,
494 displayName: 'super root 2 name'
498 it('Should not send a new mention comment notification if I mention the video owner', async function () {
501 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
502 const uuid = resVideo.body.video.uuid
504 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
505 const commentId = resComment.body.comment.id
508 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
511 it('Should not send a new mention comment notification if I mention myself', async function () {
514 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
515 const uuid = resVideo.body.video.uuid
517 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
518 const commentId = resComment.body.comment.id
521 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
524 it('Should not send a new mention notification if the account is muted', async function () {
527 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
529 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
530 const uuid = resVideo.body.video.uuid
532 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
533 const commentId = resComment.body.comment.id
536 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
538 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
541 it('Should not send a new mention notification if the remote account mention a local account', async function () {
544 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
545 const uuid = resVideo.body.video.uuid
547 await waitJobs(servers)
548 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
549 const threadId = resThread.body.comment.id
551 await waitJobs(servers)
552 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
555 it('Should send a new mention notification after local comments', async function () {
558 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
559 const uuid = resVideo.body.video.uuid
561 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
562 const threadId = resThread.body.comment.id
565 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
567 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
568 const commentId = resComment.body.comment.id
571 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
574 it('Should send a new mention notification after remote comments', async function () {
577 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
578 const uuid = resVideo.body.video.uuid
580 await waitJobs(servers)
581 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1')
582 const server2ThreadId = resThread.body.comment.id
584 await waitJobs(servers)
586 const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
587 expect(resThread2.body.data).to.have.lengthOf(1)
588 const server1ThreadId = resThread2.body.data[0].id
589 await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
591 const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001'
592 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text)
594 await waitJobs(servers)
596 const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
597 const tree = resComments.body as VideoCommentThreadTree
599 expect(tree.children).to.have.lengthOf(1)
600 const commentId = tree.children[0].comment.id
602 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
606 describe('Video abuse for moderators notification' , function () {
607 let baseParams: CheckerBaseParams
613 socketNotifications: adminNotifications,
614 token: servers[0].accessToken
618 it('Should send a notification to moderators on local video abuse', async function () {
621 const name = 'video for abuse ' + uuidv4()
622 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
623 const uuid = resVideo.body.video.uuid
625 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
627 await waitJobs(servers)
628 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
631 it('Should send a notification to moderators on remote video abuse', async function () {
634 const name = 'video for abuse ' + uuidv4()
635 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
636 const uuid = resVideo.body.video.uuid
638 await waitJobs(servers)
640 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
642 await waitJobs(servers)
643 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
647 describe('Video blacklist on my video', function () {
648 let baseParams: CheckerBaseParams
654 socketNotifications: userNotifications,
655 token: userAccessToken
659 it('Should send a notification to video owner on blacklist', async function () {
662 const name = 'video for abuse ' + uuidv4()
663 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
664 const uuid = resVideo.body.video.uuid
666 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
668 await waitJobs(servers)
669 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
672 it('Should send a notification to video owner on unblacklist', async function () {
675 const name = 'video for abuse ' + uuidv4()
676 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
677 const uuid = resVideo.body.video.uuid
679 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
681 await waitJobs(servers)
682 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
683 await waitJobs(servers)
686 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
690 describe('My video is published', function () {
691 let baseParams: CheckerBaseParams
697 socketNotifications: adminNotificationsServer2,
698 token: servers[1].accessToken
702 it('Should not send a notification if transcoding is not enabled', async function () {
705 const { name, uuid } = await uploadVideoByLocalAccount(servers)
706 await waitJobs(servers)
708 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
711 it('Should not send a notification if the wait transcoding is false', async function () {
714 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
715 await waitJobs(servers)
717 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
719 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
723 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
726 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
727 await waitJobs(servers)
729 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
732 it('Should send a notification with a transcoded video', async function () {
735 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
736 await waitJobs(servers)
738 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
741 it('Should send a notification when an imported video is transcoded', async function () {
744 const name = 'video import ' + uuidv4()
749 privacy: VideoPrivacy.PUBLIC,
750 targetUrl: getYoutubeVideoUrl(),
751 waitTranscoding: true
753 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
754 const uuid = res.body.video.uuid
756 await waitJobs(servers)
757 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
760 it('Should send a notification when the scheduled update has been proceeded', async function () {
764 let updateAt = new Date(new Date().getTime() + 2000)
767 privacy: VideoPrivacy.PRIVATE,
769 updateAt: updateAt.toISOString(),
770 privacy: VideoPrivacy.PUBLIC
773 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
776 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
779 it('Should not send a notification before the video is published', async function () {
782 let updateAt = new Date(new Date().getTime() + 100000)
785 privacy: VideoPrivacy.PRIVATE,
787 updateAt: updateAt.toISOString(),
788 privacy: VideoPrivacy.PUBLIC
791 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
794 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
798 describe('My video is imported', function () {
799 let baseParams: CheckerBaseParams
805 socketNotifications: adminNotifications,
806 token: servers[0].accessToken
810 it('Should send a notification when the video import failed', async function () {
813 const name = 'video import ' + uuidv4()
818 privacy: VideoPrivacy.PRIVATE,
819 targetUrl: getBadVideoUrl()
821 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
822 const uuid = res.body.video.uuid
824 await waitJobs(servers)
825 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
828 it('Should send a notification when the video import succeeded', async function () {
831 const name = 'video import ' + uuidv4()
836 privacy: VideoPrivacy.PRIVATE,
837 targetUrl: getYoutubeVideoUrl()
839 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
840 const uuid = res.body.video.uuid
842 await waitJobs(servers)
843 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
847 describe('New registration', function () {
848 let baseParams: CheckerBaseParams
854 socketNotifications: adminNotifications,
855 token: servers[0].accessToken
859 it('Should send a notification only to moderators when a user registers on the instance', async function () {
862 await registerUser(servers[0].url, 'user_45', 'password')
864 await waitJobs(servers)
866 await checkUserRegistered(baseParams, 'user_45', 'presence')
868 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
869 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
873 describe('New instance follower', function () {
874 let baseParams: CheckerBaseParams
880 socketNotifications: adminNotifications,
881 token: servers[0].accessToken
885 it('Should send a notification only to admin when there is a new instance follower', async function () {
888 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
890 await waitJobs(servers)
892 await checkNewInstanceFollower(baseParams, 'localhost:9003', 'presence')
894 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
895 await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:9003', 'absence')
899 describe('New actor follow', function () {
900 let baseParams: CheckerBaseParams
901 let myChannelName = 'super channel name'
902 let myUserName = 'super user name'
908 socketNotifications: userNotifications,
909 token: userAccessToken
914 accessToken: servers[0].accessToken,
915 displayName: 'super root name'
920 accessToken: userAccessToken,
921 displayName: myUserName
926 accessToken: servers[1].accessToken,
927 displayName: 'super root 2 name'
930 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
933 it('Should notify when a local channel is following one of our channel', async function () {
936 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
937 await waitJobs(servers)
939 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
941 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
944 it('Should notify when a remote channel is following one of our channel', async function () {
947 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
948 await waitJobs(servers)
950 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
952 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
955 it('Should notify when a local account is following one of our channel', async function () {
958 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001')
960 await waitJobs(servers)
962 await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
965 it('Should notify when a remote account is following one of our channel', async function () {
968 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001')
970 await waitJobs(servers)
972 await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
976 describe('Video-related notifications when video auto-blacklist is enabled', function () {
977 let userBaseParams: CheckerBaseParams
978 let adminBaseParamsServer1: CheckerBaseParams
979 let adminBaseParamsServer2: CheckerBaseParams
980 let videoUUID: string
981 let videoName: string
982 let currentCustomConfig: CustomConfig
986 adminBaseParamsServer1 = {
989 socketNotifications: adminNotifications,
990 token: servers[0].accessToken
993 adminBaseParamsServer2 = {
996 socketNotifications: adminNotificationsServer2,
997 token: servers[1].accessToken
1003 socketNotifications: userNotifications,
1004 token: userAccessToken
1007 const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken)
1008 currentCustomConfig = resCustomConfig.body
1009 const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, {
1018 // enable transcoding otherwise own publish notification after transcoding not expected
1019 autoBlacklistTestsCustomConfig.transcoding.enabled = true
1020 await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig)
1022 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
1023 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
1027 it('Should send notification to moderators on new video with auto-blacklist', async function () {
1030 videoName = 'video with auto-blacklist ' + uuidv4()
1031 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
1032 videoUUID = resVideo.body.video.uuid
1034 await waitJobs(servers)
1035 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
1038 it('Should not send video publish notification if auto-blacklisted', async function () {
1039 await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence')
1042 it('Should not send a local user subscription notification if auto-blacklisted', async function () {
1043 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence')
1046 it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
1047 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence')
1050 it('Should send video published and unblacklist after video unblacklisted', async function () {
1053 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID)
1055 await waitJobs(servers)
1057 // FIXME: Can't test as two notifications sent to same user and util only checks last one
1058 // One notification might be better anyways
1059 // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist')
1060 // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence')
1063 it('Should send a local user subscription notification after removed from blacklist', async function () {
1064 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence')
1067 it('Should send a remote user subscription notification after removed from blacklist', async function () {
1068 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence')
1071 it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
1074 let updateAt = new Date(new Date().getTime() + 100000)
1076 const name = 'video with auto-blacklist and future schedule ' + uuidv4()
1080 privacy: VideoPrivacy.PRIVATE,
1082 updateAt: updateAt.toISOString(),
1083 privacy: VideoPrivacy.PUBLIC
1087 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1088 const uuid = resVideo.body.video.uuid
1090 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
1092 await waitJobs(servers)
1093 await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
1095 // FIXME: Can't test absence as two notifications sent to same user and util only checks last one
1096 // One notification might be better anyways
1097 // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1099 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1100 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1103 it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
1107 let updateAt = new Date(new Date().getTime() + 2000)
1109 const name = 'video with schedule done and still auto-blacklisted ' + uuidv4()
1113 privacy: VideoPrivacy.PRIVATE,
1115 updateAt: updateAt.toISOString(),
1116 privacy: VideoPrivacy.PUBLIC
1120 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1121 const uuid = resVideo.body.video.uuid
1124 await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1125 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1126 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1129 it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
1132 const name = 'video without auto-blacklist ' + uuidv4()
1134 // admin with blacklist right will not be auto-blacklisted
1135 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name })
1136 const uuid = resVideo.body.video.uuid
1138 await waitJobs(servers)
1139 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
1143 await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig)
1145 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
1146 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
1150 describe('Mark as read', function () {
1151 it('Should mark as read some notifications', async function () {
1152 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
1153 const ids = res.body.data.map(n => n.id)
1155 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
1158 it('Should have the notifications marked as read', async function () {
1159 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
1161 const notifications = res.body.data as UserNotification[]
1162 expect(notifications[ 0 ].read).to.be.false
1163 expect(notifications[ 1 ].read).to.be.false
1164 expect(notifications[ 2 ].read).to.be.true
1165 expect(notifications[ 3 ].read).to.be.true
1166 expect(notifications[ 4 ].read).to.be.true
1167 expect(notifications[ 5 ].read).to.be.false
1170 it('Should only list read notifications', async function () {
1171 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
1173 const notifications = res.body.data as UserNotification[]
1174 for (const notification of notifications) {
1175 expect(notification.read).to.be.true
1179 it('Should only list unread notifications', async function () {
1180 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1182 const notifications = res.body.data as UserNotification[]
1183 for (const notification of notifications) {
1184 expect(notification.read).to.be.false
1188 it('Should mark as read all notifications', async function () {
1189 await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
1191 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1193 expect(res.body.total).to.equal(0)
1194 expect(res.body.data).to.have.lengthOf(0)
1198 describe('Notification settings', function () {
1199 let baseParams: CheckerBaseParams
1205 socketNotifications: userNotifications,
1206 token: userAccessToken
1210 it('Should not have notifications', async function () {
1213 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1214 newVideoFromSubscription: UserNotificationSettingValue.NONE
1218 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1219 const info = res.body as User
1220 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
1223 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1225 const check = { web: true, mail: true }
1226 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1229 it('Should only have web notifications', async function () {
1232 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1233 newVideoFromSubscription: UserNotificationSettingValue.WEB
1237 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1238 const info = res.body as User
1239 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
1242 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1245 const check = { mail: true, web: false }
1246 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1250 const check = { mail: false, web: true }
1251 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1255 it('Should only have mail notifications', async function () {
1258 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1259 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
1263 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1264 const info = res.body as User
1265 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
1268 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1271 const check = { mail: false, web: true }
1272 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1276 const check = { mail: true, web: false }
1277 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1281 it('Should have email and web notifications', async function () {
1284 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1285 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1289 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1290 const info = res.body as User
1291 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
1292 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1296 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1298 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
1302 after(async function () {
1303 MockSmtpServer.Instance.kill()
1305 await cleanupTests(servers)