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 } from '../../../../shared/utils/users/user-notifications'
45 UserNotificationSetting,
46 UserNotificationSettingValue,
48 } from '../../../../shared/models/users'
49 import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
50 import { addUserSubscription, removeUserSubscription } from '../../../../shared/utils/users/user-subscriptions'
51 import { VideoPrivacy } from '../../../../shared/models/videos'
52 import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports'
53 import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments'
54 import * as uuidv4 from 'uuid/v4'
55 import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist'
57 const expect = chai.expect
59 async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) {
60 const name = 'remote video ' + uuidv4()
62 const data = Object.assign({ name }, additionalParams)
63 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data)
65 await waitJobs(servers)
67 return { uuid: res.body.video.uuid, name }
70 async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) {
71 const name = 'local video ' + uuidv4()
73 const data = Object.assign({ name }, additionalParams)
74 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data)
76 await waitJobs(servers)
78 return { uuid: res.body.video.uuid, name }
81 describe('Test users notifications', function () {
82 let servers: ServerInfo[] = []
83 let userAccessToken: string
84 let userNotifications: UserNotification[] = []
85 let adminNotifications: UserNotification[] = []
86 let adminNotificationsServer2: UserNotification[] = []
87 const emails: object[] = []
90 const allNotificationSettings: UserNotificationSetting = {
91 newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
92 newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
93 videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
94 blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
95 myVideoImportFinished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
96 myVideoPublished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
97 commentMention: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
98 newFollow: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
99 newUserRegistration: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL
102 before(async function () {
105 await MockSmtpServer.Instance.collectEmails(emails)
109 const overrideConfig = {
111 hostname: 'localhost'
114 servers = await flushAndRunMultipleServers(2, overrideConfig)
116 // Get the access tokens
117 await setAccessTokensToServers(servers)
119 // Server 1 and server 2 follow each other
120 await doubleFollow(servers[0], servers[1])
122 await waitJobs(servers)
126 password: 'super password'
128 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000)
129 userAccessToken = await userLogin(servers[0], user)
131 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
132 await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
133 await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
136 const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
137 socket.on('new-notification', n => userNotifications.push(n))
140 const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
141 socket.on('new-notification', n => adminNotifications.push(n))
144 const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
145 socket.on('new-notification', n => adminNotificationsServer2.push(n))
149 const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
150 channelId = resChannel.body.videoChannels[0].id
154 describe('New video from my subscription notification', function () {
155 let baseParams: CheckerBaseParams
161 socketNotifications: userNotifications,
162 token: userAccessToken
166 it('Should not send notifications if the user does not follow the video publisher', async function () {
167 await uploadVideoByLocalAccount(servers)
169 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
170 expect(notification).to.be.undefined
172 expect(emails).to.have.lengthOf(0)
173 expect(userNotifications).to.have.lengthOf(0)
176 it('Should send a new video notification if the user follows the local video publisher', async function () {
177 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
179 const { name, uuid } = await uploadVideoByLocalAccount(servers)
180 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
183 it('Should send a new video notification from a remote account', async function () {
184 this.timeout(50000) // Server 2 has transcoding enabled
186 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002')
188 const { name, uuid } = await uploadVideoByRemoteAccount(servers)
189 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
192 it('Should send a new video notification on a scheduled publication', async function () {
196 let updateAt = new Date(new Date().getTime() + 2000)
199 privacy: VideoPrivacy.PRIVATE,
201 updateAt: updateAt.toISOString(),
202 privacy: VideoPrivacy.PUBLIC
205 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
208 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
211 it('Should send a new video notification on a remote scheduled publication', async function () {
215 let updateAt = new Date(new Date().getTime() + 2000)
218 privacy: VideoPrivacy.PRIVATE,
220 updateAt: updateAt.toISOString(),
221 privacy: VideoPrivacy.PUBLIC
224 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
225 await waitJobs(servers)
228 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
231 it('Should not send a notification before the video is published', async function () {
234 let updateAt = new Date(new Date().getTime() + 100000)
237 privacy: VideoPrivacy.PRIVATE,
239 updateAt: updateAt.toISOString(),
240 privacy: VideoPrivacy.PUBLIC
243 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
246 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
249 it('Should send a new video notification when a video becomes public', async function () {
252 const data = { privacy: VideoPrivacy.PRIVATE }
253 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
255 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
257 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
260 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
263 it('Should send a new video notification when a remote video becomes public', async function () {
266 const data = { privacy: VideoPrivacy.PRIVATE }
267 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
269 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
271 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
273 await waitJobs(servers)
274 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
277 it('Should not send a new video notification when a video becomes unlisted', async function () {
280 const data = { privacy: VideoPrivacy.PRIVATE }
281 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
283 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
285 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
288 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
291 const data = { privacy: VideoPrivacy.PRIVATE }
292 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
294 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
296 await waitJobs(servers)
297 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
300 it('Should send a new video notification after a video import', async function () {
303 const name = 'video import ' + uuidv4()
308 privacy: VideoPrivacy.PUBLIC,
309 targetUrl: getYoutubeVideoUrl()
311 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
312 const uuid = res.body.video.uuid
314 await waitJobs(servers)
316 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
320 describe('Comment on my video notifications', function () {
321 let baseParams: CheckerBaseParams
327 socketNotifications: userNotifications,
328 token: userAccessToken
332 it('Should not send a new comment notification after a comment on another video', async function () {
335 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
336 const uuid = resVideo.body.video.uuid
338 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
339 const commentId = resComment.body.comment.id
342 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
345 it('Should not send a new comment notification if I comment my own video', async function () {
348 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
349 const uuid = resVideo.body.video.uuid
351 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
352 const commentId = resComment.body.comment.id
355 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
358 it('Should not send a new comment notification if the account is muted', async function () {
361 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
363 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
364 const uuid = resVideo.body.video.uuid
366 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
367 const commentId = resComment.body.comment.id
370 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
372 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
375 it('Should send a new comment notification after a local comment on my video', async function () {
378 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
379 const uuid = resVideo.body.video.uuid
381 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
382 const commentId = resComment.body.comment.id
385 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
388 it('Should send a new comment notification after a remote comment on my video', async function () {
391 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
392 const uuid = resVideo.body.video.uuid
394 await waitJobs(servers)
396 const resComment = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
397 const commentId = resComment.body.comment.id
399 await waitJobs(servers)
400 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
403 it('Should send a new comment notification after a local reply on my video', async function () {
406 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
407 const uuid = resVideo.body.video.uuid
409 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
410 const threadId = resThread.body.comment.id
412 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
413 const commentId = resComment.body.comment.id
416 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
419 it('Should send a new comment notification after a remote reply on my video', async function () {
422 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
423 const uuid = resVideo.body.video.uuid
424 await waitJobs(servers)
426 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
427 const threadId = resThread.body.comment.id
429 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply')
430 const commentId = resComment.body.comment.id
432 await waitJobs(servers)
433 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
437 describe('Mention notifications', function () {
438 let baseParams: CheckerBaseParams
444 socketNotifications: userNotifications,
445 token: userAccessToken
450 accessToken: servers[0].accessToken,
451 displayName: 'super root name'
456 accessToken: servers[1].accessToken,
457 displayName: 'super root 2 name'
461 it('Should not send a new mention comment notification if I mention the video owner', async function () {
464 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
465 const uuid = resVideo.body.video.uuid
467 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
468 const commentId = resComment.body.comment.id
471 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
474 it('Should not send a new mention comment notification if I mention myself', async function () {
477 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
478 const uuid = resVideo.body.video.uuid
480 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
481 const commentId = resComment.body.comment.id
484 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
487 it('Should not send a new mention notification if the account is muted', async function () {
490 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
492 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
493 const uuid = resVideo.body.video.uuid
495 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
496 const commentId = resComment.body.comment.id
499 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
501 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
504 it('Should send a new mention notification after local comments', async function () {
507 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
508 const uuid = resVideo.body.video.uuid
510 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
511 const threadId = resThread.body.comment.id
514 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
516 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
517 const commentId = resComment.body.comment.id
520 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
523 it('Should send a new mention notification after remote 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 await waitJobs(servers)
530 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1')
531 const threadId = resThread.body.comment.id
533 await waitJobs(servers)
534 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'presence')
536 const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001'
537 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, text)
538 const commentId = resComment.body.comment.id
540 await waitJobs(servers)
541 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root 2 name', 'presence')
545 describe('Video abuse for moderators notification' , function () {
546 let baseParams: CheckerBaseParams
552 socketNotifications: adminNotifications,
553 token: servers[0].accessToken
557 it('Should send a notification to moderators on local video abuse', async function () {
560 const name = 'video for abuse ' + uuidv4()
561 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
562 const uuid = resVideo.body.video.uuid
564 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
566 await waitJobs(servers)
567 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
570 it('Should send a notification to moderators on remote video abuse', async function () {
573 const name = 'video for abuse ' + uuidv4()
574 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
575 const uuid = resVideo.body.video.uuid
577 await waitJobs(servers)
579 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
581 await waitJobs(servers)
582 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
586 describe('Video blacklist on my video', function () {
587 let baseParams: CheckerBaseParams
593 socketNotifications: userNotifications,
594 token: userAccessToken
598 it('Should send a notification to video owner on blacklist', async function () {
601 const name = 'video for abuse ' + uuidv4()
602 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
603 const uuid = resVideo.body.video.uuid
605 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
607 await waitJobs(servers)
608 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
611 it('Should send a notification to video owner on unblacklist', async function () {
614 const name = 'video for abuse ' + uuidv4()
615 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
616 const uuid = resVideo.body.video.uuid
618 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
620 await waitJobs(servers)
621 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
622 await waitJobs(servers)
625 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
629 describe('My video is published', function () {
630 let baseParams: CheckerBaseParams
636 socketNotifications: adminNotificationsServer2,
637 token: servers[1].accessToken
641 it('Should not send a notification if transcoding is not enabled', async function () {
642 const { name, uuid } = await uploadVideoByLocalAccount(servers)
643 await waitJobs(servers)
645 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
648 it('Should not send a notification if the wait transcoding is false', async function () {
651 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
652 await waitJobs(servers)
654 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
656 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
660 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
663 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
664 await waitJobs(servers)
666 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
669 it('Should send a notification with a transcoded video', async function () {
672 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
673 await waitJobs(servers)
675 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
678 it('Should send a notification when an imported video is transcoded', async function () {
681 const name = 'video import ' + uuidv4()
686 privacy: VideoPrivacy.PUBLIC,
687 targetUrl: getYoutubeVideoUrl(),
688 waitTranscoding: true
690 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
691 const uuid = res.body.video.uuid
693 await waitJobs(servers)
694 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
697 it('Should send a notification when the scheduled update has been proceeded', async function () {
701 let updateAt = new Date(new Date().getTime() + 2000)
704 privacy: VideoPrivacy.PRIVATE,
706 updateAt: updateAt.toISOString(),
707 privacy: VideoPrivacy.PUBLIC
710 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
713 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
717 describe('My video is imported', function () {
718 let baseParams: CheckerBaseParams
724 socketNotifications: adminNotifications,
725 token: servers[0].accessToken
729 it('Should send a notification when the video import failed', async function () {
732 const name = 'video import ' + uuidv4()
737 privacy: VideoPrivacy.PRIVATE,
738 targetUrl: getBadVideoUrl()
740 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
741 const uuid = res.body.video.uuid
743 await waitJobs(servers)
744 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
747 it('Should send a notification when the video import succeeded', async function () {
750 const name = 'video import ' + uuidv4()
755 privacy: VideoPrivacy.PRIVATE,
756 targetUrl: getYoutubeVideoUrl()
758 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
759 const uuid = res.body.video.uuid
761 await waitJobs(servers)
762 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
766 describe('New registration', function () {
767 let baseParams: CheckerBaseParams
773 socketNotifications: adminNotifications,
774 token: servers[0].accessToken
778 it('Should send a notification only to moderators when a user registers on the instance', async function () {
779 await registerUser(servers[0].url, 'user_45', 'password')
781 await waitJobs(servers)
783 await checkUserRegistered(baseParams, 'user_45', 'presence')
785 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
786 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
790 describe('New actor follow', function () {
791 let baseParams: CheckerBaseParams
792 let myChannelName = 'super channel name'
793 let myUserName = 'super user name'
799 socketNotifications: userNotifications,
800 token: userAccessToken
805 accessToken: servers[0].accessToken,
806 displayName: 'super root name'
811 accessToken: userAccessToken,
812 displayName: myUserName
817 accessToken: servers[1].accessToken,
818 displayName: 'super root 2 name'
821 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
824 it('Should notify when a local channel is following one of our channel', async function () {
825 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
827 await waitJobs(servers)
829 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
831 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
834 it('Should notify when a remote channel is following one of our channel', async function () {
835 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
837 await waitJobs(servers)
839 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
841 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
844 it('Should notify when a local account is following one of our channel', async function () {
845 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001')
847 await waitJobs(servers)
849 await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
852 it('Should notify when a remote account is following one of our channel', async function () {
853 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001')
855 await waitJobs(servers)
857 await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
861 describe('Mark as read', function () {
862 it('Should mark as read some notifications', async function () {
863 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
864 const ids = res.body.data.map(n => n.id)
866 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
869 it('Should have the notifications marked as read', async function () {
870 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
872 const notifications = res.body.data as UserNotification[]
873 expect(notifications[ 0 ].read).to.be.false
874 expect(notifications[ 1 ].read).to.be.false
875 expect(notifications[ 2 ].read).to.be.true
876 expect(notifications[ 3 ].read).to.be.true
877 expect(notifications[ 4 ].read).to.be.true
878 expect(notifications[ 5 ].read).to.be.false
881 it('Should only list read notifications', async function () {
882 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
884 const notifications = res.body.data as UserNotification[]
885 for (const notification of notifications) {
886 expect(notification.read).to.be.true
890 it('Should only list unread notifications', async function () {
891 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
893 const notifications = res.body.data as UserNotification[]
894 for (const notification of notifications) {
895 expect(notification.read).to.be.false
900 describe('Notification settings', function () {
901 let baseParams: CheckerBaseParams
907 socketNotifications: userNotifications,
908 token: userAccessToken
912 it('Should not have notifications', async function () {
913 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
914 newVideoFromSubscription: UserNotificationSettingValue.NONE
918 const res = await getMyUserInformation(servers[0].url, userAccessToken)
919 const info = res.body as User
920 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
923 const { name, uuid } = await uploadVideoByLocalAccount(servers)
925 const check = { web: true, mail: true }
926 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
929 it('Should only have web notifications', async function () {
930 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
931 newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION
935 const res = await getMyUserInformation(servers[0].url, userAccessToken)
936 const info = res.body as User
937 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB_NOTIFICATION)
940 const { name, uuid } = await uploadVideoByLocalAccount(servers)
943 const check = { mail: true, web: false }
944 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
948 const check = { mail: false, web: true }
949 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
953 it('Should only have mail notifications', async function () {
954 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
955 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
959 const res = await getMyUserInformation(servers[0].url, userAccessToken)
960 const info = res.body as User
961 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
964 const { name, uuid } = await uploadVideoByLocalAccount(servers)
967 const check = { mail: false, web: true }
968 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
972 const check = { mail: true, web: false }
973 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
977 it('Should have email and web notifications', async function () {
978 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
979 newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL
983 const res = await getMyUserInformation(servers[0].url, userAccessToken)
984 const info = res.body as User
985 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL)
988 const { name, uuid } = await uploadVideoByLocalAccount(servers)
990 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
994 after(async function () {
995 killallServers(servers)