1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
10 flushAndRunMultipleServers,
14 getVideoCommentThreads,
15 getVideoThreadComments,
18 removeVideoFromBlacklist,
19 reportVideoAbuse, unfollow,
20 updateCustomConfig, updateCustomSubConfig,
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 checkAutoInstanceFollowing
50 } from '../../../../shared/extra-utils/users/user-notifications'
54 UserNotificationSetting,
55 UserNotificationSettingValue,
57 } from '../../../../shared/models/users'
58 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
59 import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions'
60 import { VideoPrivacy } from '../../../../shared/models/videos'
61 import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
62 import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
63 import * as uuidv4 from 'uuid/v4'
64 import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/extra-utils/users/blocklist'
65 import { CustomConfig } from '../../../../shared/models/server'
66 import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
68 const expect = chai.expect
70 async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) {
71 const name = 'remote video ' + uuidv4()
73 const data = Object.assign({ name }, additionalParams)
74 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data)
76 await waitJobs(servers)
78 return { uuid: res.body.video.uuid, name }
81 async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) {
82 const name = 'local video ' + uuidv4()
84 const data = Object.assign({ name }, additionalParams)
85 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data)
87 await waitJobs(servers)
89 return { uuid: res.body.video.uuid, name }
92 describe('Test users notifications', function () {
93 let servers: ServerInfo[] = []
94 let userAccessToken: string
95 let userNotifications: UserNotification[] = []
96 let adminNotifications: UserNotification[] = []
97 let adminNotificationsServer2: UserNotification[] = []
98 const emails: object[] = []
101 const allNotificationSettings: UserNotificationSetting = {
102 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
103 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
104 videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
105 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
106 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
107 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
108 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
109 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
110 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
111 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
112 newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
113 autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
116 before(async function () {
119 const port = await MockSmtpServer.Instance.collectEmails(emails)
121 const overrideConfig = {
123 hostname: 'localhost',
127 servers = await flushAndRunMultipleServers(3, overrideConfig)
129 // Get the access tokens
130 await setAccessTokensToServers(servers)
132 // Server 1 and server 2 follow each other
133 await doubleFollow(servers[0], servers[1])
135 await waitJobs(servers)
139 password: 'super password'
142 url: servers[ 0 ].url,
143 accessToken: servers[ 0 ].accessToken,
144 username: user.username,
145 password: user.password,
146 videoQuota: 10 * 1000 * 1000
148 userAccessToken = await userLogin(servers[0], user)
150 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
151 await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
152 await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
155 const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
156 socket.on('new-notification', n => userNotifications.push(n))
159 const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
160 socket.on('new-notification', n => adminNotifications.push(n))
163 const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
164 socket.on('new-notification', n => adminNotificationsServer2.push(n))
168 const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
169 channelId = resChannel.body.videoChannels[0].id
173 describe('New video from my subscription notification', function () {
174 let baseParams: CheckerBaseParams
180 socketNotifications: userNotifications,
181 token: userAccessToken
185 it('Should not send notifications if the user does not follow the video publisher', async function () {
188 await uploadVideoByLocalAccount(servers)
190 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
191 expect(notification).to.be.undefined
193 expect(emails).to.have.lengthOf(0)
194 expect(userNotifications).to.have.lengthOf(0)
197 it('Should send a new video notification if the user follows the local video publisher', async function () {
200 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port)
201 await waitJobs(servers)
203 const { name, uuid } = await uploadVideoByLocalAccount(servers)
204 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
207 it('Should send a new video notification from a remote account', async function () {
208 this.timeout(50000) // Server 2 has transcoding enabled
210 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[1].port)
211 await waitJobs(servers)
213 const { name, uuid } = await uploadVideoByRemoteAccount(servers)
214 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
217 it('Should send a new video notification on a scheduled publication', async function () {
221 let updateAt = new Date(new Date().getTime() + 2000)
224 privacy: VideoPrivacy.PRIVATE,
226 updateAt: updateAt.toISOString(),
227 privacy: VideoPrivacy.PUBLIC
230 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
233 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
236 it('Should send a new video notification on a remote scheduled publication', async function () {
240 let updateAt = new Date(new Date().getTime() + 2000)
243 privacy: VideoPrivacy.PRIVATE,
245 updateAt: updateAt.toISOString(),
246 privacy: VideoPrivacy.PUBLIC
249 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
250 await waitJobs(servers)
253 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
256 it('Should not send a notification before the video is published', async function () {
259 let updateAt = new Date(new Date().getTime() + 1000000)
262 privacy: VideoPrivacy.PRIVATE,
264 updateAt: updateAt.toISOString(),
265 privacy: VideoPrivacy.PUBLIC
268 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
271 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
274 it('Should send a new video notification when a video becomes public', async function () {
277 const data = { privacy: VideoPrivacy.PRIVATE }
278 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
280 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
282 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
285 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
288 it('Should send a new video notification when a remote video becomes public', async function () {
291 const data = { privacy: VideoPrivacy.PRIVATE }
292 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
294 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
296 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
298 await waitJobs(servers)
299 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
302 it('Should not send a new video notification when a video becomes unlisted', async function () {
305 const data = { privacy: VideoPrivacy.PRIVATE }
306 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
308 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
310 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
313 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
316 const data = { privacy: VideoPrivacy.PRIVATE }
317 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
319 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
321 await waitJobs(servers)
322 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
325 it('Should send a new video notification after a video import', async function () {
328 const name = 'video import ' + uuidv4()
333 privacy: VideoPrivacy.PUBLIC,
334 targetUrl: getYoutubeVideoUrl()
336 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
337 const uuid = res.body.video.uuid
339 await waitJobs(servers)
341 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
345 describe('Comment on my video notifications', function () {
346 let baseParams: CheckerBaseParams
352 socketNotifications: userNotifications,
353 token: userAccessToken
357 it('Should not send a new comment notification after a comment on another video', async function () {
360 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
361 const uuid = resVideo.body.video.uuid
363 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, 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 I comment my own video', async function () {
373 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
374 const uuid = resVideo.body.video.uuid
376 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
377 const commentId = resComment.body.comment.id
380 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
383 it('Should not send a new comment notification if the account is muted', async function () {
386 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
388 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
389 const uuid = resVideo.body.video.uuid
391 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
392 const commentId = resComment.body.comment.id
395 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
397 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
400 it('Should send a new comment notification after a local 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 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
407 const commentId = resComment.body.comment.id
410 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
413 it('Should send a new comment notification after a remote comment on my video', async function () {
416 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
417 const uuid = resVideo.body.video.uuid
419 await waitJobs(servers)
421 await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
423 await waitJobs(servers)
425 const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
426 expect(resComment.body.data).to.have.lengthOf(1)
427 const commentId = resComment.body.data[0].id
429 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
432 it('Should send a new comment notification after a local reply on my video', async function () {
435 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
436 const uuid = resVideo.body.video.uuid
438 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
439 const threadId = resThread.body.comment.id
441 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
442 const commentId = resComment.body.comment.id
445 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
448 it('Should send a new comment notification after a remote reply on my video', async function () {
451 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
452 const uuid = resVideo.body.video.uuid
453 await waitJobs(servers)
456 const resThread = await addVideoCommentThread(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, 'comment')
457 const threadId = resThread.body.comment.id
458 await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, threadId, 'reply')
461 await waitJobs(servers)
463 const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
464 expect(resThread.body.data).to.have.lengthOf(1)
465 const threadId = resThread.body.data[0].id
467 const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
468 const tree = resComments.body as VideoCommentThreadTree
470 expect(tree.children).to.have.lengthOf(1)
471 const commentId = tree.children[0].comment.id
473 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
477 describe('Mention notifications', function () {
478 let baseParams: CheckerBaseParams
484 socketNotifications: userNotifications,
485 token: userAccessToken
490 accessToken: servers[0].accessToken,
491 displayName: 'super root name'
496 accessToken: servers[1].accessToken,
497 displayName: 'super root 2 name'
501 it('Should not send a new mention comment notification if I mention the video owner', async function () {
504 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { 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')
514 it('Should not send a new mention comment notification if I mention myself', async function () {
517 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
518 const uuid = resVideo.body.video.uuid
520 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
521 const commentId = resComment.body.comment.id
524 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
527 it('Should not send a new mention notification if the account is muted', async function () {
530 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
532 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
533 const uuid = resVideo.body.video.uuid
535 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
536 const commentId = resComment.body.comment.id
539 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
541 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
544 it('Should not send a new mention notification if the remote account mention a local account', async function () {
547 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
548 const uuid = resVideo.body.video.uuid
550 await waitJobs(servers)
551 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
552 const threadId = resThread.body.comment.id
554 await waitJobs(servers)
555 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
558 it('Should send a new mention notification after local comments', async function () {
561 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
562 const uuid = resVideo.body.video.uuid
564 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
565 const threadId = resThread.body.comment.id
568 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
570 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
571 const commentId = resComment.body.comment.id
574 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
577 it('Should send a new mention notification after remote comments', async function () {
580 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
581 const uuid = resVideo.body.video.uuid
583 await waitJobs(servers)
585 const text1 = `hello @user_1@localhost:${servers[ 0 ].port} 1`
586 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, text1)
587 const server2ThreadId = resThread.body.comment.id
589 await waitJobs(servers)
591 const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
592 expect(resThread2.body.data).to.have.lengthOf(1)
593 const server1ThreadId = resThread2.body.data[0].id
594 await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
596 const text2 = `@user_1@localhost:${servers[ 0 ].port} hello 2 @root@localhost:${servers[ 0 ].port}`
597 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text2)
599 await waitJobs(servers)
601 const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
602 const tree = resComments.body as VideoCommentThreadTree
604 expect(tree.children).to.have.lengthOf(1)
605 const commentId = tree.children[0].comment.id
607 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
611 describe('Video abuse for moderators notification' , function () {
612 let baseParams: CheckerBaseParams
618 socketNotifications: adminNotifications,
619 token: servers[0].accessToken
623 it('Should send a notification to moderators on local video abuse', async function () {
626 const name = 'video for abuse ' + uuidv4()
627 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
628 const uuid = resVideo.body.video.uuid
630 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
632 await waitJobs(servers)
633 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
636 it('Should send a notification to moderators on remote video abuse', async function () {
639 const name = 'video for abuse ' + uuidv4()
640 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
641 const uuid = resVideo.body.video.uuid
643 await waitJobs(servers)
645 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
647 await waitJobs(servers)
648 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
652 describe('Video blacklist on my video', function () {
653 let baseParams: CheckerBaseParams
659 socketNotifications: userNotifications,
660 token: userAccessToken
664 it('Should send a notification to video owner on blacklist', async function () {
667 const name = 'video for abuse ' + uuidv4()
668 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
669 const uuid = resVideo.body.video.uuid
671 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
673 await waitJobs(servers)
674 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
677 it('Should send a notification to video owner on unblacklist', async function () {
680 const name = 'video for abuse ' + uuidv4()
681 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
682 const uuid = resVideo.body.video.uuid
684 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
686 await waitJobs(servers)
687 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
688 await waitJobs(servers)
691 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
695 describe('My video is published', function () {
696 let baseParams: CheckerBaseParams
702 socketNotifications: adminNotificationsServer2,
703 token: servers[1].accessToken
707 it('Should not send a notification if transcoding is not enabled', async function () {
710 const { name, uuid } = await uploadVideoByLocalAccount(servers)
711 await waitJobs(servers)
713 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
716 it('Should not send a notification if the wait transcoding is false', async function () {
719 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
720 await waitJobs(servers)
722 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
724 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
728 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
731 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
732 await waitJobs(servers)
734 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
737 it('Should send a notification with a transcoded video', async function () {
740 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
741 await waitJobs(servers)
743 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
746 it('Should send a notification when an imported video is transcoded', async function () {
749 const name = 'video import ' + uuidv4()
754 privacy: VideoPrivacy.PUBLIC,
755 targetUrl: getYoutubeVideoUrl(),
756 waitTranscoding: true
758 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
759 const uuid = res.body.video.uuid
761 await waitJobs(servers)
762 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
765 it('Should send a notification when the scheduled update has been proceeded', async function () {
769 let updateAt = new Date(new Date().getTime() + 2000)
772 privacy: VideoPrivacy.PRIVATE,
774 updateAt: updateAt.toISOString(),
775 privacy: VideoPrivacy.PUBLIC
778 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
781 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
784 it('Should not send a notification before the video is published', async function () {
787 let updateAt = new Date(new Date().getTime() + 1000000)
790 privacy: VideoPrivacy.PRIVATE,
792 updateAt: updateAt.toISOString(),
793 privacy: VideoPrivacy.PUBLIC
796 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
799 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
803 describe('My video is imported', function () {
804 let baseParams: CheckerBaseParams
810 socketNotifications: adminNotifications,
811 token: servers[0].accessToken
815 it('Should send a notification when the video import failed', async function () {
818 const name = 'video import ' + uuidv4()
823 privacy: VideoPrivacy.PRIVATE,
824 targetUrl: getBadVideoUrl()
826 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
827 const uuid = res.body.video.uuid
829 await waitJobs(servers)
830 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
833 it('Should send a notification when the video import succeeded', async function () {
836 const name = 'video import ' + uuidv4()
841 privacy: VideoPrivacy.PRIVATE,
842 targetUrl: getYoutubeVideoUrl()
844 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
845 const uuid = res.body.video.uuid
847 await waitJobs(servers)
848 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
852 describe('New registration', function () {
853 let baseParams: CheckerBaseParams
859 socketNotifications: adminNotifications,
860 token: servers[0].accessToken
864 it('Should send a notification only to moderators when a user registers on the instance', async function () {
867 await registerUser(servers[0].url, 'user_45', 'password')
869 await waitJobs(servers)
871 await checkUserRegistered(baseParams, 'user_45', 'presence')
873 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
874 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
878 describe('New instance follower', function () {
879 let baseParams: CheckerBaseParams
885 socketNotifications: adminNotifications,
886 token: servers[0].accessToken
890 it('Should send a notification only to admin when there is a new instance follower', async function () {
893 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
895 await waitJobs(servers)
897 await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence')
899 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
900 await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence')
903 it('Should send a notification on auto follow back', async function () {
906 await unfollow(servers[2].url, servers[2].accessToken, servers[0])
907 await waitJobs(servers)
912 autoFollowBack: { enabled: true }
916 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
918 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
920 await waitJobs(servers)
922 const followerHost = servers[0].host
923 const followingHost = servers[2].host
924 await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence')
926 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
927 await checkAutoInstanceFollowing(immutableAssign(baseParams, userOverride), followerHost, followingHost, 'absence')
929 config.followings.instance.autoFollowBack.enabled = false
930 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
934 describe('New actor follow', function () {
935 let baseParams: CheckerBaseParams
936 let myChannelName = 'super channel name'
937 let myUserName = 'super user name'
943 socketNotifications: userNotifications,
944 token: userAccessToken
949 accessToken: servers[0].accessToken,
950 displayName: 'super root name'
955 accessToken: userAccessToken,
956 displayName: myUserName
961 accessToken: servers[1].accessToken,
962 displayName: 'super root 2 name'
965 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
968 it('Should notify when a local channel is following one of our channel', async function () {
971 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
972 await waitJobs(servers)
974 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
976 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
979 it('Should notify when a remote channel is following one of our channel', async function () {
982 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
983 await waitJobs(servers)
985 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
987 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
990 it('Should notify when a local account is following one of our channel', async function () {
993 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port)
995 await waitJobs(servers)
997 await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
1000 it('Should notify when a remote account is following one of our channel', async function () {
1003 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port)
1005 await waitJobs(servers)
1007 await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
1011 describe('Video-related notifications when video auto-blacklist is enabled', function () {
1012 let userBaseParams: CheckerBaseParams
1013 let adminBaseParamsServer1: CheckerBaseParams
1014 let adminBaseParamsServer2: CheckerBaseParams
1015 let videoUUID: string
1016 let videoName: string
1017 let currentCustomConfig: CustomConfig
1019 before(async () => {
1021 adminBaseParamsServer1 = {
1024 socketNotifications: adminNotifications,
1025 token: servers[0].accessToken
1028 adminBaseParamsServer2 = {
1031 socketNotifications: adminNotificationsServer2,
1032 token: servers[1].accessToken
1038 socketNotifications: userNotifications,
1039 token: userAccessToken
1042 const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken)
1043 currentCustomConfig = resCustomConfig.body
1044 const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, {
1053 // enable transcoding otherwise own publish notification after transcoding not expected
1054 autoBlacklistTestsCustomConfig.transcoding.enabled = true
1055 await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig)
1057 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
1058 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
1062 it('Should send notification to moderators on new video with auto-blacklist', async function () {
1065 videoName = 'video with auto-blacklist ' + uuidv4()
1066 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
1067 videoUUID = resVideo.body.video.uuid
1069 await waitJobs(servers)
1070 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
1073 it('Should not send video publish notification if auto-blacklisted', async function () {
1074 await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence')
1077 it('Should not send a local user subscription notification if auto-blacklisted', async function () {
1078 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence')
1081 it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
1082 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence')
1085 it('Should send video published and unblacklist after video unblacklisted', async function () {
1088 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID)
1090 await waitJobs(servers)
1092 // FIXME: Can't test as two notifications sent to same user and util only checks last one
1093 // One notification might be better anyways
1094 // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist')
1095 // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence')
1098 it('Should send a local user subscription notification after removed from blacklist', async function () {
1099 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence')
1102 it('Should send a remote user subscription notification after removed from blacklist', async function () {
1103 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence')
1106 it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
1109 let updateAt = new Date(new Date().getTime() + 1000000)
1111 const name = 'video with auto-blacklist and future schedule ' + uuidv4()
1115 privacy: VideoPrivacy.PRIVATE,
1117 updateAt: updateAt.toISOString(),
1118 privacy: VideoPrivacy.PUBLIC
1122 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1123 const uuid = resVideo.body.video.uuid
1125 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
1127 await waitJobs(servers)
1128 await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
1130 // FIXME: Can't test absence as two notifications sent to same user and util only checks last one
1131 // One notification might be better anyways
1132 // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1134 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1135 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1138 it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
1142 let updateAt = new Date(new Date().getTime() + 2000)
1144 const name = 'video with schedule done and still auto-blacklisted ' + uuidv4()
1148 privacy: VideoPrivacy.PRIVATE,
1150 updateAt: updateAt.toISOString(),
1151 privacy: VideoPrivacy.PUBLIC
1155 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1156 const uuid = resVideo.body.video.uuid
1159 await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1160 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1161 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1164 it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
1167 const name = 'video without auto-blacklist ' + uuidv4()
1169 // admin with blacklist right will not be auto-blacklisted
1170 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name })
1171 const uuid = resVideo.body.video.uuid
1173 await waitJobs(servers)
1174 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
1178 await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig)
1180 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
1181 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
1185 describe('Mark as read', function () {
1186 it('Should mark as read some notifications', async function () {
1187 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
1188 const ids = res.body.data.map(n => n.id)
1190 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
1193 it('Should have the notifications marked as read', async function () {
1194 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
1196 const notifications = res.body.data as UserNotification[]
1197 expect(notifications[ 0 ].read).to.be.false
1198 expect(notifications[ 1 ].read).to.be.false
1199 expect(notifications[ 2 ].read).to.be.true
1200 expect(notifications[ 3 ].read).to.be.true
1201 expect(notifications[ 4 ].read).to.be.true
1202 expect(notifications[ 5 ].read).to.be.false
1205 it('Should only list read notifications', async function () {
1206 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
1208 const notifications = res.body.data as UserNotification[]
1209 for (const notification of notifications) {
1210 expect(notification.read).to.be.true
1214 it('Should only list unread notifications', async function () {
1215 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1217 const notifications = res.body.data as UserNotification[]
1218 for (const notification of notifications) {
1219 expect(notification.read).to.be.false
1223 it('Should mark as read all notifications', async function () {
1224 await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
1226 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1228 expect(res.body.total).to.equal(0)
1229 expect(res.body.data).to.have.lengthOf(0)
1233 describe('Notification settings', function () {
1234 let baseParams: CheckerBaseParams
1240 socketNotifications: userNotifications,
1241 token: userAccessToken
1245 it('Should not have notifications', async function () {
1248 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1249 newVideoFromSubscription: UserNotificationSettingValue.NONE
1253 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1254 const info = res.body as User
1255 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
1258 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1260 const check = { web: true, mail: true }
1261 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1264 it('Should only have web notifications', async function () {
1267 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1268 newVideoFromSubscription: UserNotificationSettingValue.WEB
1272 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1273 const info = res.body as User
1274 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
1277 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1280 const check = { mail: true, web: false }
1281 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1285 const check = { mail: false, web: true }
1286 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1290 it('Should only have mail notifications', async function () {
1293 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1294 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
1298 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1299 const info = res.body as User
1300 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
1303 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1306 const check = { mail: false, web: true }
1307 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1311 const check = { mail: true, web: false }
1312 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1316 it('Should have email and web notifications', async function () {
1319 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1320 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1324 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1325 const info = res.body as User
1326 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
1327 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1331 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1333 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
1337 after(async function () {
1338 MockSmtpServer.Instance.kill()
1340 await cleanupTests(servers)