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 () {
168 await uploadVideoByLocalAccount(servers)
170 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
171 expect(notification).to.be.undefined
173 expect(emails).to.have.lengthOf(0)
174 expect(userNotifications).to.have.lengthOf(0)
177 it('Should send a new video notification if the user follows the local video publisher', async function () {
180 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
181 await waitJobs(servers)
183 const { name, uuid } = await uploadVideoByLocalAccount(servers)
184 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
187 it('Should send a new video notification from a remote account', async function () {
188 this.timeout(50000) // Server 2 has transcoding enabled
190 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002')
191 await waitJobs(servers)
193 const { name, uuid } = await uploadVideoByRemoteAccount(servers)
194 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
197 it('Should send a new video notification on a scheduled publication', async function () {
201 let updateAt = new Date(new Date().getTime() + 2000)
204 privacy: VideoPrivacy.PRIVATE,
206 updateAt: updateAt.toISOString(),
207 privacy: VideoPrivacy.PUBLIC
210 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
213 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
216 it('Should send a new video notification on a remote scheduled publication', async function () {
220 let updateAt = new Date(new Date().getTime() + 2000)
223 privacy: VideoPrivacy.PRIVATE,
225 updateAt: updateAt.toISOString(),
226 privacy: VideoPrivacy.PUBLIC
229 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
230 await waitJobs(servers)
233 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
236 it('Should not send a notification before the video is published', async function () {
239 let updateAt = new Date(new Date().getTime() + 100000)
242 privacy: VideoPrivacy.PRIVATE,
244 updateAt: updateAt.toISOString(),
245 privacy: VideoPrivacy.PUBLIC
248 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
251 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
254 it('Should send a new video notification when a video becomes public', async function () {
257 const data = { privacy: VideoPrivacy.PRIVATE }
258 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
260 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
262 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
265 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
268 it('Should send a new video notification when a remote video becomes public', async function () {
271 const data = { privacy: VideoPrivacy.PRIVATE }
272 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
274 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
276 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
278 await waitJobs(servers)
279 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
282 it('Should not send a new video notification when a video becomes unlisted', async function () {
285 const data = { privacy: VideoPrivacy.PRIVATE }
286 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
288 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
290 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
293 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
296 const data = { privacy: VideoPrivacy.PRIVATE }
297 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
299 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
301 await waitJobs(servers)
302 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
305 it('Should send a new video notification after a video import', async function () {
308 const name = 'video import ' + uuidv4()
313 privacy: VideoPrivacy.PUBLIC,
314 targetUrl: getYoutubeVideoUrl()
316 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
317 const uuid = res.body.video.uuid
319 await waitJobs(servers)
321 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
325 describe('Comment on my video notifications', function () {
326 let baseParams: CheckerBaseParams
332 socketNotifications: userNotifications,
333 token: userAccessToken
337 it('Should not send a new comment notification after a comment on another video', async function () {
340 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
341 const uuid = resVideo.body.video.uuid
343 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
344 const commentId = resComment.body.comment.id
347 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
350 it('Should not send a new comment notification if I comment my own video', async function () {
353 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
354 const uuid = resVideo.body.video.uuid
356 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, 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 the account is muted', async function () {
366 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
368 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
369 const uuid = resVideo.body.video.uuid
371 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
372 const commentId = resComment.body.comment.id
375 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
377 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
380 it('Should send a new comment notification after a local comment on my video', async function () {
383 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
384 const uuid = resVideo.body.video.uuid
386 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
387 const commentId = resComment.body.comment.id
390 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
393 it('Should send a new comment notification after a remote 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 await waitJobs(servers)
401 const resComment = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
402 const commentId = resComment.body.comment.id
404 await waitJobs(servers)
405 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
408 it('Should send a new comment notification after a local reply on my video', async function () {
411 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
412 const uuid = resVideo.body.video.uuid
414 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
415 const threadId = resThread.body.comment.id
417 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
418 const commentId = resComment.body.comment.id
421 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
424 it('Should send a new comment notification after a remote reply on my video', async function () {
427 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
428 const uuid = resVideo.body.video.uuid
429 await waitJobs(servers)
431 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
432 const threadId = resThread.body.comment.id
434 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply')
435 const commentId = resComment.body.comment.id
437 await waitJobs(servers)
438 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
442 describe('Mention notifications', function () {
443 let baseParams: CheckerBaseParams
449 socketNotifications: userNotifications,
450 token: userAccessToken
455 accessToken: servers[0].accessToken,
456 displayName: 'super root name'
461 accessToken: servers[1].accessToken,
462 displayName: 'super root 2 name'
466 it('Should not send a new mention comment notification if I mention the video owner', async function () {
469 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
470 const uuid = resVideo.body.video.uuid
472 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
473 const commentId = resComment.body.comment.id
476 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
479 it('Should not send a new mention comment notification if I mention myself', async function () {
482 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
483 const uuid = resVideo.body.video.uuid
485 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
486 const commentId = resComment.body.comment.id
489 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
492 it('Should not send a new mention notification if the account is muted', async function () {
495 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
497 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { 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')
506 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
509 it('Should not send a new mention notification if the remote account mention a local account', async function () {
512 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
513 const uuid = resVideo.body.video.uuid
515 await waitJobs(servers)
516 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
517 const threadId = resThread.body.comment.id
519 await waitJobs(servers)
520 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
523 it('Should send a new mention notification after local comments', async function () {
526 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
527 const uuid = resVideo.body.video.uuid
529 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
530 const threadId = resThread.body.comment.id
533 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
535 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
536 const commentId = resComment.body.comment.id
539 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
542 it('Should send a new mention notification after remote comments', async function () {
545 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
546 const uuid = resVideo.body.video.uuid
548 await waitJobs(servers)
549 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1')
550 const threadId = resThread.body.comment.id
552 await waitJobs(servers)
553 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'presence')
555 const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001'
556 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, text)
557 const commentId = resComment.body.comment.id
559 await waitJobs(servers)
560 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root 2 name', 'presence')
564 describe('Video abuse for moderators notification' , function () {
565 let baseParams: CheckerBaseParams
571 socketNotifications: adminNotifications,
572 token: servers[0].accessToken
576 it('Should send a notification to moderators on local video abuse', async function () {
579 const name = 'video for abuse ' + uuidv4()
580 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
581 const uuid = resVideo.body.video.uuid
583 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
585 await waitJobs(servers)
586 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
589 it('Should send a notification to moderators on remote video abuse', async function () {
592 const name = 'video for abuse ' + uuidv4()
593 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
594 const uuid = resVideo.body.video.uuid
596 await waitJobs(servers)
598 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
600 await waitJobs(servers)
601 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
605 describe('Video blacklist on my video', function () {
606 let baseParams: CheckerBaseParams
612 socketNotifications: userNotifications,
613 token: userAccessToken
617 it('Should send a notification to video owner on blacklist', async function () {
620 const name = 'video for abuse ' + uuidv4()
621 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
622 const uuid = resVideo.body.video.uuid
624 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
626 await waitJobs(servers)
627 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
630 it('Should send a notification to video owner on unblacklist', async function () {
633 const name = 'video for abuse ' + uuidv4()
634 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
635 const uuid = resVideo.body.video.uuid
637 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
639 await waitJobs(servers)
640 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
641 await waitJobs(servers)
644 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
648 describe('My video is published', function () {
649 let baseParams: CheckerBaseParams
655 socketNotifications: adminNotificationsServer2,
656 token: servers[1].accessToken
660 it('Should not send a notification if transcoding is not enabled', async function () {
661 const { name, uuid } = await uploadVideoByLocalAccount(servers)
662 await waitJobs(servers)
664 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
667 it('Should not send a notification if the wait transcoding is false', async function () {
670 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
671 await waitJobs(servers)
673 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
675 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
679 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
682 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
683 await waitJobs(servers)
685 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
688 it('Should send a notification with a transcoded video', async function () {
691 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
692 await waitJobs(servers)
694 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
697 it('Should send a notification when an imported video is transcoded', async function () {
700 const name = 'video import ' + uuidv4()
705 privacy: VideoPrivacy.PUBLIC,
706 targetUrl: getYoutubeVideoUrl(),
707 waitTranscoding: true
709 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
710 const uuid = res.body.video.uuid
712 await waitJobs(servers)
713 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
716 it('Should send a notification when the scheduled update has been proceeded', async function () {
720 let updateAt = new Date(new Date().getTime() + 2000)
723 privacy: VideoPrivacy.PRIVATE,
725 updateAt: updateAt.toISOString(),
726 privacy: VideoPrivacy.PUBLIC
729 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
732 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
736 describe('My video is imported', function () {
737 let baseParams: CheckerBaseParams
743 socketNotifications: adminNotifications,
744 token: servers[0].accessToken
748 it('Should send a notification when the video import failed', async function () {
751 const name = 'video import ' + uuidv4()
756 privacy: VideoPrivacy.PRIVATE,
757 targetUrl: getBadVideoUrl()
759 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
760 const uuid = res.body.video.uuid
762 await waitJobs(servers)
763 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
766 it('Should send a notification when the video import succeeded', async function () {
769 const name = 'video import ' + uuidv4()
774 privacy: VideoPrivacy.PRIVATE,
775 targetUrl: getYoutubeVideoUrl()
777 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
778 const uuid = res.body.video.uuid
780 await waitJobs(servers)
781 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
785 describe('New registration', function () {
786 let baseParams: CheckerBaseParams
792 socketNotifications: adminNotifications,
793 token: servers[0].accessToken
797 it('Should send a notification only to moderators when a user registers on the instance', async function () {
798 await registerUser(servers[0].url, 'user_45', 'password')
800 await waitJobs(servers)
802 await checkUserRegistered(baseParams, 'user_45', 'presence')
804 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
805 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
809 describe('New actor follow', function () {
810 let baseParams: CheckerBaseParams
811 let myChannelName = 'super channel name'
812 let myUserName = 'super user name'
818 socketNotifications: userNotifications,
819 token: userAccessToken
824 accessToken: servers[0].accessToken,
825 displayName: 'super root name'
830 accessToken: userAccessToken,
831 displayName: myUserName
836 accessToken: servers[1].accessToken,
837 displayName: 'super root 2 name'
840 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
843 it('Should notify when a local channel is following one of our channel', async function () {
846 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
847 await waitJobs(servers)
849 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
851 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
854 it('Should notify when a remote channel is following one of our channel', async function () {
857 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
858 await waitJobs(servers)
860 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
862 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
865 it('Should notify when a local account is following one of our channel', async function () {
866 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001')
868 await waitJobs(servers)
870 await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
873 it('Should notify when a remote account is following one of our channel', async function () {
874 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001')
876 await waitJobs(servers)
878 await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
882 describe('Mark as read', function () {
883 it('Should mark as read some notifications', async function () {
884 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
885 const ids = res.body.data.map(n => n.id)
887 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
890 it('Should have the notifications marked as read', async function () {
891 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
893 const notifications = res.body.data as UserNotification[]
894 expect(notifications[ 0 ].read).to.be.false
895 expect(notifications[ 1 ].read).to.be.false
896 expect(notifications[ 2 ].read).to.be.true
897 expect(notifications[ 3 ].read).to.be.true
898 expect(notifications[ 4 ].read).to.be.true
899 expect(notifications[ 5 ].read).to.be.false
902 it('Should only list read notifications', async function () {
903 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
905 const notifications = res.body.data as UserNotification[]
906 for (const notification of notifications) {
907 expect(notification.read).to.be.true
911 it('Should only list unread notifications', async function () {
912 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
914 const notifications = res.body.data as UserNotification[]
915 for (const notification of notifications) {
916 expect(notification.read).to.be.false
920 it('Should mark as read all notifications', async function () {
921 await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
923 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
925 expect(res.body.total).to.equal(0)
926 expect(res.body.data).to.have.lengthOf(0)
930 describe('Notification settings', function () {
931 let baseParams: CheckerBaseParams
937 socketNotifications: userNotifications,
938 token: userAccessToken
942 it('Should not have notifications', async function () {
943 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
944 newVideoFromSubscription: UserNotificationSettingValue.NONE
948 const res = await getMyUserInformation(servers[0].url, userAccessToken)
949 const info = res.body as User
950 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
953 const { name, uuid } = await uploadVideoByLocalAccount(servers)
955 const check = { web: true, mail: true }
956 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
959 it('Should only have web notifications', async function () {
960 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
961 newVideoFromSubscription: UserNotificationSettingValue.WEB
965 const res = await getMyUserInformation(servers[0].url, userAccessToken)
966 const info = res.body as User
967 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
970 const { name, uuid } = await uploadVideoByLocalAccount(servers)
973 const check = { mail: true, web: false }
974 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
978 const check = { mail: false, web: true }
979 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
983 it('Should only have mail notifications', async function () {
984 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
985 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
989 const res = await getMyUserInformation(servers[0].url, userAccessToken)
990 const info = res.body as User
991 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
994 const { name, uuid } = await uploadVideoByLocalAccount(servers)
997 const check = { mail: false, web: true }
998 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1002 const check = { mail: true, web: false }
1003 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1007 it('Should have email and web notifications', async function () {
1008 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1009 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1013 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1014 const info = res.body as User
1015 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
1016 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1020 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1022 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
1026 after(async function () {
1027 MockSmtpServer.Instance.kill()
1029 killallServers(servers)