]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/users/user-notifications.ts
Add import finished and video published notifs
[github/Chocobozzz/PeerTube.git] / server / tests / api / users / user-notifications.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import {
6 addVideoToBlacklist,
7 createUser,
8 doubleFollow,
9 flushAndRunMultipleServers,
10 flushTests,
11 getMyUserInformation,
12 immutableAssign,
13 removeVideoFromBlacklist,
14 reportVideoAbuse,
15 updateVideo,
16 userLogin,
17 wait
18 } from '../../../../shared/utils'
19 import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index'
20 import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
21 import { waitJobs } from '../../../../shared/utils/server/jobs'
22 import { getUserNotificationSocket } from '../../../../shared/utils/socket/socket-io'
23 import {
24 CheckerBaseParams,
25 checkNewBlacklistOnMyVideo,
26 checkNewCommentOnMyVideo,
27 checkNewVideoAbuseForModerators,
28 checkNewVideoFromSubscription,
29 getLastNotification,
30 getUserNotifications,
31 markAsReadNotifications,
32 updateMyNotificationSettings,
33 checkVideoIsPublished, checkMyVideoImportIsFinished
34 } from '../../../../shared/utils/users/user-notifications'
35 import {
36 User,
37 UserNotification,
38 UserNotificationSetting,
39 UserNotificationSettingValue,
40 UserNotificationType
41 } from '../../../../shared/models/users'
42 import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
43 import { addUserSubscription } from '../../../../shared/utils/users/user-subscriptions'
44 import { VideoPrivacy } from '../../../../shared/models/videos'
45 import { getYoutubeVideoUrl, importVideo, getBadVideoUrl } from '../../../../shared/utils/videos/video-imports'
46 import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments'
47 import * as uuidv4 from 'uuid/v4'
48 import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist'
49
50 const expect = chai.expect
51
52 async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) {
53 const name = 'remote video ' + uuidv4()
54
55 const data = Object.assign({ name }, additionalParams)
56 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data)
57
58 await waitJobs(servers)
59
60 return { uuid: res.body.video.uuid, name }
61 }
62
63 async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) {
64 const name = 'local video ' + uuidv4()
65
66 const data = Object.assign({ name }, additionalParams)
67 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data)
68
69 await waitJobs(servers)
70
71 return { uuid: res.body.video.uuid, name }
72 }
73
74 describe('Test users notifications', function () {
75 let servers: ServerInfo[] = []
76 let userAccessToken: string
77 let userNotifications: UserNotification[] = []
78 let adminNotifications: UserNotification[] = []
79 let adminNotificationsServer2: UserNotification[] = []
80 const emails: object[] = []
81 let channelId: number
82
83 const allNotificationSettings: UserNotificationSetting = {
84 myVideoPublished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
85 myVideoImportFinished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
86 newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
87 newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
88 videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL,
89 blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL
90 }
91
92 before(async function () {
93 this.timeout(120000)
94
95 await MockSmtpServer.Instance.collectEmails(emails)
96
97 await flushTests()
98
99 const overrideConfig = {
100 smtp: {
101 hostname: 'localhost'
102 }
103 }
104 servers = await flushAndRunMultipleServers(2, overrideConfig)
105
106 // Get the access tokens
107 await setAccessTokensToServers(servers)
108
109 // Server 1 and server 2 follow each other
110 await doubleFollow(servers[0], servers[1])
111
112 await waitJobs(servers)
113
114 const user = {
115 username: 'user_1',
116 password: 'super password'
117 }
118 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000)
119 userAccessToken = await userLogin(servers[0], user)
120
121 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
122 await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
123 await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
124
125 {
126 const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
127 socket.on('new-notification', n => userNotifications.push(n))
128 }
129 {
130 const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
131 socket.on('new-notification', n => adminNotifications.push(n))
132 }
133 {
134 const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
135 socket.on('new-notification', n => adminNotificationsServer2.push(n))
136 }
137
138 {
139 const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
140 channelId = resChannel.body.videoChannels[0].id
141 }
142 })
143
144 describe('New video from my subscription notification', function () {
145 let baseParams: CheckerBaseParams
146
147 before(() => {
148 baseParams = {
149 server: servers[0],
150 emails,
151 socketNotifications: userNotifications,
152 token: userAccessToken
153 }
154 })
155
156 it('Should not send notifications if the user does not follow the video publisher', async function () {
157 await uploadVideoByLocalAccount(servers)
158
159 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
160 expect(notification).to.be.undefined
161
162 expect(emails).to.have.lengthOf(0)
163 expect(userNotifications).to.have.lengthOf(0)
164 })
165
166 it('Should send a new video notification if the user follows the local video publisher', async function () {
167 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
168
169 const { name, uuid } = await uploadVideoByLocalAccount(servers)
170 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
171 })
172
173 it('Should send a new video notification from a remote account', async function () {
174 this.timeout(50000) // Server 2 has transcoding enabled
175
176 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002')
177
178 const { name, uuid } = await uploadVideoByRemoteAccount(servers)
179 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
180 })
181
182 it('Should send a new video notification on a scheduled publication', async function () {
183 this.timeout(20000)
184
185 // In 2 seconds
186 let updateAt = new Date(new Date().getTime() + 2000)
187
188 const data = {
189 privacy: VideoPrivacy.PRIVATE,
190 scheduleUpdate: {
191 updateAt: updateAt.toISOString(),
192 privacy: VideoPrivacy.PUBLIC
193 }
194 }
195 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
196
197 await wait(6000)
198 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
199 })
200
201 it('Should send a new video notification on a remote scheduled publication', async function () {
202 this.timeout(20000)
203
204 // In 2 seconds
205 let updateAt = new Date(new Date().getTime() + 2000)
206
207 const data = {
208 privacy: VideoPrivacy.PRIVATE,
209 scheduleUpdate: {
210 updateAt: updateAt.toISOString(),
211 privacy: VideoPrivacy.PUBLIC
212 }
213 }
214 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
215 await waitJobs(servers)
216
217 await wait(6000)
218 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
219 })
220
221 it('Should not send a notification before the video is published', async function () {
222 this.timeout(20000)
223
224 let updateAt = new Date(new Date().getTime() + 100000)
225
226 const data = {
227 privacy: VideoPrivacy.PRIVATE,
228 scheduleUpdate: {
229 updateAt: updateAt.toISOString(),
230 privacy: VideoPrivacy.PUBLIC
231 }
232 }
233 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
234
235 await wait(6000)
236 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
237 })
238
239 it('Should send a new video notification when a video becomes public', async function () {
240 this.timeout(10000)
241
242 const data = { privacy: VideoPrivacy.PRIVATE }
243 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
244
245 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
246
247 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
248
249 await wait(500)
250 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
251 })
252
253 it('Should send a new video notification when a remote video becomes public', async function () {
254 this.timeout(20000)
255
256 const data = { privacy: VideoPrivacy.PRIVATE }
257 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
258
259 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
260
261 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
262
263 await waitJobs(servers)
264 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
265 })
266
267 it('Should not send a new video notification when a video becomes unlisted', async function () {
268 this.timeout(20000)
269
270 const data = { privacy: VideoPrivacy.PRIVATE }
271 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
272
273 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
274
275 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
276 })
277
278 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
279 this.timeout(20000)
280
281 const data = { privacy: VideoPrivacy.PRIVATE }
282 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
283
284 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
285
286 await waitJobs(servers)
287 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
288 })
289
290 it('Should send a new video notification after a video import', async function () {
291 this.timeout(30000)
292
293 const name = 'video import ' + uuidv4()
294
295 const attributes = {
296 name,
297 channelId,
298 privacy: VideoPrivacy.PUBLIC,
299 targetUrl: getYoutubeVideoUrl()
300 }
301 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
302 const uuid = res.body.video.uuid
303
304 await waitJobs(servers)
305
306 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
307 })
308 })
309
310 describe('Comment on my video notifications', function () {
311 let baseParams: CheckerBaseParams
312
313 before(() => {
314 baseParams = {
315 server: servers[0],
316 emails,
317 socketNotifications: userNotifications,
318 token: userAccessToken
319 }
320 })
321
322 it('Should not send a new comment notification after a comment on another video', async function () {
323 this.timeout(10000)
324
325 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
326 const uuid = resVideo.body.video.uuid
327
328 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
329 const commentId = resComment.body.comment.id
330
331 await wait(500)
332 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
333 })
334
335 it('Should not send a new comment notification if I comment my own video', async function () {
336 this.timeout(10000)
337
338 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
339 const uuid = resVideo.body.video.uuid
340
341 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
342 const commentId = resComment.body.comment.id
343
344 await wait(500)
345 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
346 })
347
348 it('Should not send a new comment notification if the account is muted', async function () {
349 this.timeout(10000)
350
351 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
352
353 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
354 const uuid = resVideo.body.video.uuid
355
356 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
357 const commentId = resComment.body.comment.id
358
359 await wait(500)
360 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
361
362 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
363 })
364
365 it('Should send a new comment notification after a local comment on my video', async function () {
366 this.timeout(10000)
367
368 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
369 const uuid = resVideo.body.video.uuid
370
371 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
372 const commentId = resComment.body.comment.id
373
374 await wait(500)
375 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
376 })
377
378 it('Should send a new comment notification after a remote comment on my video', async function () {
379 this.timeout(10000)
380
381 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
382 const uuid = resVideo.body.video.uuid
383
384 await waitJobs(servers)
385
386 const resComment = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
387 const commentId = resComment.body.comment.id
388
389 await waitJobs(servers)
390 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
391 })
392
393 it('Should send a new comment notification after a local reply on my video', async function () {
394 this.timeout(10000)
395
396 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
397 const uuid = resVideo.body.video.uuid
398
399 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
400 const threadId = resThread.body.comment.id
401
402 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
403 const commentId = resComment.body.comment.id
404
405 await wait(500)
406 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
407 })
408
409 it('Should send a new comment notification after a remote reply on my video', async function () {
410 this.timeout(10000)
411
412 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
413 const uuid = resVideo.body.video.uuid
414 await waitJobs(servers)
415
416 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
417 const threadId = resThread.body.comment.id
418
419 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply')
420 const commentId = resComment.body.comment.id
421
422 await waitJobs(servers)
423 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
424 })
425 })
426
427 describe('Video abuse for moderators notification' , function () {
428 let baseParams: CheckerBaseParams
429
430 before(() => {
431 baseParams = {
432 server: servers[0],
433 emails,
434 socketNotifications: adminNotifications,
435 token: servers[0].accessToken
436 }
437 })
438
439 it('Should send a notification to moderators on local video abuse', async function () {
440 this.timeout(10000)
441
442 const name = 'video for abuse ' + uuidv4()
443 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
444 const uuid = resVideo.body.video.uuid
445
446 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
447
448 await waitJobs(servers)
449 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
450 })
451
452 it('Should send a notification to moderators on remote video abuse', async function () {
453 this.timeout(10000)
454
455 const name = 'video for abuse ' + uuidv4()
456 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
457 const uuid = resVideo.body.video.uuid
458
459 await waitJobs(servers)
460
461 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
462
463 await waitJobs(servers)
464 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
465 })
466 })
467
468 describe('Video blacklist on my video', function () {
469 let baseParams: CheckerBaseParams
470
471 before(() => {
472 baseParams = {
473 server: servers[0],
474 emails,
475 socketNotifications: userNotifications,
476 token: userAccessToken
477 }
478 })
479
480 it('Should send a notification to video owner on blacklist', async function () {
481 this.timeout(10000)
482
483 const name = 'video for abuse ' + uuidv4()
484 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
485 const uuid = resVideo.body.video.uuid
486
487 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
488
489 await waitJobs(servers)
490 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
491 })
492
493 it('Should send a notification to video owner on unblacklist', async function () {
494 this.timeout(10000)
495
496 const name = 'video for abuse ' + uuidv4()
497 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
498 const uuid = resVideo.body.video.uuid
499
500 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
501
502 await waitJobs(servers)
503 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
504 await waitJobs(servers)
505
506 await wait(500)
507 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
508 })
509 })
510
511 describe('My video is published', function () {
512 let baseParams: CheckerBaseParams
513
514 before(() => {
515 baseParams = {
516 server: servers[1],
517 emails,
518 socketNotifications: adminNotificationsServer2,
519 token: servers[1].accessToken
520 }
521 })
522
523 it('Should not send a notification if transcoding is not enabled', async function () {
524 const { name, uuid } = await uploadVideoByLocalAccount(servers)
525 await waitJobs(servers)
526
527 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
528 })
529
530 it('Should not send a notification if the wait transcoding is false', async function () {
531 this.timeout(50000)
532
533 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
534 await waitJobs(servers)
535
536 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
537 if (notification) {
538 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
539 }
540 })
541
542 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
543 this.timeout(50000)
544
545 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
546 await waitJobs(servers)
547
548 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
549 })
550
551 it('Should send a notification with a transcoded video', async function () {
552 this.timeout(50000)
553
554 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
555 await waitJobs(servers)
556
557 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
558 })
559
560 it('Should send a notification when an imported video is transcoded', async function () {
561 this.timeout(50000)
562
563 const name = 'video import ' + uuidv4()
564
565 const attributes = {
566 name,
567 channelId,
568 privacy: VideoPrivacy.PUBLIC,
569 targetUrl: getYoutubeVideoUrl(),
570 waitTranscoding: true
571 }
572 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
573 const uuid = res.body.video.uuid
574
575 await waitJobs(servers)
576 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
577 })
578
579 it('Should send a notification when the scheduled update has been proceeded', async function () {
580 this.timeout(70000)
581
582 // In 2 seconds
583 let updateAt = new Date(new Date().getTime() + 2000)
584
585 const data = {
586 privacy: VideoPrivacy.PRIVATE,
587 scheduleUpdate: {
588 updateAt: updateAt.toISOString(),
589 privacy: VideoPrivacy.PUBLIC
590 }
591 }
592 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
593
594 await wait(6000)
595 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
596 })
597 })
598
599 describe('My video is imported', function () {
600 let baseParams: CheckerBaseParams
601
602 before(() => {
603 baseParams = {
604 server: servers[0],
605 emails,
606 socketNotifications: adminNotifications,
607 token: servers[0].accessToken
608 }
609 })
610
611 it('Should send a notification when the video import failed', async function () {
612 this.timeout(70000)
613
614 const name = 'video import ' + uuidv4()
615
616 const attributes = {
617 name,
618 channelId,
619 privacy: VideoPrivacy.PRIVATE,
620 targetUrl: getBadVideoUrl()
621 }
622 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
623 const uuid = res.body.video.uuid
624
625 await waitJobs(servers)
626 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
627 })
628
629 it('Should send a notification when the video import succeeded', async function () {
630 this.timeout(70000)
631
632 const name = 'video import ' + uuidv4()
633
634 const attributes = {
635 name,
636 channelId,
637 privacy: VideoPrivacy.PRIVATE,
638 targetUrl: getYoutubeVideoUrl()
639 }
640 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
641 const uuid = res.body.video.uuid
642
643 await waitJobs(servers)
644 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
645 })
646 })
647
648 describe('Mark as read', function () {
649 it('Should mark as read some notifications', async function () {
650 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
651 const ids = res.body.data.map(n => n.id)
652
653 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
654 })
655
656 it('Should have the notifications marked as read', async function () {
657 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
658
659 const notifications = res.body.data as UserNotification[]
660 expect(notifications[ 0 ].read).to.be.false
661 expect(notifications[ 1 ].read).to.be.false
662 expect(notifications[ 2 ].read).to.be.true
663 expect(notifications[ 3 ].read).to.be.true
664 expect(notifications[ 4 ].read).to.be.true
665 expect(notifications[ 5 ].read).to.be.false
666 })
667
668 it('Should only list read notifications', async function () {
669 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
670
671 const notifications = res.body.data as UserNotification[]
672 for (const notification of notifications) {
673 expect(notification.read).to.be.true
674 }
675 })
676
677 it('Should only list unread notifications', async function () {
678 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
679
680 const notifications = res.body.data as UserNotification[]
681 for (const notification of notifications) {
682 expect(notification.read).to.be.false
683 }
684 })
685 })
686
687 describe('Notification settings', function () {
688 let baseParams: CheckerBaseParams
689
690 before(() => {
691 baseParams = {
692 server: servers[0],
693 emails,
694 socketNotifications: userNotifications,
695 token: userAccessToken
696 }
697 })
698
699 it('Should not have notifications', async function () {
700 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
701 newVideoFromSubscription: UserNotificationSettingValue.NONE
702 }))
703
704 {
705 const res = await getMyUserInformation(servers[0].url, userAccessToken)
706 const info = res.body as User
707 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
708 }
709
710 const { name, uuid } = await uploadVideoByLocalAccount(servers)
711
712 const check = { web: true, mail: true }
713 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
714 })
715
716 it('Should only have web notifications', async function () {
717 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
718 newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION
719 }))
720
721 {
722 const res = await getMyUserInformation(servers[0].url, userAccessToken)
723 const info = res.body as User
724 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB_NOTIFICATION)
725 }
726
727 const { name, uuid } = await uploadVideoByLocalAccount(servers)
728
729 {
730 const check = { mail: true, web: false }
731 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
732 }
733
734 {
735 const check = { mail: false, web: true }
736 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
737 }
738 })
739
740 it('Should only have mail notifications', async function () {
741 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
742 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
743 }))
744
745 {
746 const res = await getMyUserInformation(servers[0].url, userAccessToken)
747 const info = res.body as User
748 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
749 }
750
751 const { name, uuid } = await uploadVideoByLocalAccount(servers)
752
753 {
754 const check = { mail: false, web: true }
755 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
756 }
757
758 {
759 const check = { mail: true, web: false }
760 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
761 }
762 })
763
764 it('Should have email and web notifications', async function () {
765 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
766 newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL
767 }))
768
769 {
770 const res = await getMyUserInformation(servers[0].url, userAccessToken)
771 const info = res.body as User
772 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL)
773 }
774
775 const { name, uuid } = await uploadVideoByLocalAccount(servers)
776
777 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
778 })
779 })
780
781 after(async function () {
782 killallServers(servers)
783 })
784 })