1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
9 flushAndRunMultipleServers,
14 removeVideoFromBlacklist,
22 updateCustomConfig, getVideoThreadComments, getVideoCommentThreads
23 } from '../../../../shared/utils'
24 import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index'
25 import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
26 import { waitJobs } from '../../../../shared/utils/server/jobs'
27 import { getUserNotificationSocket } from '../../../../shared/utils/socket/socket-io'
31 checkMyVideoImportIsFinished,
33 checkNewBlacklistOnMyVideo,
34 checkNewCommentOnMyVideo,
35 checkNewVideoAbuseForModerators,
36 checkVideoAutoBlacklistForModerators,
37 checkNewVideoFromSubscription,
39 checkVideoIsPublished,
42 markAsReadNotifications,
43 updateMyNotificationSettings,
44 markAsReadAllNotifications
45 } from '../../../../shared/utils/users/user-notifications'
49 UserNotificationSetting,
50 UserNotificationSettingValue,
52 } from '../../../../shared/models/users'
53 import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
54 import { addUserSubscription, removeUserSubscription } from '../../../../shared/utils/users/user-subscriptions'
55 import { VideoPrivacy } from '../../../../shared/models/videos'
56 import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports'
57 import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments'
58 import * as uuidv4 from 'uuid/v4'
59 import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist'
60 import { CustomConfig } from '../../../../shared/models/server'
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
109 before(async function () {
112 await MockSmtpServer.Instance.collectEmails(emails)
116 const overrideConfig = {
118 hostname: 'localhost'
121 servers = await flushAndRunMultipleServers(2, overrideConfig)
123 // Get the access tokens
124 await setAccessTokensToServers(servers)
126 // Server 1 and server 2 follow each other
127 await doubleFollow(servers[0], servers[1])
129 await waitJobs(servers)
133 password: 'super password'
135 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000)
136 userAccessToken = await userLogin(servers[0], user)
138 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
139 await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
140 await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
143 const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
144 socket.on('new-notification', n => userNotifications.push(n))
147 const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
148 socket.on('new-notification', n => adminNotifications.push(n))
151 const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
152 socket.on('new-notification', n => adminNotificationsServer2.push(n))
156 const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
157 channelId = resChannel.body.videoChannels[0].id
161 describe('New video from my subscription notification', function () {
162 let baseParams: CheckerBaseParams
168 socketNotifications: userNotifications,
169 token: userAccessToken
173 it('Should not send notifications if the user does not follow the video publisher', async function () {
176 await uploadVideoByLocalAccount(servers)
178 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
179 expect(notification).to.be.undefined
181 expect(emails).to.have.lengthOf(0)
182 expect(userNotifications).to.have.lengthOf(0)
185 it('Should send a new video notification if the user follows the local video publisher', async function () {
188 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
189 await waitJobs(servers)
191 const { name, uuid } = await uploadVideoByLocalAccount(servers)
192 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
195 it('Should send a new video notification from a remote account', async function () {
196 this.timeout(50000) // Server 2 has transcoding enabled
198 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002')
199 await waitJobs(servers)
201 const { name, uuid } = await uploadVideoByRemoteAccount(servers)
202 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
205 it('Should send a new video notification on a scheduled publication', async function () {
209 let updateAt = new Date(new Date().getTime() + 2000)
212 privacy: VideoPrivacy.PRIVATE,
214 updateAt: updateAt.toISOString(),
215 privacy: VideoPrivacy.PUBLIC
218 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
221 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
224 it('Should send a new video notification on a remote scheduled publication', async function () {
228 let updateAt = new Date(new Date().getTime() + 2000)
231 privacy: VideoPrivacy.PRIVATE,
233 updateAt: updateAt.toISOString(),
234 privacy: VideoPrivacy.PUBLIC
237 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
238 await waitJobs(servers)
241 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
244 it('Should not send a notification before the video is published', async function () {
247 let updateAt = new Date(new Date().getTime() + 1000000)
250 privacy: VideoPrivacy.PRIVATE,
252 updateAt: updateAt.toISOString(),
253 privacy: VideoPrivacy.PUBLIC
256 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
259 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
262 it('Should send a new video notification when a video becomes public', async function () {
265 const data = { privacy: VideoPrivacy.PRIVATE }
266 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
268 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
270 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
273 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
276 it('Should send a new video notification when a remote video becomes public', async function () {
279 const data = { privacy: VideoPrivacy.PRIVATE }
280 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
282 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
284 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
286 await waitJobs(servers)
287 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
290 it('Should not send a new video notification when a video becomes unlisted', async function () {
293 const data = { privacy: VideoPrivacy.PRIVATE }
294 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
296 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
298 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
301 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
304 const data = { privacy: VideoPrivacy.PRIVATE }
305 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
307 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
309 await waitJobs(servers)
310 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
313 it('Should send a new video notification after a video import', async function () {
316 const name = 'video import ' + uuidv4()
321 privacy: VideoPrivacy.PUBLIC,
322 targetUrl: getYoutubeVideoUrl()
324 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
325 const uuid = res.body.video.uuid
327 await waitJobs(servers)
329 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
333 describe('Comment on my video notifications', function () {
334 let baseParams: CheckerBaseParams
340 socketNotifications: userNotifications,
341 token: userAccessToken
345 it('Should not send a new comment notification after a comment on another video', async function () {
348 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
349 const uuid = resVideo.body.video.uuid
351 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
352 const commentId = resComment.body.comment.id
355 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
358 it('Should not send a new comment notification if I comment my own video', async function () {
361 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
362 const uuid = resVideo.body.video.uuid
364 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
365 const commentId = resComment.body.comment.id
368 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
371 it('Should not send a new comment notification if the account is muted', async function () {
374 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
376 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
377 const uuid = resVideo.body.video.uuid
379 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
380 const commentId = resComment.body.comment.id
383 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
385 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
388 it('Should send a new comment notification after a local comment on my video', async function () {
391 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
392 const uuid = resVideo.body.video.uuid
394 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
395 const commentId = resComment.body.comment.id
398 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
401 it('Should send a new comment notification after a remote comment on my video', async function () {
404 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
405 const uuid = resVideo.body.video.uuid
407 await waitJobs(servers)
409 await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
411 await waitJobs(servers)
413 const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
414 expect(resComment.body.data).to.have.lengthOf(1)
415 const commentId = resComment.body.data[0].id
417 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
420 it('Should send a new comment notification after a local reply on my video', async function () {
423 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
424 const uuid = resVideo.body.video.uuid
426 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
427 const threadId = resThread.body.comment.id
429 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
430 const commentId = resComment.body.comment.id
433 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
436 it('Should send a new comment notification after a remote reply on my video', async function () {
439 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
440 const uuid = resVideo.body.video.uuid
441 await waitJobs(servers)
444 const resThread = await addVideoCommentThread(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, 'comment')
445 const threadId = resThread.body.comment.id
446 await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, threadId, 'reply')
449 await waitJobs(servers)
451 const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
452 expect(resThread.body.data).to.have.lengthOf(1)
453 const threadId = resThread.body.data[0].id
455 const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
456 const tree = resComments.body as VideoCommentThreadTree
458 expect(tree.children).to.have.lengthOf(1)
459 const commentId = tree.children[0].comment.id
461 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
465 describe('Mention notifications', function () {
466 let baseParams: CheckerBaseParams
472 socketNotifications: userNotifications,
473 token: userAccessToken
478 accessToken: servers[0].accessToken,
479 displayName: 'super root name'
484 accessToken: servers[1].accessToken,
485 displayName: 'super root 2 name'
489 it('Should not send a new mention comment notification if I mention the video owner', async function () {
492 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
493 const uuid = resVideo.body.video.uuid
495 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
496 const commentId = resComment.body.comment.id
499 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
502 it('Should not send a new mention comment notification if I mention myself', async function () {
505 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
506 const uuid = resVideo.body.video.uuid
508 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
509 const commentId = resComment.body.comment.id
512 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
515 it('Should not send a new mention notification if the account is muted', async function () {
518 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
520 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
521 const uuid = resVideo.body.video.uuid
523 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
524 const commentId = resComment.body.comment.id
527 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
529 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
532 it('Should not send a new mention notification if the remote account mention a local account', async function () {
535 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
536 const uuid = resVideo.body.video.uuid
538 await waitJobs(servers)
539 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
540 const threadId = resThread.body.comment.id
542 await waitJobs(servers)
543 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
546 it('Should send a new mention notification after local comments', async function () {
549 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
550 const uuid = resVideo.body.video.uuid
552 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
553 const threadId = resThread.body.comment.id
556 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
558 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
559 const commentId = resComment.body.comment.id
562 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
565 it('Should send a new mention notification after remote comments', async function () {
568 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
569 const uuid = resVideo.body.video.uuid
571 await waitJobs(servers)
572 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1')
573 const server2ThreadId = resThread.body.comment.id
575 await waitJobs(servers)
577 const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
578 expect(resThread2.body.data).to.have.lengthOf(1)
579 const server1ThreadId = resThread2.body.data[0].id
580 await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
582 const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001'
583 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text)
585 await waitJobs(servers)
587 const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
588 const tree = resComments.body as VideoCommentThreadTree
590 expect(tree.children).to.have.lengthOf(1)
591 const commentId = tree.children[0].comment.id
593 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
597 describe('Video abuse for moderators notification' , function () {
598 let baseParams: CheckerBaseParams
604 socketNotifications: adminNotifications,
605 token: servers[0].accessToken
609 it('Should send a notification to moderators on local video abuse', async function () {
612 const name = 'video for abuse ' + uuidv4()
613 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
614 const uuid = resVideo.body.video.uuid
616 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
618 await waitJobs(servers)
619 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
622 it('Should send a notification to moderators on remote video abuse', async function () {
625 const name = 'video for abuse ' + uuidv4()
626 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
627 const uuid = resVideo.body.video.uuid
629 await waitJobs(servers)
631 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
633 await waitJobs(servers)
634 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
638 describe('Video blacklist on my video', function () {
639 let baseParams: CheckerBaseParams
645 socketNotifications: userNotifications,
646 token: userAccessToken
650 it('Should send a notification to video owner on blacklist', async function () {
653 const name = 'video for abuse ' + uuidv4()
654 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
655 const uuid = resVideo.body.video.uuid
657 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
659 await waitJobs(servers)
660 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
663 it('Should send a notification to video owner on unblacklist', async function () {
666 const name = 'video for abuse ' + uuidv4()
667 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
668 const uuid = resVideo.body.video.uuid
670 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
672 await waitJobs(servers)
673 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
674 await waitJobs(servers)
677 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
681 describe('My video is published', function () {
682 let baseParams: CheckerBaseParams
688 socketNotifications: adminNotificationsServer2,
689 token: servers[1].accessToken
693 it('Should not send a notification if transcoding is not enabled', async function () {
696 const { name, uuid } = await uploadVideoByLocalAccount(servers)
697 await waitJobs(servers)
699 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
702 it('Should not send a notification if the wait transcoding is false', async function () {
705 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
706 await waitJobs(servers)
708 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
710 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
714 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
717 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
718 await waitJobs(servers)
720 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
723 it('Should send a notification with a transcoded video', async function () {
726 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
727 await waitJobs(servers)
729 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
732 it('Should send a notification when an imported video is transcoded', async function () {
735 const name = 'video import ' + uuidv4()
740 privacy: VideoPrivacy.PUBLIC,
741 targetUrl: getYoutubeVideoUrl(),
742 waitTranscoding: true
744 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
745 const uuid = res.body.video.uuid
747 await waitJobs(servers)
748 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
751 it('Should send a notification when the scheduled update has been proceeded', async function () {
755 let updateAt = new Date(new Date().getTime() + 2000)
758 privacy: VideoPrivacy.PRIVATE,
760 updateAt: updateAt.toISOString(),
761 privacy: VideoPrivacy.PUBLIC
764 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
767 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
770 it('Should not send a notification before the video is published', async function () {
773 let updateAt = new Date(new Date().getTime() + 100000)
776 privacy: VideoPrivacy.PRIVATE,
778 updateAt: updateAt.toISOString(),
779 privacy: VideoPrivacy.PUBLIC
782 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
785 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
789 describe('My video is imported', function () {
790 let baseParams: CheckerBaseParams
796 socketNotifications: adminNotifications,
797 token: servers[0].accessToken
801 it('Should send a notification when the video import failed', async function () {
804 const name = 'video import ' + uuidv4()
809 privacy: VideoPrivacy.PRIVATE,
810 targetUrl: getBadVideoUrl()
812 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
813 const uuid = res.body.video.uuid
815 await waitJobs(servers)
816 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
819 it('Should send a notification when the video import succeeded', async function () {
822 const name = 'video import ' + uuidv4()
827 privacy: VideoPrivacy.PRIVATE,
828 targetUrl: getYoutubeVideoUrl()
830 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
831 const uuid = res.body.video.uuid
833 await waitJobs(servers)
834 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
838 describe('New registration', function () {
839 let baseParams: CheckerBaseParams
845 socketNotifications: adminNotifications,
846 token: servers[0].accessToken
850 it('Should send a notification only to moderators when a user registers on the instance', async function () {
853 await registerUser(servers[0].url, 'user_45', 'password')
855 await waitJobs(servers)
857 await checkUserRegistered(baseParams, 'user_45', 'presence')
859 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
860 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
864 describe('New actor follow', function () {
865 let baseParams: CheckerBaseParams
866 let myChannelName = 'super channel name'
867 let myUserName = 'super user name'
873 socketNotifications: userNotifications,
874 token: userAccessToken
879 accessToken: servers[0].accessToken,
880 displayName: 'super root name'
885 accessToken: userAccessToken,
886 displayName: myUserName
891 accessToken: servers[1].accessToken,
892 displayName: 'super root 2 name'
895 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
898 it('Should notify when a local channel is following one of our channel', async function () {
901 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
902 await waitJobs(servers)
904 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
906 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
909 it('Should notify when a remote channel is following one of our channel', async function () {
912 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
913 await waitJobs(servers)
915 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
917 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
920 it('Should notify when a local account is following one of our channel', async function () {
923 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001')
925 await waitJobs(servers)
927 await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
930 it('Should notify when a remote account is following one of our channel', async function () {
933 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001')
935 await waitJobs(servers)
937 await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
941 describe('Video-related notifications when video auto-blacklist is enabled', function () {
942 let userBaseParams: CheckerBaseParams
943 let adminBaseParamsServer1: CheckerBaseParams
944 let adminBaseParamsServer2: CheckerBaseParams
945 let videoUUID: string
946 let videoName: string
947 let currentCustomConfig: CustomConfig
951 adminBaseParamsServer1 = {
954 socketNotifications: adminNotifications,
955 token: servers[0].accessToken
958 adminBaseParamsServer2 = {
961 socketNotifications: adminNotificationsServer2,
962 token: servers[1].accessToken
968 socketNotifications: userNotifications,
969 token: userAccessToken
972 const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken)
973 currentCustomConfig = resCustomConfig.body
974 const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, {
983 // enable transcoding otherwise own publish notification after transcoding not expected
984 autoBlacklistTestsCustomConfig.transcoding.enabled = true
985 await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig)
987 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
988 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
992 it('Should send notification to moderators on new video with auto-blacklist', async function () {
995 videoName = 'video with auto-blacklist ' + uuidv4()
996 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
997 videoUUID = resVideo.body.video.uuid
999 await waitJobs(servers)
1000 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
1003 it('Should not send video publish notification if auto-blacklisted', async function () {
1004 await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence')
1007 it('Should not send a local user subscription notification if auto-blacklisted', async function () {
1008 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence')
1011 it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
1012 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence')
1015 it('Should send video published and unblacklist after video unblacklisted', async function () {
1018 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID)
1020 await waitJobs(servers)
1022 // FIXME: Can't test as two notifications sent to same user and util only checks last one
1023 // One notification might be better anyways
1024 // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist')
1025 // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence')
1028 it('Should send a local user subscription notification after removed from blacklist', async function () {
1029 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence')
1032 it('Should send a remote user subscription notification after removed from blacklist', async function () {
1033 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence')
1036 it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
1039 let updateAt = new Date(new Date().getTime() + 100000)
1041 const name = 'video with auto-blacklist and future schedule ' + uuidv4()
1045 privacy: VideoPrivacy.PRIVATE,
1047 updateAt: updateAt.toISOString(),
1048 privacy: VideoPrivacy.PUBLIC
1052 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1053 const uuid = resVideo.body.video.uuid
1055 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
1057 await waitJobs(servers)
1058 await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
1060 // FIXME: Can't test absence as two notifications sent to same user and util only checks last one
1061 // One notification might be better anyways
1062 // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1064 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1065 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1068 it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
1072 let updateAt = new Date(new Date().getTime() + 2000)
1074 const name = 'video with schedule done and still auto-blacklisted ' + uuidv4()
1078 privacy: VideoPrivacy.PRIVATE,
1080 updateAt: updateAt.toISOString(),
1081 privacy: VideoPrivacy.PUBLIC
1085 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1086 const uuid = resVideo.body.video.uuid
1089 await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1090 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1091 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1094 it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
1097 const name = 'video without auto-blacklist ' + uuidv4()
1099 // admin with blacklist right will not be auto-blacklisted
1100 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name })
1101 const uuid = resVideo.body.video.uuid
1103 await waitJobs(servers)
1104 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
1108 await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig)
1110 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
1111 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
1115 describe('Mark as read', function () {
1116 it('Should mark as read some notifications', async function () {
1117 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
1118 const ids = res.body.data.map(n => n.id)
1120 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
1123 it('Should have the notifications marked as read', async function () {
1124 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
1126 const notifications = res.body.data as UserNotification[]
1127 expect(notifications[ 0 ].read).to.be.false
1128 expect(notifications[ 1 ].read).to.be.false
1129 expect(notifications[ 2 ].read).to.be.true
1130 expect(notifications[ 3 ].read).to.be.true
1131 expect(notifications[ 4 ].read).to.be.true
1132 expect(notifications[ 5 ].read).to.be.false
1135 it('Should only list read notifications', async function () {
1136 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
1138 const notifications = res.body.data as UserNotification[]
1139 for (const notification of notifications) {
1140 expect(notification.read).to.be.true
1144 it('Should only list unread notifications', async function () {
1145 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1147 const notifications = res.body.data as UserNotification[]
1148 for (const notification of notifications) {
1149 expect(notification.read).to.be.false
1153 it('Should mark as read all notifications', async function () {
1154 await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
1156 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1158 expect(res.body.total).to.equal(0)
1159 expect(res.body.data).to.have.lengthOf(0)
1163 describe('Notification settings', function () {
1164 let baseParams: CheckerBaseParams
1170 socketNotifications: userNotifications,
1171 token: userAccessToken
1175 it('Should not have notifications', async function () {
1178 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1179 newVideoFromSubscription: UserNotificationSettingValue.NONE
1183 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1184 const info = res.body as User
1185 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
1188 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1190 const check = { web: true, mail: true }
1191 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1194 it('Should only have web notifications', async function () {
1197 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1198 newVideoFromSubscription: UserNotificationSettingValue.WEB
1202 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1203 const info = res.body as User
1204 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
1207 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1210 const check = { mail: true, web: false }
1211 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1215 const check = { mail: false, web: true }
1216 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1220 it('Should only have mail notifications', async function () {
1223 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1224 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
1228 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1229 const info = res.body as User
1230 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
1233 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1236 const check = { mail: false, web: true }
1237 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1241 const check = { mail: true, web: false }
1242 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1246 it('Should have email and web notifications', async function () {
1249 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1250 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1254 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1255 const info = res.body as User
1256 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
1257 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1261 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1263 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
1267 after(async function () {
1268 MockSmtpServer.Instance.kill()
1270 killallServers(servers)