1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
9 flushAndRunMultipleServers,
14 removeVideoFromBlacklist,
21 } from '../../../../shared/utils'
22 import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index'
23 import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
24 import { waitJobs } from '../../../../shared/utils/server/jobs'
25 import { getUserNotificationSocket } from '../../../../shared/utils/socket/socket-io'
29 checkMyVideoImportIsFinished,
31 checkNewBlacklistOnMyVideo,
32 checkNewCommentOnMyVideo,
33 checkNewVideoAbuseForModerators,
34 checkNewVideoFromSubscription,
36 checkVideoIsPublished,
39 markAsReadNotifications,
40 updateMyNotificationSettings,
41 markAsReadAllNotifications
42 } from '../../../../shared/utils/users/user-notifications'
46 UserNotificationSetting,
47 UserNotificationSettingValue,
49 } from '../../../../shared/models/users'
50 import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
51 import { addUserSubscription, removeUserSubscription } from '../../../../shared/utils/users/user-subscriptions'
52 import { VideoPrivacy } from '../../../../shared/models/videos'
53 import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports'
54 import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments'
55 import * as uuidv4 from 'uuid/v4'
56 import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist'
58 const expect = chai.expect
60 async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) {
61 const name = 'remote video ' + uuidv4()
63 const data = Object.assign({ name }, additionalParams)
64 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data)
66 await waitJobs(servers)
68 return { uuid: res.body.video.uuid, name }
71 async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) {
72 const name = 'local video ' + uuidv4()
74 const data = Object.assign({ name }, additionalParams)
75 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data)
77 await waitJobs(servers)
79 return { uuid: res.body.video.uuid, name }
82 describe('Test users notifications', function () {
83 let servers: ServerInfo[] = []
84 let userAccessToken: string
85 let userNotifications: UserNotification[] = []
86 let adminNotifications: UserNotification[] = []
87 let adminNotificationsServer2: UserNotification[] = []
88 const emails: object[] = []
91 const allNotificationSettings: UserNotificationSetting = {
92 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
93 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
94 videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
95 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
96 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
97 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
98 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
99 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
100 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
103 before(async function () {
106 await MockSmtpServer.Instance.collectEmails(emails)
110 const overrideConfig = {
112 hostname: 'localhost'
115 servers = await flushAndRunMultipleServers(2, overrideConfig)
117 // Get the access tokens
118 await setAccessTokensToServers(servers)
120 // Server 1 and server 2 follow each other
121 await doubleFollow(servers[0], servers[1])
123 await waitJobs(servers)
127 password: 'super password'
129 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000)
130 userAccessToken = await userLogin(servers[0], user)
132 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
133 await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
134 await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
137 const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
138 socket.on('new-notification', n => userNotifications.push(n))
141 const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
142 socket.on('new-notification', n => adminNotifications.push(n))
145 const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
146 socket.on('new-notification', n => adminNotificationsServer2.push(n))
150 const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
151 channelId = resChannel.body.videoChannels[0].id
155 describe('New video from my subscription notification', function () {
156 let baseParams: CheckerBaseParams
162 socketNotifications: userNotifications,
163 token: userAccessToken
167 it('Should not send notifications if the user does not follow the video publisher', async function () {
170 await uploadVideoByLocalAccount(servers)
172 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
173 expect(notification).to.be.undefined
175 expect(emails).to.have.lengthOf(0)
176 expect(userNotifications).to.have.lengthOf(0)
179 it('Should send a new video notification if the user follows the local video publisher', async function () {
182 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
183 await waitJobs(servers)
185 const { name, uuid } = await uploadVideoByLocalAccount(servers)
186 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
189 it('Should send a new video notification from a remote account', async function () {
190 this.timeout(50000) // Server 2 has transcoding enabled
192 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002')
193 await waitJobs(servers)
195 const { name, uuid } = await uploadVideoByRemoteAccount(servers)
196 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
199 it('Should send a new video notification on a scheduled publication', async function () {
203 let updateAt = new Date(new Date().getTime() + 2000)
206 privacy: VideoPrivacy.PRIVATE,
208 updateAt: updateAt.toISOString(),
209 privacy: VideoPrivacy.PUBLIC
212 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
215 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
218 it('Should send a new video notification on a remote scheduled publication', async function () {
222 let updateAt = new Date(new Date().getTime() + 2000)
225 privacy: VideoPrivacy.PRIVATE,
227 updateAt: updateAt.toISOString(),
228 privacy: VideoPrivacy.PUBLIC
231 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
232 await waitJobs(servers)
235 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
238 it('Should not send a notification before the video is published', async function () {
241 let updateAt = new Date(new Date().getTime() + 100000)
244 privacy: VideoPrivacy.PRIVATE,
246 updateAt: updateAt.toISOString(),
247 privacy: VideoPrivacy.PUBLIC
250 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
253 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
256 it('Should send a new video notification when a video becomes public', async function () {
259 const data = { privacy: VideoPrivacy.PRIVATE }
260 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
262 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
264 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
267 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
270 it('Should send a new video notification when a remote video becomes public', async function () {
273 const data = { privacy: VideoPrivacy.PRIVATE }
274 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
276 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
278 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
280 await waitJobs(servers)
281 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
284 it('Should not send a new video notification when a video becomes unlisted', async function () {
287 const data = { privacy: VideoPrivacy.PRIVATE }
288 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
290 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
292 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
295 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
298 const data = { privacy: VideoPrivacy.PRIVATE }
299 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
301 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
303 await waitJobs(servers)
304 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
307 it('Should send a new video notification after a video import', async function () {
310 const name = 'video import ' + uuidv4()
315 privacy: VideoPrivacy.PUBLIC,
316 targetUrl: getYoutubeVideoUrl()
318 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
319 const uuid = res.body.video.uuid
321 await waitJobs(servers)
323 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
327 describe('Comment on my video notifications', function () {
328 let baseParams: CheckerBaseParams
334 socketNotifications: userNotifications,
335 token: userAccessToken
339 it('Should not send a new comment notification after a comment on another video', async function () {
342 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
343 const uuid = resVideo.body.video.uuid
345 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
346 const commentId = resComment.body.comment.id
349 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
352 it('Should not send a new comment notification if I comment my own video', async function () {
355 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
356 const uuid = resVideo.body.video.uuid
358 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
359 const commentId = resComment.body.comment.id
362 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
365 it('Should not send a new comment notification if the account is muted', async function () {
368 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
370 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
371 const uuid = resVideo.body.video.uuid
373 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
374 const commentId = resComment.body.comment.id
377 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
379 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
382 it('Should send a new comment notification after a local comment on my video', async function () {
385 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
386 const uuid = resVideo.body.video.uuid
388 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
389 const commentId = resComment.body.comment.id
392 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
395 it('Should send a new comment notification after a remote comment on my video', async function () {
398 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
399 const uuid = resVideo.body.video.uuid
401 await waitJobs(servers)
403 const resComment = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
404 const commentId = resComment.body.comment.id
406 await waitJobs(servers)
407 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
410 it('Should send a new comment notification after a local reply on my video', async function () {
413 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
414 const uuid = resVideo.body.video.uuid
416 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
417 const threadId = resThread.body.comment.id
419 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
420 const commentId = resComment.body.comment.id
423 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
426 it('Should send a new comment notification after a remote reply on my video', async function () {
429 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
430 const uuid = resVideo.body.video.uuid
431 await waitJobs(servers)
433 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
434 const threadId = resThread.body.comment.id
436 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply')
437 const commentId = resComment.body.comment.id
439 await waitJobs(servers)
440 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
444 describe('Mention notifications', function () {
445 let baseParams: CheckerBaseParams
451 socketNotifications: userNotifications,
452 token: userAccessToken
457 accessToken: servers[0].accessToken,
458 displayName: 'super root name'
463 accessToken: servers[1].accessToken,
464 displayName: 'super root 2 name'
468 it('Should not send a new mention comment notification if I mention the video owner', async function () {
471 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
472 const uuid = resVideo.body.video.uuid
474 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
475 const commentId = resComment.body.comment.id
478 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
481 it('Should not send a new mention comment notification if I mention myself', async function () {
484 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
485 const uuid = resVideo.body.video.uuid
487 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
488 const commentId = resComment.body.comment.id
491 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
494 it('Should not send a new mention notification if the account is muted', async function () {
497 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
499 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
500 const uuid = resVideo.body.video.uuid
502 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
503 const commentId = resComment.body.comment.id
506 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
508 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
511 it('Should not send a new mention notification if the remote account mention a local account', async function () {
514 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
515 const uuid = resVideo.body.video.uuid
517 await waitJobs(servers)
518 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
519 const threadId = resThread.body.comment.id
521 await waitJobs(servers)
522 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
525 it('Should send a new mention notification after local comments', async function () {
528 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
529 const uuid = resVideo.body.video.uuid
531 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
532 const threadId = resThread.body.comment.id
535 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
537 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
538 const commentId = resComment.body.comment.id
541 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
544 it('Should send a new mention notification after remote comments', 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, 'hello @user_1@localhost:9001 1')
552 const threadId = resThread.body.comment.id
554 await waitJobs(servers)
555 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'presence')
557 const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001'
558 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, text)
559 const commentId = resComment.body.comment.id
561 await waitJobs(servers)
562 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root 2 name', 'presence')
566 describe('Video abuse for moderators notification' , function () {
567 let baseParams: CheckerBaseParams
573 socketNotifications: adminNotifications,
574 token: servers[0].accessToken
578 it('Should send a notification to moderators on local video abuse', async function () {
581 const name = 'video for abuse ' + uuidv4()
582 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
583 const uuid = resVideo.body.video.uuid
585 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
587 await waitJobs(servers)
588 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
591 it('Should send a notification to moderators on remote video abuse', async function () {
594 const name = 'video for abuse ' + uuidv4()
595 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
596 const uuid = resVideo.body.video.uuid
598 await waitJobs(servers)
600 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
602 await waitJobs(servers)
603 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
607 describe('Video blacklist on my video', function () {
608 let baseParams: CheckerBaseParams
614 socketNotifications: userNotifications,
615 token: userAccessToken
619 it('Should send a notification to video owner on blacklist', async function () {
622 const name = 'video for abuse ' + uuidv4()
623 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
624 const uuid = resVideo.body.video.uuid
626 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
628 await waitJobs(servers)
629 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
632 it('Should send a notification to video owner on unblacklist', async function () {
635 const name = 'video for abuse ' + uuidv4()
636 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
637 const uuid = resVideo.body.video.uuid
639 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
641 await waitJobs(servers)
642 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
643 await waitJobs(servers)
646 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
650 describe('My video is published', function () {
651 let baseParams: CheckerBaseParams
657 socketNotifications: adminNotificationsServer2,
658 token: servers[1].accessToken
662 it('Should not send a notification if transcoding is not enabled', async function () {
665 const { name, uuid } = await uploadVideoByLocalAccount(servers)
666 await waitJobs(servers)
668 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
671 it('Should not send a notification if the wait transcoding is false', async function () {
674 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
675 await waitJobs(servers)
677 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
679 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
683 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
686 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
687 await waitJobs(servers)
689 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
692 it('Should send a notification with a transcoded video', async function () {
695 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
696 await waitJobs(servers)
698 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
701 it('Should send a notification when an imported video is transcoded', async function () {
704 const name = 'video import ' + uuidv4()
709 privacy: VideoPrivacy.PUBLIC,
710 targetUrl: getYoutubeVideoUrl(),
711 waitTranscoding: true
713 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
714 const uuid = res.body.video.uuid
716 await waitJobs(servers)
717 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
720 it('Should send a notification when the scheduled update has been proceeded', async function () {
724 let updateAt = new Date(new Date().getTime() + 2000)
727 privacy: VideoPrivacy.PRIVATE,
729 updateAt: updateAt.toISOString(),
730 privacy: VideoPrivacy.PUBLIC
733 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
736 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
739 it('Should not send a notification before the video is published', async function () {
742 let updateAt = new Date(new Date().getTime() + 100000)
745 privacy: VideoPrivacy.PRIVATE,
747 updateAt: updateAt.toISOString(),
748 privacy: VideoPrivacy.PUBLIC
751 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
754 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
758 describe('My video is imported', function () {
759 let baseParams: CheckerBaseParams
765 socketNotifications: adminNotifications,
766 token: servers[0].accessToken
770 it('Should send a notification when the video import failed', async function () {
773 const name = 'video import ' + uuidv4()
778 privacy: VideoPrivacy.PRIVATE,
779 targetUrl: getBadVideoUrl()
781 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
782 const uuid = res.body.video.uuid
784 await waitJobs(servers)
785 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
788 it('Should send a notification when the video import succeeded', async function () {
791 const name = 'video import ' + uuidv4()
796 privacy: VideoPrivacy.PRIVATE,
797 targetUrl: getYoutubeVideoUrl()
799 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
800 const uuid = res.body.video.uuid
802 await waitJobs(servers)
803 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
807 describe('New registration', function () {
808 let baseParams: CheckerBaseParams
814 socketNotifications: adminNotifications,
815 token: servers[0].accessToken
819 it('Should send a notification only to moderators when a user registers on the instance', async function () {
822 await registerUser(servers[0].url, 'user_45', 'password')
824 await waitJobs(servers)
826 await checkUserRegistered(baseParams, 'user_45', 'presence')
828 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
829 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
833 describe('New actor follow', function () {
834 let baseParams: CheckerBaseParams
835 let myChannelName = 'super channel name'
836 let myUserName = 'super user name'
842 socketNotifications: userNotifications,
843 token: userAccessToken
848 accessToken: servers[0].accessToken,
849 displayName: 'super root name'
854 accessToken: userAccessToken,
855 displayName: myUserName
860 accessToken: servers[1].accessToken,
861 displayName: 'super root 2 name'
864 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
867 it('Should notify when a local channel is following one of our channel', async function () {
870 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
871 await waitJobs(servers)
873 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
875 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
878 it('Should notify when a remote channel is following one of our channel', async function () {
881 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
882 await waitJobs(servers)
884 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
886 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
889 it('Should notify when a local account is following one of our channel', async function () {
892 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001')
894 await waitJobs(servers)
896 await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
899 it('Should notify when a remote account is following one of our channel', async function () {
902 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001')
904 await waitJobs(servers)
906 await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
910 describe('Mark as read', function () {
911 it('Should mark as read some notifications', async function () {
912 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
913 const ids = res.body.data.map(n => n.id)
915 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
918 it('Should have the notifications marked as read', async function () {
919 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
921 const notifications = res.body.data as UserNotification[]
922 expect(notifications[ 0 ].read).to.be.false
923 expect(notifications[ 1 ].read).to.be.false
924 expect(notifications[ 2 ].read).to.be.true
925 expect(notifications[ 3 ].read).to.be.true
926 expect(notifications[ 4 ].read).to.be.true
927 expect(notifications[ 5 ].read).to.be.false
930 it('Should only list read notifications', async function () {
931 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
933 const notifications = res.body.data as UserNotification[]
934 for (const notification of notifications) {
935 expect(notification.read).to.be.true
939 it('Should only list unread notifications', async function () {
940 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
942 const notifications = res.body.data as UserNotification[]
943 for (const notification of notifications) {
944 expect(notification.read).to.be.false
948 it('Should mark as read all notifications', async function () {
949 await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
951 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
953 expect(res.body.total).to.equal(0)
954 expect(res.body.data).to.have.lengthOf(0)
958 describe('Notification settings', function () {
959 let baseParams: CheckerBaseParams
965 socketNotifications: userNotifications,
966 token: userAccessToken
970 it('Should not have notifications', async function () {
973 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
974 newVideoFromSubscription: UserNotificationSettingValue.NONE
978 const res = await getMyUserInformation(servers[0].url, userAccessToken)
979 const info = res.body as User
980 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
983 const { name, uuid } = await uploadVideoByLocalAccount(servers)
985 const check = { web: true, mail: true }
986 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
989 it('Should only have web notifications', async function () {
992 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
993 newVideoFromSubscription: UserNotificationSettingValue.WEB
997 const res = await getMyUserInformation(servers[0].url, userAccessToken)
998 const info = res.body as User
999 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
1002 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1005 const check = { mail: true, web: false }
1006 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1010 const check = { mail: false, web: true }
1011 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1015 it('Should only have mail notifications', async function () {
1018 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1019 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
1023 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1024 const info = res.body as User
1025 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
1028 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1031 const check = { mail: false, web: true }
1032 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1036 const check = { mail: true, web: false }
1037 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1041 it('Should have email and web notifications', async function () {
1044 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1045 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1049 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1050 const info = res.body as User
1051 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
1052 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1056 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1058 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
1062 after(async function () {
1063 MockSmtpServer.Instance.kill()
1065 killallServers(servers)