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 send a new mention notification after local comments', async function () {
512 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
513 const uuid = resVideo.body.video.uuid
515 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
516 const threadId = resThread.body.comment.id
519 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
521 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
522 const commentId = resComment.body.comment.id
525 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
528 it('Should send a new mention notification after remote comments', async function () {
531 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
532 const uuid = resVideo.body.video.uuid
534 await waitJobs(servers)
535 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1')
536 const threadId = resThread.body.comment.id
538 await waitJobs(servers)
539 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'presence')
541 const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001'
542 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, text)
543 const commentId = resComment.body.comment.id
545 await waitJobs(servers)
546 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root 2 name', 'presence')
550 describe('Video abuse for moderators notification' , function () {
551 let baseParams: CheckerBaseParams
557 socketNotifications: adminNotifications,
558 token: servers[0].accessToken
562 it('Should send a notification to moderators on local video abuse', async function () {
565 const name = 'video for abuse ' + uuidv4()
566 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
567 const uuid = resVideo.body.video.uuid
569 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
571 await waitJobs(servers)
572 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
575 it('Should send a notification to moderators on remote video abuse', async function () {
578 const name = 'video for abuse ' + uuidv4()
579 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
580 const uuid = resVideo.body.video.uuid
582 await waitJobs(servers)
584 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
586 await waitJobs(servers)
587 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
591 describe('Video blacklist on my video', function () {
592 let baseParams: CheckerBaseParams
598 socketNotifications: userNotifications,
599 token: userAccessToken
603 it('Should send a notification to video owner on blacklist', async function () {
606 const name = 'video for abuse ' + uuidv4()
607 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
608 const uuid = resVideo.body.video.uuid
610 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
612 await waitJobs(servers)
613 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
616 it('Should send a notification to video owner on unblacklist', async function () {
619 const name = 'video for abuse ' + uuidv4()
620 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
621 const uuid = resVideo.body.video.uuid
623 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
625 await waitJobs(servers)
626 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
627 await waitJobs(servers)
630 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
634 describe('My video is published', function () {
635 let baseParams: CheckerBaseParams
641 socketNotifications: adminNotificationsServer2,
642 token: servers[1].accessToken
646 it('Should not send a notification if transcoding is not enabled', async function () {
647 const { name, uuid } = await uploadVideoByLocalAccount(servers)
648 await waitJobs(servers)
650 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
653 it('Should not send a notification if the wait transcoding is false', async function () {
656 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
657 await waitJobs(servers)
659 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
661 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
665 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
668 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
669 await waitJobs(servers)
671 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
674 it('Should send a notification with a transcoded video', async function () {
677 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
678 await waitJobs(servers)
680 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
683 it('Should send a notification when an imported video is transcoded', async function () {
686 const name = 'video import ' + uuidv4()
691 privacy: VideoPrivacy.PUBLIC,
692 targetUrl: getYoutubeVideoUrl(),
693 waitTranscoding: true
695 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
696 const uuid = res.body.video.uuid
698 await waitJobs(servers)
699 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
702 it('Should send a notification when the scheduled update has been proceeded', async function () {
706 let updateAt = new Date(new Date().getTime() + 2000)
709 privacy: VideoPrivacy.PRIVATE,
711 updateAt: updateAt.toISOString(),
712 privacy: VideoPrivacy.PUBLIC
715 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
718 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
722 describe('My video is imported', function () {
723 let baseParams: CheckerBaseParams
729 socketNotifications: adminNotifications,
730 token: servers[0].accessToken
734 it('Should send a notification when the video import failed', async function () {
737 const name = 'video import ' + uuidv4()
742 privacy: VideoPrivacy.PRIVATE,
743 targetUrl: getBadVideoUrl()
745 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
746 const uuid = res.body.video.uuid
748 await waitJobs(servers)
749 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
752 it('Should send a notification when the video import succeeded', async function () {
755 const name = 'video import ' + uuidv4()
760 privacy: VideoPrivacy.PRIVATE,
761 targetUrl: getYoutubeVideoUrl()
763 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
764 const uuid = res.body.video.uuid
766 await waitJobs(servers)
767 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
771 describe('New registration', function () {
772 let baseParams: CheckerBaseParams
778 socketNotifications: adminNotifications,
779 token: servers[0].accessToken
783 it('Should send a notification only to moderators when a user registers on the instance', async function () {
784 await registerUser(servers[0].url, 'user_45', 'password')
786 await waitJobs(servers)
788 await checkUserRegistered(baseParams, 'user_45', 'presence')
790 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
791 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
795 describe('New actor follow', function () {
796 let baseParams: CheckerBaseParams
797 let myChannelName = 'super channel name'
798 let myUserName = 'super user name'
804 socketNotifications: userNotifications,
805 token: userAccessToken
810 accessToken: servers[0].accessToken,
811 displayName: 'super root name'
816 accessToken: userAccessToken,
817 displayName: myUserName
822 accessToken: servers[1].accessToken,
823 displayName: 'super root 2 name'
826 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
829 it('Should notify when a local channel is following one of our channel', async function () {
832 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
833 await waitJobs(servers)
835 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
837 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
840 it('Should notify when a remote channel is following one of our channel', async function () {
843 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
844 await waitJobs(servers)
846 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
848 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
851 it('Should notify when a local account is following one of our channel', async function () {
852 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001')
854 await waitJobs(servers)
856 await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
859 it('Should notify when a remote account is following one of our channel', async function () {
860 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001')
862 await waitJobs(servers)
864 await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
868 describe('Mark as read', function () {
869 it('Should mark as read some notifications', async function () {
870 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
871 const ids = res.body.data.map(n => n.id)
873 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
876 it('Should have the notifications marked as read', async function () {
877 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
879 const notifications = res.body.data as UserNotification[]
880 expect(notifications[ 0 ].read).to.be.false
881 expect(notifications[ 1 ].read).to.be.false
882 expect(notifications[ 2 ].read).to.be.true
883 expect(notifications[ 3 ].read).to.be.true
884 expect(notifications[ 4 ].read).to.be.true
885 expect(notifications[ 5 ].read).to.be.false
888 it('Should only list read notifications', async function () {
889 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
891 const notifications = res.body.data as UserNotification[]
892 for (const notification of notifications) {
893 expect(notification.read).to.be.true
897 it('Should only list unread notifications', async function () {
898 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
900 const notifications = res.body.data as UserNotification[]
901 for (const notification of notifications) {
902 expect(notification.read).to.be.false
906 it('Should mark as read all notifications', async function () {
907 await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
909 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
911 expect(res.body.total).to.equal(0)
912 expect(res.body.data).to.have.lengthOf(0)
916 describe('Notification settings', function () {
917 let baseParams: CheckerBaseParams
923 socketNotifications: userNotifications,
924 token: userAccessToken
928 it('Should not have notifications', async function () {
929 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
930 newVideoFromSubscription: UserNotificationSettingValue.NONE
934 const res = await getMyUserInformation(servers[0].url, userAccessToken)
935 const info = res.body as User
936 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
939 const { name, uuid } = await uploadVideoByLocalAccount(servers)
941 const check = { web: true, mail: true }
942 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
945 it('Should only have web notifications', async function () {
946 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
947 newVideoFromSubscription: UserNotificationSettingValue.WEB
951 const res = await getMyUserInformation(servers[0].url, userAccessToken)
952 const info = res.body as User
953 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
956 const { name, uuid } = await uploadVideoByLocalAccount(servers)
959 const check = { mail: true, web: false }
960 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
964 const check = { mail: false, web: true }
965 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
969 it('Should only have mail notifications', async function () {
970 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
971 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
975 const res = await getMyUserInformation(servers[0].url, userAccessToken)
976 const info = res.body as User
977 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
980 const { name, uuid } = await uploadVideoByLocalAccount(servers)
983 const check = { mail: false, web: true }
984 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
988 const check = { mail: true, web: false }
989 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
993 it('Should have email and web notifications', async function () {
994 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
995 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
999 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1000 const info = res.body as User
1001 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
1002 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1006 const { name, uuid } = await uploadVideoByLocalAccount(servers)
1008 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
1012 after(async function () {
1013 killallServers(servers)