1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
9 flushAndRunMultipleServers,
14 removeVideoFromBlacklist,
22 updateCustomConfig, getVideoThreadComments, getVideoCommentThreads, follow, cleanupTests
23 } from '../../../../shared/extra-utils'
24 import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
25 import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
26 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
27 import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io'
31 checkMyVideoImportIsFinished,
33 checkNewBlacklistOnMyVideo,
34 checkNewCommentOnMyVideo,
35 checkNewVideoAbuseForModerators,
36 checkVideoAutoBlacklistForModerators,
37 checkNewVideoFromSubscription,
39 checkVideoIsPublished,
42 markAsReadNotifications,
43 updateMyNotificationSettings,
44 markAsReadAllNotifications, checkNewInstanceFollower
45 } from '../../../../shared/extra-utils/users/user-notifications'
49 UserNotificationSetting,
50 UserNotificationSettingValue,
52 } from '../../../../shared/models/users'
53 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
54 import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions'
55 import { VideoPrivacy } from '../../../../shared/models/videos'
56 import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
57 import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
58 import * as uuidv4 from 'uuid/v4'
59 import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/extra-utils/users/blocklist'
60 import { CustomConfig } from '../../../../shared/models/server'
61 import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
63 const expect = chai.expect
65 async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) {
66 const name = 'remote video ' + uuidv4()
68 const data = Object.assign({ name }, additionalParams)
69 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data)
71 await waitJobs(servers)
73 return { uuid: res.body.video.uuid, name }
76 async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) {
77 const name = 'local video ' + uuidv4()
79 const data = Object.assign({ name }, additionalParams)
80 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data)
82 await waitJobs(servers)
84 return { uuid: res.body.video.uuid, name }
87 describe('Test users notifications', function () {
88 let servers: ServerInfo[] = []
89 let userAccessToken: string
90 let userNotifications: UserNotification[] = []
91 let adminNotifications: UserNotification[] = []
92 let adminNotificationsServer2: UserNotification[] = []
93 const emails: object[] = []
96 const allNotificationSettings: UserNotificationSetting = {
97 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
98 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
99 videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
100 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
101 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
102 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
103 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
104 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
105 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
106 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
107 newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
110 before(async function () {
113 await MockSmtpServer.Instance.collectEmails(emails)
115 const overrideConfig = {
117 hostname: 'localhost'
120 servers = await flushAndRunMultipleServers(3, 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'
135 url: servers[ 0 ].url,
136 accessToken: servers[ 0 ].accessToken,
137 username: user.username,
138 password: user.password,
139 videoQuota: 10 * 1000 * 1000
141 userAccessToken = await userLogin(servers[0], user)
143 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
144 await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
145 await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
148 const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
149 socket.on('new-notification', n => userNotifications.push(n))
152 const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
153 socket.on('new-notification', n => adminNotifications.push(n))
156 const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
157 socket.on('new-notification', n => adminNotificationsServer2.push(n))
161 const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
162 channelId = resChannel.body.videoChannels[0].id
166 describe('New video from my subscription notification', function () {
167 let baseParams: CheckerBaseParams
173 socketNotifications: userNotifications,
174 token: userAccessToken
178 it('Should not send notifications if the user does not follow the video publisher', async function () {
181 await uploadVideoByLocalAccount(servers)
183 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
184 expect(notification).to.be.undefined
186 expect(emails).to.have.lengthOf(0)
187 expect(userNotifications).to.have.lengthOf(0)
190 it('Should send a new video notification if the user follows the local video publisher', async function () {
193 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
194 await waitJobs(servers)
196 const { name, uuid } = await uploadVideoByLocalAccount(servers)
197 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
200 it('Should send a new video notification from a remote account', async function () {
201 this.timeout(50000) // Server 2 has transcoding enabled
203 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002')
204 await waitJobs(servers)
206 const { name, uuid } = await uploadVideoByRemoteAccount(servers)
207 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
210 it('Should send a new video notification on a scheduled publication', async function () {
214 let updateAt = new Date(new Date().getTime() + 2000)
217 privacy: VideoPrivacy.PRIVATE,
219 updateAt: updateAt.toISOString(),
220 privacy: VideoPrivacy.PUBLIC
223 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
226 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
229 it('Should send a new video notification on a remote scheduled publication', async function () {
233 let updateAt = new Date(new Date().getTime() + 2000)
236 privacy: VideoPrivacy.PRIVATE,
238 updateAt: updateAt.toISOString(),
239 privacy: VideoPrivacy.PUBLIC
242 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
243 await waitJobs(servers)
246 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
249 it('Should not send a notification before the video is published', async function () {
252 let updateAt = new Date(new Date().getTime() + 1000000)
255 privacy: VideoPrivacy.PRIVATE,
257 updateAt: updateAt.toISOString(),
258 privacy: VideoPrivacy.PUBLIC
261 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
264 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
267 it('Should send a new video notification when a video becomes public', async function () {
270 const data = { privacy: VideoPrivacy.PRIVATE }
271 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
273 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
275 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
278 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
281 it('Should send a new video notification when a remote video becomes public', async function () {
284 const data = { privacy: VideoPrivacy.PRIVATE }
285 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
287 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
289 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
291 await waitJobs(servers)
292 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
295 it('Should not send a new video notification when a video becomes unlisted', async function () {
298 const data = { privacy: VideoPrivacy.PRIVATE }
299 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
301 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
303 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
306 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
309 const data = { privacy: VideoPrivacy.PRIVATE }
310 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
312 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
314 await waitJobs(servers)
315 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
318 it('Should send a new video notification after a video import', async function () {
321 const name = 'video import ' + uuidv4()
326 privacy: VideoPrivacy.PUBLIC,
327 targetUrl: getYoutubeVideoUrl()
329 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
330 const uuid = res.body.video.uuid
332 await waitJobs(servers)
334 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
338 describe('Comment on my video notifications', function () {
339 let baseParams: CheckerBaseParams
345 socketNotifications: userNotifications,
346 token: userAccessToken
350 it('Should not send a new comment notification after a comment on another video', async function () {
353 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
354 const uuid = resVideo.body.video.uuid
356 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
357 const commentId = resComment.body.comment.id
360 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
363 it('Should not send a new comment notification if I comment my own video', async function () {
366 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
367 const uuid = resVideo.body.video.uuid
369 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
370 const commentId = resComment.body.comment.id
373 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
376 it('Should not send a new comment notification if the account is muted', async function () {
379 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
381 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
382 const uuid = resVideo.body.video.uuid
384 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
385 const commentId = resComment.body.comment.id
388 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
390 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
393 it('Should send a new comment notification after a local comment on my video', async function () {
396 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
397 const uuid = resVideo.body.video.uuid
399 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
400 const commentId = resComment.body.comment.id
403 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
406 it('Should send a new comment notification after a remote comment on my video', async function () {
409 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
410 const uuid = resVideo.body.video.uuid
412 await waitJobs(servers)
414 await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
416 await waitJobs(servers)
418 const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
419 expect(resComment.body.data).to.have.lengthOf(1)
420 const commentId = resComment.body.data[0].id
422 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
425 it('Should send a new comment notification after a local reply on my video', async function () {
428 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
429 const uuid = resVideo.body.video.uuid
431 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
432 const threadId = resThread.body.comment.id
434 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
435 const commentId = resComment.body.comment.id
438 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
441 it('Should send a new comment notification after a remote reply on my video', async function () {
444 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
445 const uuid = resVideo.body.video.uuid
446 await waitJobs(servers)
449 const resThread = await addVideoCommentThread(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, 'comment')
450 const threadId = resThread.body.comment.id
451 await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, threadId, 'reply')
454 await waitJobs(servers)
456 const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
457 expect(resThread.body.data).to.have.lengthOf(1)
458 const threadId = resThread.body.data[0].id
460 const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
461 const tree = resComments.body as VideoCommentThreadTree
463 expect(tree.children).to.have.lengthOf(1)
464 const commentId = tree.children[0].comment.id
466 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
470 describe('Mention notifications', function () {
471 let baseParams: CheckerBaseParams
477 socketNotifications: userNotifications,
478 token: userAccessToken
483 accessToken: servers[0].accessToken,
484 displayName: 'super root name'
489 accessToken: servers[1].accessToken,
490 displayName: 'super root 2 name'
494 it('Should not send a new mention comment notification if I mention the video owner', async function () {
497 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
498 const uuid = resVideo.body.video.uuid
500 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
501 const commentId = resComment.body.comment.id
504 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
507 it('Should not send a new mention comment notification if I mention myself', async function () {
510 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
511 const uuid = resVideo.body.video.uuid
513 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
514 const commentId = resComment.body.comment.id
517 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
520 it('Should not send a new mention notification if the account is muted', async function () {
523 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
525 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
526 const uuid = resVideo.body.video.uuid
528 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
529 const commentId = resComment.body.comment.id
532 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
534 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
537 it('Should not send a new mention notification if the remote account mention a local account', async function () {
540 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
541 const uuid = resVideo.body.video.uuid
543 await waitJobs(servers)
544 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
545 const threadId = resThread.body.comment.id
547 await waitJobs(servers)
548 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
551 it('Should send a new mention notification after local comments', async function () {
554 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
555 const uuid = resVideo.body.video.uuid
557 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
558 const threadId = resThread.body.comment.id
561 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
563 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
564 const commentId = resComment.body.comment.id
567 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
570 it('Should send a new mention notification after remote comments', async function () {
573 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
574 const uuid = resVideo.body.video.uuid
576 await waitJobs(servers)
577 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1')
578 const server2ThreadId = resThread.body.comment.id
580 await waitJobs(servers)
582 const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
583 expect(resThread2.body.data).to.have.lengthOf(1)
584 const server1ThreadId = resThread2.body.data[0].id
585 await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
587 const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001'
588 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text)
590 await waitJobs(servers)
592 const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
593 const tree = resComments.body as VideoCommentThreadTree
595 expect(tree.children).to.have.lengthOf(1)
596 const commentId = tree.children[0].comment.id
598 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
602 describe('Video abuse for moderators notification' , function () {
603 let baseParams: CheckerBaseParams
609 socketNotifications: adminNotifications,
610 token: servers[0].accessToken
614 it('Should send a notification to moderators on local video abuse', async function () {
617 const name = 'video for abuse ' + uuidv4()
618 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
619 const uuid = resVideo.body.video.uuid
621 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
623 await waitJobs(servers)
624 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
627 it('Should send a notification to moderators on remote video abuse', async function () {
630 const name = 'video for abuse ' + uuidv4()
631 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
632 const uuid = resVideo.body.video.uuid
634 await waitJobs(servers)
636 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
638 await waitJobs(servers)
639 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
643 describe('Video blacklist on my video', function () {
644 let baseParams: CheckerBaseParams
650 socketNotifications: userNotifications,
651 token: userAccessToken
655 it('Should send a notification to video owner on blacklist', async function () {
658 const name = 'video for abuse ' + uuidv4()
659 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
660 const uuid = resVideo.body.video.uuid
662 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
664 await waitJobs(servers)
665 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
668 it('Should send a notification to video owner on unblacklist', async function () {
671 const name = 'video for abuse ' + uuidv4()
672 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
673 const uuid = resVideo.body.video.uuid
675 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
677 await waitJobs(servers)
678 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
679 await waitJobs(servers)
682 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
686 describe('My video is published', function () {
687 let baseParams: CheckerBaseParams
693 socketNotifications: adminNotificationsServer2,
694 token: servers[1].accessToken
698 it('Should not send a notification if transcoding is not enabled', async function () {
701 const { name, uuid } = await uploadVideoByLocalAccount(servers)
702 await waitJobs(servers)
704 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
707 it('Should not send a notification if the wait transcoding is false', async function () {
710 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
711 await waitJobs(servers)
713 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
715 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
719 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
722 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
723 await waitJobs(servers)
725 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
728 it('Should send a notification with a transcoded video', async function () {
731 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
732 await waitJobs(servers)
734 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
737 it('Should send a notification when an imported video is transcoded', async function () {
740 const name = 'video import ' + uuidv4()
745 privacy: VideoPrivacy.PUBLIC,
746 targetUrl: getYoutubeVideoUrl(),
747 waitTranscoding: true
749 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
750 const uuid = res.body.video.uuid
752 await waitJobs(servers)
753 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
756 it('Should send a notification when the scheduled update has been proceeded', async function () {
760 let updateAt = new Date(new Date().getTime() + 2000)
763 privacy: VideoPrivacy.PRIVATE,
765 updateAt: updateAt.toISOString(),
766 privacy: VideoPrivacy.PUBLIC
769 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
772 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
775 it('Should not send a notification before the video is published', async function () {
778 let updateAt = new Date(new Date().getTime() + 100000)
781 privacy: VideoPrivacy.PRIVATE,
783 updateAt: updateAt.toISOString(),
784 privacy: VideoPrivacy.PUBLIC
787 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
790 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
794 describe('My video is imported', function () {
795 let baseParams: CheckerBaseParams
801 socketNotifications: adminNotifications,
802 token: servers[0].accessToken
806 it('Should send a notification when the video import failed', async function () {
809 const name = 'video import ' + uuidv4()
814 privacy: VideoPrivacy.PRIVATE,
815 targetUrl: getBadVideoUrl()
817 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
818 const uuid = res.body.video.uuid
820 await waitJobs(servers)
821 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
824 it('Should send a notification when the video import succeeded', async function () {
827 const name = 'video import ' + uuidv4()
832 privacy: VideoPrivacy.PRIVATE,
833 targetUrl: getYoutubeVideoUrl()
835 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
836 const uuid = res.body.video.uuid
838 await waitJobs(servers)
839 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
843 describe('New registration', function () {
844 let baseParams: CheckerBaseParams
850 socketNotifications: adminNotifications,
851 token: servers[0].accessToken
855 it('Should send a notification only to moderators when a user registers on the instance', async function () {
858 await registerUser(servers[0].url, 'user_45', 'password')
860 await waitJobs(servers)
862 await checkUserRegistered(baseParams, 'user_45', 'presence')
864 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
865 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
869 describe('New instance follower', function () {
870 let baseParams: CheckerBaseParams
876 socketNotifications: adminNotifications,
877 token: servers[0].accessToken
881 it('Should send a notification only to admin when there is a new instance follower', async function () {
884 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
886 await waitJobs(servers)
888 await checkNewInstanceFollower(baseParams, 'localhost:9003', 'presence')
890 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
891 await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:9003', 'absence')
895 describe('New actor follow', function () {
896 let baseParams: CheckerBaseParams
897 let myChannelName = 'super channel name'
898 let myUserName = 'super user name'
904 socketNotifications: userNotifications,
905 token: userAccessToken
910 accessToken: servers[0].accessToken,
911 displayName: 'super root name'
916 accessToken: userAccessToken,
917 displayName: myUserName
922 accessToken: servers[1].accessToken,
923 displayName: 'super root 2 name'
926 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
929 it('Should notify when a local channel is following one of our channel', async function () {
932 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
933 await waitJobs(servers)
935 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
937 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
940 it('Should notify when a remote channel is following one of our channel', async function () {
943 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
944 await waitJobs(servers)
946 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
948 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
951 it('Should notify when a local account is following one of our channel', async function () {
954 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001')
956 await waitJobs(servers)
958 await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
961 it('Should notify when a remote account is following one of our channel', async function () {
964 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001')
966 await waitJobs(servers)
968 await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
972 describe('Video-related notifications when video auto-blacklist is enabled', function () {
973 let userBaseParams: CheckerBaseParams
974 let adminBaseParamsServer1: CheckerBaseParams
975 let adminBaseParamsServer2: CheckerBaseParams
976 let videoUUID: string
977 let videoName: string
978 let currentCustomConfig: CustomConfig
982 adminBaseParamsServer1 = {
985 socketNotifications: adminNotifications,
986 token: servers[0].accessToken
989 adminBaseParamsServer2 = {
992 socketNotifications: adminNotificationsServer2,
993 token: servers[1].accessToken
999 socketNotifications: userNotifications,
1000 token: userAccessToken
1003 const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken)
1004 currentCustomConfig = resCustomConfig.body
1005 const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, {
1014 // enable transcoding otherwise own publish notification after transcoding not expected
1015 autoBlacklistTestsCustomConfig.transcoding.enabled = true
1016 await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig)
1018 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
1019 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
1023 it('Should send notification to moderators on new video with auto-blacklist', async function () {
1026 videoName = 'video with auto-blacklist ' + uuidv4()
1027 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
1028 videoUUID = resVideo.body.video.uuid
1030 await waitJobs(servers)
1031 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
1034 it('Should not send video publish notification if auto-blacklisted', async function () {
1035 await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence')
1038 it('Should not send a local user subscription notification if auto-blacklisted', async function () {
1039 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence')
1042 it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
1043 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence')
1046 it('Should send video published and unblacklist after video unblacklisted', async function () {
1049 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID)
1051 await waitJobs(servers)
1053 // FIXME: Can't test as two notifications sent to same user and util only checks last one
1054 // One notification might be better anyways
1055 // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist')
1056 // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence')
1059 it('Should send a local user subscription notification after removed from blacklist', async function () {
1060 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence')
1063 it('Should send a remote user subscription notification after removed from blacklist', async function () {
1064 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence')
1067 it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
1070 let updateAt = new Date(new Date().getTime() + 100000)
1072 const name = 'video with auto-blacklist and future schedule ' + uuidv4()
1076 privacy: VideoPrivacy.PRIVATE,
1078 updateAt: updateAt.toISOString(),
1079 privacy: VideoPrivacy.PUBLIC
1083 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1084 const uuid = resVideo.body.video.uuid
1086 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
1088 await waitJobs(servers)
1089 await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
1091 // FIXME: Can't test absence as two notifications sent to same user and util only checks last one
1092 // One notification might be better anyways
1093 // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1095 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1096 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1099 it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
1103 let updateAt = new Date(new Date().getTime() + 2000)
1105 const name = 'video with schedule done and still auto-blacklisted ' + uuidv4()
1109 privacy: VideoPrivacy.PRIVATE,
1111 updateAt: updateAt.toISOString(),
1112 privacy: VideoPrivacy.PUBLIC
1116 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1117 const uuid = resVideo.body.video.uuid
1120 await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1121 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1122 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1125 it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
1128 const name = 'video without auto-blacklist ' + uuidv4()
1130 // admin with blacklist right will not be auto-blacklisted
1131 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name })
1132 const uuid = resVideo.body.video.uuid
1134 await waitJobs(servers)
1135 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
1139 await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig)
1141 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
1142 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
1146 describe('Mark as read', function () {
1147 it('Should mark as read some notifications', async function () {
1148 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
1149 const ids = res.body.data.map(n => n.id)
1151 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
1154 it('Should have the notifications marked as read', async function () {
1155 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
1157 const notifications = res.body.data as UserNotification[]
1158 expect(notifications[ 0 ].read).to.be.false
1159 expect(notifications[ 1 ].read).to.be.false
1160 expect(notifications[ 2 ].read).to.be.true
1161 expect(notifications[ 3 ].read).to.be.true
1162 expect(notifications[ 4 ].read).to.be.true
1163 expect(notifications[ 5 ].read).to.be.false
1166 it('Should only list read notifications', async function () {
1167 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
1169 const notifications = res.body.data as UserNotification[]
1170 for (const notification of notifications) {
1171 expect(notification.read).to.be.true
1175 it('Should only list unread notifications', async function () {
1176 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1178 const notifications = res.body.data as UserNotification[]
1179 for (const notification of notifications) {
1180 expect(notification.read).to.be.false
1184 it('Should mark as read all notifications', async function () {
1185 await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
1187 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1189 expect(res.body.total).to.equal(0)
1190 expect(res.body.data).to.have.lengthOf(0)
1194 describe('Notification settings', function () {
1195 let baseParams: CheckerBaseParams
1201 socketNotifications: userNotifications,
1202 token: userAccessToken
1206 it('Should not have notifications', async function () {
1209 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1210 newVideoFromSubscription: UserNotificationSettingValue.NONE
1214 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1215 const info = res.body as User
1216 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
1219 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1221 const check = { web: true, mail: true }
1222 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1225 it('Should only have web notifications', async function () {
1228 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1229 newVideoFromSubscription: UserNotificationSettingValue.WEB
1233 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1234 const info = res.body as User
1235 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
1238 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1241 const check = { mail: true, web: false }
1242 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1246 const check = { mail: false, web: true }
1247 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1251 it('Should only have mail notifications', async function () {
1254 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1255 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
1259 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1260 const info = res.body as User
1261 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
1264 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1267 const check = { mail: false, web: true }
1268 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1272 const check = { mail: true, web: false }
1273 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1277 it('Should have email and web notifications', async function () {
1280 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1281 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1285 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1286 const info = res.body as User
1287 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
1288 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1292 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1294 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
1298 after(async function () {
1299 MockSmtpServer.Instance.kill()
1301 await cleanupTests(servers)