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