Add auto follow back support for instances
[oweals/peertube.git] / server / tests / api / notifications / user-notifications.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import {
6   addVideoToBlacklist,
7   cleanupTests,
8   createUser,
9   doubleFollow,
10   flushAndRunMultipleServers,
11   follow,
12   getCustomConfig,
13   getMyUserInformation,
14   getVideoCommentThreads,
15   getVideoThreadComments,
16   immutableAssign,
17   registerUser,
18   removeVideoFromBlacklist,
19   reportVideoAbuse, unfollow,
20   updateCustomConfig, updateCustomSubConfig,
21   updateMyUser,
22   updateVideo,
23   updateVideoChannel,
24   userLogin,
25   wait
26 } from '../../../../shared/extra-utils'
27 import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
28 import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
29 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
30 import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io'
31 import {
32   checkCommentMention,
33   CheckerBaseParams,
34   checkMyVideoImportIsFinished,
35   checkNewActorFollow,
36   checkNewBlacklistOnMyVideo,
37   checkNewCommentOnMyVideo,
38   checkNewInstanceFollower,
39   checkNewVideoAbuseForModerators,
40   checkNewVideoFromSubscription,
41   checkUserRegistered,
42   checkVideoAutoBlacklistForModerators,
43   checkVideoIsPublished,
44   getLastNotification,
45   getUserNotifications,
46   markAsReadAllNotifications,
47   markAsReadNotifications,
48   updateMyNotificationSettings,
49   checkAutoInstanceFollowing
50 } from '../../../../shared/extra-utils/users/user-notifications'
51 import {
52   User,
53   UserNotification,
54   UserNotificationSetting,
55   UserNotificationSettingValue,
56   UserNotificationType
57 } from '../../../../shared/models/users'
58 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
59 import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions'
60 import { VideoPrivacy } from '../../../../shared/models/videos'
61 import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
62 import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
63 import * as uuidv4 from 'uuid/v4'
64 import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/extra-utils/users/blocklist'
65 import { CustomConfig } from '../../../../shared/models/server'
66 import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
67
68 const expect = chai.expect
69
70 async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) {
71   const name = 'remote video ' + uuidv4()
72
73   const data = Object.assign({ name }, additionalParams)
74   const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data)
75
76   await waitJobs(servers)
77
78   return { uuid: res.body.video.uuid, name }
79 }
80
81 async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) {
82   const name = 'local video ' + uuidv4()
83
84   const data = Object.assign({ name }, additionalParams)
85   const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data)
86
87   await waitJobs(servers)
88
89   return { uuid: res.body.video.uuid, name }
90 }
91
92 describe('Test users notifications', function () {
93   let servers: ServerInfo[] = []
94   let userAccessToken: string
95   let userNotifications: UserNotification[] = []
96   let adminNotifications: UserNotification[] = []
97   let adminNotificationsServer2: UserNotification[] = []
98   const emails: object[] = []
99   let channelId: number
100
101   const allNotificationSettings: UserNotificationSetting = {
102     newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
103     newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
104     videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
105     videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
106     blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
107     myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
108     myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
109     commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
110     newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
111     newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
112     newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
113     autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
114   }
115
116   before(async function () {
117     this.timeout(120000)
118
119     const port = await MockSmtpServer.Instance.collectEmails(emails)
120
121     const overrideConfig = {
122       smtp: {
123         hostname: 'localhost',
124         port
125       }
126     }
127     servers = await flushAndRunMultipleServers(3, overrideConfig)
128
129     // Get the access tokens
130     await setAccessTokensToServers(servers)
131
132     // Server 1 and server 2 follow each other
133     await doubleFollow(servers[0], servers[1])
134
135     await waitJobs(servers)
136
137     const user = {
138       username: 'user_1',
139       password: 'super password'
140     }
141     await createUser({
142       url: servers[ 0 ].url,
143       accessToken: servers[ 0 ].accessToken,
144       username: user.username,
145       password: user.password,
146       videoQuota: 10 * 1000 * 1000
147     })
148     userAccessToken = await userLogin(servers[0], user)
149
150     await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
151     await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
152     await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
153
154     {
155       const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
156       socket.on('new-notification', n => userNotifications.push(n))
157     }
158     {
159       const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
160       socket.on('new-notification', n => adminNotifications.push(n))
161     }
162     {
163       const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
164       socket.on('new-notification', n => adminNotificationsServer2.push(n))
165     }
166
167     {
168       const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
169       channelId = resChannel.body.videoChannels[0].id
170     }
171   })
172
173   describe('New video from my subscription notification', function () {
174     let baseParams: CheckerBaseParams
175
176     before(() => {
177       baseParams = {
178         server: servers[0],
179         emails,
180         socketNotifications: userNotifications,
181         token: userAccessToken
182       }
183     })
184
185     it('Should not send notifications if the user does not follow the video publisher', async function () {
186       this.timeout(10000)
187
188       await uploadVideoByLocalAccount(servers)
189
190       const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
191       expect(notification).to.be.undefined
192
193       expect(emails).to.have.lengthOf(0)
194       expect(userNotifications).to.have.lengthOf(0)
195     })
196
197     it('Should send a new video notification if the user follows the local video publisher', async function () {
198       this.timeout(15000)
199
200       await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port)
201       await waitJobs(servers)
202
203       const { name, uuid } = await uploadVideoByLocalAccount(servers)
204       await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
205     })
206
207     it('Should send a new video notification from a remote account', async function () {
208       this.timeout(50000) // Server 2 has transcoding enabled
209
210       await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[1].port)
211       await waitJobs(servers)
212
213       const { name, uuid } = await uploadVideoByRemoteAccount(servers)
214       await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
215     })
216
217     it('Should send a new video notification on a scheduled publication', async function () {
218       this.timeout(20000)
219
220       // In 2 seconds
221       let updateAt = new Date(new Date().getTime() + 2000)
222
223       const data = {
224         privacy: VideoPrivacy.PRIVATE,
225         scheduleUpdate: {
226           updateAt: updateAt.toISOString(),
227           privacy: VideoPrivacy.PUBLIC
228         }
229       }
230       const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
231
232       await wait(6000)
233       await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
234     })
235
236     it('Should send a new video notification on a remote scheduled publication', async function () {
237       this.timeout(50000)
238
239       // In 2 seconds
240       let updateAt = new Date(new Date().getTime() + 2000)
241
242       const data = {
243         privacy: VideoPrivacy.PRIVATE,
244         scheduleUpdate: {
245           updateAt: updateAt.toISOString(),
246           privacy: VideoPrivacy.PUBLIC
247         }
248       }
249       const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
250       await waitJobs(servers)
251
252       await wait(6000)
253       await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
254     })
255
256     it('Should not send a notification before the video is published', async function () {
257       this.timeout(20000)
258
259       let updateAt = new Date(new Date().getTime() + 1000000)
260
261       const data = {
262         privacy: VideoPrivacy.PRIVATE,
263         scheduleUpdate: {
264           updateAt: updateAt.toISOString(),
265           privacy: VideoPrivacy.PUBLIC
266         }
267       }
268       const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
269
270       await wait(6000)
271       await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
272     })
273
274     it('Should send a new video notification when a video becomes public', async function () {
275       this.timeout(10000)
276
277       const data = { privacy: VideoPrivacy.PRIVATE }
278       const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
279
280       await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
281
282       await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
283
284       await wait(500)
285       await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
286     })
287
288     it('Should send a new video notification when a remote video becomes public', async function () {
289       this.timeout(20000)
290
291       const data = { privacy: VideoPrivacy.PRIVATE }
292       const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
293
294       await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
295
296       await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
297
298       await waitJobs(servers)
299       await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
300     })
301
302     it('Should not send a new video notification when a video becomes unlisted', async function () {
303       this.timeout(20000)
304
305       const data = { privacy: VideoPrivacy.PRIVATE }
306       const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
307
308       await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
309
310       await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
311     })
312
313     it('Should not send a new video notification when a remote video becomes unlisted', async function () {
314       this.timeout(20000)
315
316       const data = { privacy: VideoPrivacy.PRIVATE }
317       const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
318
319       await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
320
321       await waitJobs(servers)
322       await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
323     })
324
325     it('Should send a new video notification after a video import', async function () {
326       this.timeout(100000)
327
328       const name = 'video import ' + uuidv4()
329
330       const attributes = {
331         name,
332         channelId,
333         privacy: VideoPrivacy.PUBLIC,
334         targetUrl: getYoutubeVideoUrl()
335       }
336       const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
337       const uuid = res.body.video.uuid
338
339       await waitJobs(servers)
340
341       await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
342     })
343   })
344
345   describe('Comment on my video notifications', function () {
346     let baseParams: CheckerBaseParams
347
348     before(() => {
349       baseParams = {
350         server: servers[0],
351         emails,
352         socketNotifications: userNotifications,
353         token: userAccessToken
354       }
355     })
356
357     it('Should not send a new comment notification after a comment on another video', async function () {
358       this.timeout(10000)
359
360       const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
361       const uuid = resVideo.body.video.uuid
362
363       const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
364       const commentId = resComment.body.comment.id
365
366       await wait(500)
367       await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
368     })
369
370     it('Should not send a new comment notification if I comment my own video', async function () {
371       this.timeout(10000)
372
373       const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
374       const uuid = resVideo.body.video.uuid
375
376       const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
377       const commentId = resComment.body.comment.id
378
379       await wait(500)
380       await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
381     })
382
383     it('Should not send a new comment notification if the account is muted', async function () {
384       this.timeout(10000)
385
386       await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
387
388       const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
389       const uuid = resVideo.body.video.uuid
390
391       const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
392       const commentId = resComment.body.comment.id
393
394       await wait(500)
395       await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
396
397       await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
398     })
399
400     it('Should send a new comment notification after a local comment on my video', async function () {
401       this.timeout(10000)
402
403       const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
404       const uuid = resVideo.body.video.uuid
405
406       const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
407       const commentId = resComment.body.comment.id
408
409       await wait(500)
410       await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
411     })
412
413     it('Should send a new comment notification after a remote comment on my video', async function () {
414       this.timeout(10000)
415
416       const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
417       const uuid = resVideo.body.video.uuid
418
419       await waitJobs(servers)
420
421       await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
422
423       await waitJobs(servers)
424
425       const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
426       expect(resComment.body.data).to.have.lengthOf(1)
427       const commentId = resComment.body.data[0].id
428
429       await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
430     })
431
432     it('Should send a new comment notification after a local reply on my video', async function () {
433       this.timeout(10000)
434
435       const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
436       const uuid = resVideo.body.video.uuid
437
438       const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
439       const threadId = resThread.body.comment.id
440
441       const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
442       const commentId = resComment.body.comment.id
443
444       await wait(500)
445       await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
446     })
447
448     it('Should send a new comment notification after a remote reply on my video', async function () {
449       this.timeout(10000)
450
451       const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
452       const uuid = resVideo.body.video.uuid
453       await waitJobs(servers)
454
455       {
456         const resThread = await addVideoCommentThread(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, 'comment')
457         const threadId = resThread.body.comment.id
458         await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, threadId, 'reply')
459       }
460
461       await waitJobs(servers)
462
463       const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
464       expect(resThread.body.data).to.have.lengthOf(1)
465       const threadId = resThread.body.data[0].id
466
467       const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
468       const tree = resComments.body as VideoCommentThreadTree
469
470       expect(tree.children).to.have.lengthOf(1)
471       const commentId = tree.children[0].comment.id
472
473       await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
474     })
475   })
476
477   describe('Mention notifications', function () {
478     let baseParams: CheckerBaseParams
479
480     before(async () => {
481       baseParams = {
482         server: servers[0],
483         emails,
484         socketNotifications: userNotifications,
485         token: userAccessToken
486       }
487
488       await updateMyUser({
489         url: servers[0].url,
490         accessToken: servers[0].accessToken,
491         displayName: 'super root name'
492       })
493
494       await updateMyUser({
495         url: servers[1].url,
496         accessToken: servers[1].accessToken,
497         displayName: 'super root 2 name'
498       })
499     })
500
501     it('Should not send a new mention comment notification if I mention the video owner', async function () {
502       this.timeout(10000)
503
504       const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
505       const uuid = resVideo.body.video.uuid
506
507       const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
508       const commentId = resComment.body.comment.id
509
510       await wait(500)
511       await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
512     })
513
514     it('Should not send a new mention comment notification if I mention myself', async function () {
515       this.timeout(10000)
516
517       const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
518       const uuid = resVideo.body.video.uuid
519
520       const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
521       const commentId = resComment.body.comment.id
522
523       await wait(500)
524       await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
525     })
526
527     it('Should not send a new mention notification if the account is muted', async function () {
528       this.timeout(10000)
529
530       await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
531
532       const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
533       const uuid = resVideo.body.video.uuid
534
535       const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
536       const commentId = resComment.body.comment.id
537
538       await wait(500)
539       await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
540
541       await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
542     })
543
544     it('Should not send a new mention notification if the remote account mention a local account', async function () {
545       this.timeout(20000)
546
547       const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
548       const uuid = resVideo.body.video.uuid
549
550       await waitJobs(servers)
551       const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
552       const threadId = resThread.body.comment.id
553
554       await waitJobs(servers)
555       await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
556     })
557
558     it('Should send a new mention notification after local comments', async function () {
559       this.timeout(10000)
560
561       const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
562       const uuid = resVideo.body.video.uuid
563
564       const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
565       const threadId = resThread.body.comment.id
566
567       await wait(500)
568       await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
569
570       const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
571       const commentId = resComment.body.comment.id
572
573       await wait(500)
574       await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
575     })
576
577     it('Should send a new mention notification after remote comments', async function () {
578       this.timeout(20000)
579
580       const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
581       const uuid = resVideo.body.video.uuid
582
583       await waitJobs(servers)
584
585       const text1 = `hello @user_1@localhost:${servers[ 0 ].port} 1`
586       const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, text1)
587       const server2ThreadId = resThread.body.comment.id
588
589       await waitJobs(servers)
590
591       const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
592       expect(resThread2.body.data).to.have.lengthOf(1)
593       const server1ThreadId = resThread2.body.data[0].id
594       await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
595
596       const text2 = `@user_1@localhost:${servers[ 0 ].port} hello 2 @root@localhost:${servers[ 0 ].port}`
597       await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text2)
598
599       await waitJobs(servers)
600
601       const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
602       const tree = resComments.body as VideoCommentThreadTree
603
604       expect(tree.children).to.have.lengthOf(1)
605       const commentId = tree.children[0].comment.id
606
607       await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
608     })
609   })
610
611   describe('Video abuse for moderators notification' , function () {
612     let baseParams: CheckerBaseParams
613
614     before(() => {
615       baseParams = {
616         server: servers[0],
617         emails,
618         socketNotifications: adminNotifications,
619         token: servers[0].accessToken
620       }
621     })
622
623     it('Should send a notification to moderators on local video abuse', async function () {
624       this.timeout(10000)
625
626       const name = 'video for abuse ' + uuidv4()
627       const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
628       const uuid = resVideo.body.video.uuid
629
630       await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
631
632       await waitJobs(servers)
633       await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
634     })
635
636     it('Should send a notification to moderators on remote video abuse', async function () {
637       this.timeout(10000)
638
639       const name = 'video for abuse ' + uuidv4()
640       const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
641       const uuid = resVideo.body.video.uuid
642
643       await waitJobs(servers)
644
645       await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
646
647       await waitJobs(servers)
648       await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
649     })
650   })
651
652   describe('Video blacklist on my video', function () {
653     let baseParams: CheckerBaseParams
654
655     before(() => {
656       baseParams = {
657         server: servers[0],
658         emails,
659         socketNotifications: userNotifications,
660         token: userAccessToken
661       }
662     })
663
664     it('Should send a notification to video owner on blacklist', async function () {
665       this.timeout(10000)
666
667       const name = 'video for abuse ' + uuidv4()
668       const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
669       const uuid = resVideo.body.video.uuid
670
671       await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
672
673       await waitJobs(servers)
674       await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
675     })
676
677     it('Should send a notification to video owner on unblacklist', async function () {
678       this.timeout(10000)
679
680       const name = 'video for abuse ' + uuidv4()
681       const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
682       const uuid = resVideo.body.video.uuid
683
684       await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
685
686       await waitJobs(servers)
687       await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
688       await waitJobs(servers)
689
690       await wait(500)
691       await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
692     })
693   })
694
695   describe('My video is published', function () {
696     let baseParams: CheckerBaseParams
697
698     before(() => {
699       baseParams = {
700         server: servers[1],
701         emails,
702         socketNotifications: adminNotificationsServer2,
703         token: servers[1].accessToken
704       }
705     })
706
707     it('Should not send a notification if transcoding is not enabled', async function () {
708       this.timeout(10000)
709
710       const { name, uuid } = await uploadVideoByLocalAccount(servers)
711       await waitJobs(servers)
712
713       await checkVideoIsPublished(baseParams, name, uuid, 'absence')
714     })
715
716     it('Should not send a notification if the wait transcoding is false', async function () {
717       this.timeout(50000)
718
719       await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
720       await waitJobs(servers)
721
722       const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
723       if (notification) {
724         expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
725       }
726     })
727
728     it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
729       this.timeout(50000)
730
731       const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
732       await waitJobs(servers)
733
734       await checkVideoIsPublished(baseParams, name, uuid, 'presence')
735     })
736
737     it('Should send a notification with a transcoded video', async function () {
738       this.timeout(50000)
739
740       const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
741       await waitJobs(servers)
742
743       await checkVideoIsPublished(baseParams, name, uuid, 'presence')
744     })
745
746     it('Should send a notification when an imported video is transcoded', async function () {
747       this.timeout(50000)
748
749       const name = 'video import ' + uuidv4()
750
751       const attributes = {
752         name,
753         channelId,
754         privacy: VideoPrivacy.PUBLIC,
755         targetUrl: getYoutubeVideoUrl(),
756         waitTranscoding: true
757       }
758       const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
759       const uuid = res.body.video.uuid
760
761       await waitJobs(servers)
762       await checkVideoIsPublished(baseParams, name, uuid, 'presence')
763     })
764
765     it('Should send a notification when the scheduled update has been proceeded', async function () {
766       this.timeout(70000)
767
768       // In 2 seconds
769       let updateAt = new Date(new Date().getTime() + 2000)
770
771       const data = {
772         privacy: VideoPrivacy.PRIVATE,
773         scheduleUpdate: {
774           updateAt: updateAt.toISOString(),
775           privacy: VideoPrivacy.PUBLIC
776         }
777       }
778       const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
779
780       await wait(6000)
781       await checkVideoIsPublished(baseParams, name, uuid, 'presence')
782     })
783
784     it('Should not send a notification before the video is published', async function () {
785       this.timeout(20000)
786
787       let updateAt = new Date(new Date().getTime() + 1000000)
788
789       const data = {
790         privacy: VideoPrivacy.PRIVATE,
791         scheduleUpdate: {
792           updateAt: updateAt.toISOString(),
793           privacy: VideoPrivacy.PUBLIC
794         }
795       }
796       const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
797
798       await wait(6000)
799       await checkVideoIsPublished(baseParams, name, uuid, 'absence')
800     })
801   })
802
803   describe('My video is imported', function () {
804     let baseParams: CheckerBaseParams
805
806     before(() => {
807       baseParams = {
808         server: servers[0],
809         emails,
810         socketNotifications: adminNotifications,
811         token: servers[0].accessToken
812       }
813     })
814
815     it('Should send a notification when the video import failed', async function () {
816       this.timeout(70000)
817
818       const name = 'video import ' + uuidv4()
819
820       const attributes = {
821         name,
822         channelId,
823         privacy: VideoPrivacy.PRIVATE,
824         targetUrl: getBadVideoUrl()
825       }
826       const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
827       const uuid = res.body.video.uuid
828
829       await waitJobs(servers)
830       await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
831     })
832
833     it('Should send a notification when the video import succeeded', async function () {
834       this.timeout(70000)
835
836       const name = 'video import ' + uuidv4()
837
838       const attributes = {
839         name,
840         channelId,
841         privacy: VideoPrivacy.PRIVATE,
842         targetUrl: getYoutubeVideoUrl()
843       }
844       const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
845       const uuid = res.body.video.uuid
846
847       await waitJobs(servers)
848       await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
849     })
850   })
851
852   describe('New registration', function () {
853     let baseParams: CheckerBaseParams
854
855     before(() => {
856       baseParams = {
857         server: servers[0],
858         emails,
859         socketNotifications: adminNotifications,
860         token: servers[0].accessToken
861       }
862     })
863
864     it('Should send a notification only to moderators when a user registers on the instance', async function () {
865       this.timeout(10000)
866
867       await registerUser(servers[0].url, 'user_45', 'password')
868
869       await waitJobs(servers)
870
871       await checkUserRegistered(baseParams, 'user_45', 'presence')
872
873       const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
874       await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
875     })
876   })
877
878   describe('New instance follower', function () {
879     let baseParams: CheckerBaseParams
880
881     before(async () => {
882       baseParams = {
883         server: servers[0],
884         emails,
885         socketNotifications: adminNotifications,
886         token: servers[0].accessToken
887       }
888     })
889
890     it('Should send a notification only to admin when there is a new instance follower', async function () {
891       this.timeout(20000)
892
893       await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
894
895       await waitJobs(servers)
896
897       await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence')
898
899       const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
900       await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence')
901     })
902
903     it('Should send a notification on auto follow back', async function () {
904       this.timeout(40000)
905
906       await unfollow(servers[2].url, servers[2].accessToken, servers[0])
907       await waitJobs(servers)
908
909       const config = {
910         followings: {
911           instance: {
912             autoFollowBack: { enabled: true }
913           }
914         }
915       }
916       await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
917
918       await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
919
920       await waitJobs(servers)
921
922       const followerHost = servers[0].host
923       const followingHost = servers[2].host
924       await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence')
925
926       const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
927       await checkAutoInstanceFollowing(immutableAssign(baseParams, userOverride), followerHost, followingHost, 'absence')
928
929       config.followings.instance.autoFollowBack.enabled = false
930       await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
931     })
932   })
933
934   describe('New actor follow', function () {
935     let baseParams: CheckerBaseParams
936     let myChannelName = 'super channel name'
937     let myUserName = 'super user name'
938
939     before(async () => {
940       baseParams = {
941         server: servers[0],
942         emails,
943         socketNotifications: userNotifications,
944         token: userAccessToken
945       }
946
947       await updateMyUser({
948         url: servers[0].url,
949         accessToken: servers[0].accessToken,
950         displayName: 'super root name'
951       })
952
953       await updateMyUser({
954         url: servers[0].url,
955         accessToken: userAccessToken,
956         displayName: myUserName
957       })
958
959       await updateMyUser({
960         url: servers[1].url,
961         accessToken: servers[1].accessToken,
962         displayName: 'super root 2 name'
963       })
964
965       await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
966     })
967
968     it('Should notify when a local channel is following one of our channel', async function () {
969       this.timeout(10000)
970
971       await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
972       await waitJobs(servers)
973
974       await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
975
976       await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
977     })
978
979     it('Should notify when a remote channel is following one of our channel', async function () {
980       this.timeout(10000)
981
982       await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
983       await waitJobs(servers)
984
985       await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
986
987       await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
988     })
989
990     it('Should notify when a local account is following one of our channel', async function () {
991       this.timeout(10000)
992
993       await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port)
994
995       await waitJobs(servers)
996
997       await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
998     })
999
1000     it('Should notify when a remote account is following one of our channel', async function () {
1001       this.timeout(10000)
1002
1003       await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port)
1004
1005       await waitJobs(servers)
1006
1007       await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
1008     })
1009   })
1010
1011   describe('Video-related notifications when video auto-blacklist is enabled', function () {
1012     let userBaseParams: CheckerBaseParams
1013     let adminBaseParamsServer1: CheckerBaseParams
1014     let adminBaseParamsServer2: CheckerBaseParams
1015     let videoUUID: string
1016     let videoName: string
1017     let currentCustomConfig: CustomConfig
1018
1019     before(async () => {
1020
1021       adminBaseParamsServer1 = {
1022         server: servers[0],
1023         emails,
1024         socketNotifications: adminNotifications,
1025         token: servers[0].accessToken
1026       }
1027
1028       adminBaseParamsServer2 = {
1029         server: servers[1],
1030         emails,
1031         socketNotifications: adminNotificationsServer2,
1032         token: servers[1].accessToken
1033       }
1034
1035       userBaseParams = {
1036         server: servers[0],
1037         emails,
1038         socketNotifications: userNotifications,
1039         token: userAccessToken
1040       }
1041
1042       const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken)
1043       currentCustomConfig = resCustomConfig.body
1044       const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, {
1045         autoBlacklist: {
1046           videos: {
1047             ofUsers: {
1048               enabled: true
1049             }
1050           }
1051         }
1052       })
1053       // enable transcoding otherwise own publish notification after transcoding not expected
1054       autoBlacklistTestsCustomConfig.transcoding.enabled = true
1055       await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig)
1056
1057       await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
1058       await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
1059
1060     })
1061
1062     it('Should send notification to moderators on new video with auto-blacklist', async function () {
1063       this.timeout(20000)
1064
1065       videoName = 'video with auto-blacklist ' + uuidv4()
1066       const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
1067       videoUUID = resVideo.body.video.uuid
1068
1069       await waitJobs(servers)
1070       await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
1071     })
1072
1073     it('Should not send video publish notification if auto-blacklisted', async function () {
1074       await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence')
1075     })
1076
1077     it('Should not send a local user subscription notification if auto-blacklisted', async function () {
1078       await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence')
1079     })
1080
1081     it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
1082       await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence')
1083     })
1084
1085     it('Should send video published and unblacklist after video unblacklisted', async function () {
1086       this.timeout(20000)
1087
1088       await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID)
1089
1090       await waitJobs(servers)
1091
1092       // FIXME: Can't test as two notifications sent to same user and util only checks last one
1093       // One notification might be better anyways
1094       // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist')
1095       // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence')
1096     })
1097
1098     it('Should send a local user subscription notification after removed from blacklist', async function () {
1099       await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence')
1100     })
1101
1102     it('Should send a remote user subscription notification after removed from blacklist', async function () {
1103       await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence')
1104     })
1105
1106     it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
1107       this.timeout(20000)
1108
1109       let updateAt = new Date(new Date().getTime() + 1000000)
1110
1111       const name = 'video with auto-blacklist and future schedule ' + uuidv4()
1112
1113       const data = {
1114         name,
1115         privacy: VideoPrivacy.PRIVATE,
1116         scheduleUpdate: {
1117           updateAt: updateAt.toISOString(),
1118           privacy: VideoPrivacy.PUBLIC
1119         }
1120       }
1121
1122       const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1123       const uuid = resVideo.body.video.uuid
1124
1125       await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
1126
1127       await waitJobs(servers)
1128       await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
1129
1130       // FIXME: Can't test absence as two notifications sent to same user and util only checks last one
1131       // One notification might be better anyways
1132       // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1133
1134       await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1135       await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1136     })
1137
1138     it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
1139       this.timeout(20000)
1140
1141       // In 2 seconds
1142       let updateAt = new Date(new Date().getTime() + 2000)
1143
1144       const name = 'video with schedule done and still auto-blacklisted ' + uuidv4()
1145
1146       const data = {
1147         name,
1148         privacy: VideoPrivacy.PRIVATE,
1149         scheduleUpdate: {
1150           updateAt: updateAt.toISOString(),
1151           privacy: VideoPrivacy.PUBLIC
1152         }
1153       }
1154
1155       const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1156       const uuid = resVideo.body.video.uuid
1157
1158       await wait(6000)
1159       await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1160       await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1161       await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1162     })
1163
1164     it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
1165       this.timeout(20000)
1166
1167       const name = 'video without auto-blacklist ' + uuidv4()
1168
1169       // admin with blacklist right will not be auto-blacklisted
1170       const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name })
1171       const uuid = resVideo.body.video.uuid
1172
1173       await waitJobs(servers)
1174       await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
1175     })
1176
1177     after(async () => {
1178       await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig)
1179
1180       await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
1181       await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
1182     })
1183   })
1184
1185   describe('Mark as read', function () {
1186     it('Should mark as read some notifications', async function () {
1187       const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
1188       const ids = res.body.data.map(n => n.id)
1189
1190       await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
1191     })
1192
1193     it('Should have the notifications marked as read', async function () {
1194       const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
1195
1196       const notifications = res.body.data as UserNotification[]
1197       expect(notifications[ 0 ].read).to.be.false
1198       expect(notifications[ 1 ].read).to.be.false
1199       expect(notifications[ 2 ].read).to.be.true
1200       expect(notifications[ 3 ].read).to.be.true
1201       expect(notifications[ 4 ].read).to.be.true
1202       expect(notifications[ 5 ].read).to.be.false
1203     })
1204
1205     it('Should only list read notifications', async function () {
1206       const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
1207
1208       const notifications = res.body.data as UserNotification[]
1209       for (const notification of notifications) {
1210         expect(notification.read).to.be.true
1211       }
1212     })
1213
1214     it('Should only list unread notifications', async function () {
1215       const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1216
1217       const notifications = res.body.data as UserNotification[]
1218       for (const notification of notifications) {
1219         expect(notification.read).to.be.false
1220       }
1221     })
1222
1223     it('Should mark as read all notifications', async function () {
1224       await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
1225
1226       const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
1227
1228       expect(res.body.total).to.equal(0)
1229       expect(res.body.data).to.have.lengthOf(0)
1230     })
1231   })
1232
1233   describe('Notification settings', function () {
1234     let baseParams: CheckerBaseParams
1235
1236     before(() => {
1237       baseParams = {
1238         server: servers[0],
1239         emails,
1240         socketNotifications: userNotifications,
1241         token: userAccessToken
1242       }
1243     })
1244
1245     it('Should not have notifications', async function () {
1246       this.timeout(20000)
1247
1248       await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1249         newVideoFromSubscription: UserNotificationSettingValue.NONE
1250       }))
1251
1252       {
1253         const res = await getMyUserInformation(servers[0].url, userAccessToken)
1254         const info = res.body as User
1255         expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
1256       }
1257
1258       const { name, uuid } = await uploadVideoByLocalAccount(servers)
1259
1260       const check = { web: true, mail: true }
1261       await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1262     })
1263
1264     it('Should only have web notifications', async function () {
1265       this.timeout(20000)
1266
1267       await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1268         newVideoFromSubscription: UserNotificationSettingValue.WEB
1269       }))
1270
1271       {
1272         const res = await getMyUserInformation(servers[0].url, userAccessToken)
1273         const info = res.body as User
1274         expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
1275       }
1276
1277       const { name, uuid } = await uploadVideoByLocalAccount(servers)
1278
1279       {
1280         const check = { mail: true, web: false }
1281         await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1282       }
1283
1284       {
1285         const check = { mail: false, web: true }
1286         await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1287       }
1288     })
1289
1290     it('Should only have mail notifications', async function () {
1291       this.timeout(20000)
1292
1293       await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1294         newVideoFromSubscription: UserNotificationSettingValue.EMAIL
1295       }))
1296
1297       {
1298         const res = await getMyUserInformation(servers[0].url, userAccessToken)
1299         const info = res.body as User
1300         expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
1301       }
1302
1303       const { name, uuid } = await uploadVideoByLocalAccount(servers)
1304
1305       {
1306         const check = { mail: false, web: true }
1307         await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
1308       }
1309
1310       {
1311         const check = { mail: true, web: false }
1312         await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
1313       }
1314     })
1315
1316     it('Should have email and web notifications', async function () {
1317       this.timeout(20000)
1318
1319       await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1320         newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1321       }))
1322
1323       {
1324         const res = await getMyUserInformation(servers[0].url, userAccessToken)
1325         const info = res.body as User
1326         expect(info.notificationSettings.newVideoFromSubscription).to.equal(
1327           UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1328         )
1329       }
1330
1331       const { name, uuid } = await uploadVideoByLocalAccount(servers)
1332
1333       await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
1334     })
1335   })
1336
1337   after(async function () {
1338     MockSmtpServer.Instance.kill()
1339
1340     await cleanupTests(servers)
1341   })
1342 })