]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/users/user-notifications.ts
Merge branch 'release/v1.2.0'
[github/Chocobozzz/PeerTube.git] / server / tests / api / users / user-notifications.ts
CommitLineData
cef534ed
C
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 addVideoToBlacklist,
7 createUser,
8 doubleFollow,
9 flushAndRunMultipleServers,
10 flushTests,
11 getMyUserInformation,
12 immutableAssign,
f7cc67b4 13 registerUser,
cef534ed
C
14 removeVideoFromBlacklist,
15 reportVideoAbuse,
f7cc67b4 16 updateMyUser,
cef534ed 17 updateVideo,
f7cc67b4 18 updateVideoChannel,
cef534ed
C
19 userLogin,
20 wait
21} from '../../../../shared/utils'
22import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index'
23import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
24import { waitJobs } from '../../../../shared/utils/server/jobs'
25import { getUserNotificationSocket } from '../../../../shared/utils/socket/socket-io'
26import {
f7cc67b4 27 checkCommentMention,
cef534ed 28 CheckerBaseParams,
f7cc67b4
C
29 checkMyVideoImportIsFinished,
30 checkNewActorFollow,
cef534ed
C
31 checkNewBlacklistOnMyVideo,
32 checkNewCommentOnMyVideo,
33 checkNewVideoAbuseForModerators,
34 checkNewVideoFromSubscription,
f7cc67b4
C
35 checkUserRegistered,
36 checkVideoIsPublished,
cef534ed
C
37 getLastNotification,
38 getUserNotifications,
39 markAsReadNotifications,
2f1548fd
C
40 updateMyNotificationSettings,
41 markAsReadAllNotifications
cef534ed 42} from '../../../../shared/utils/users/user-notifications'
dc133480
C
43import {
44 User,
45 UserNotification,
46 UserNotificationSetting,
47 UserNotificationSettingValue,
48 UserNotificationType
49} from '../../../../shared/models/users'
cef534ed 50import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
f7cc67b4 51import { addUserSubscription, removeUserSubscription } from '../../../../shared/utils/users/user-subscriptions'
cef534ed 52import { VideoPrivacy } from '../../../../shared/models/videos'
f7cc67b4 53import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports'
cef534ed 54import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments'
dc133480
C
55import * as uuidv4 from 'uuid/v4'
56import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist'
cef534ed
C
57
58const expect = chai.expect
59
dc133480
C
60async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) {
61 const name = 'remote video ' + uuidv4()
62
63 const data = Object.assign({ name }, additionalParams)
cef534ed
C
64 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data)
65
66 await waitJobs(servers)
67
dc133480 68 return { uuid: res.body.video.uuid, name }
cef534ed
C
69}
70
dc133480
C
71async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) {
72 const name = 'local video ' + uuidv4()
73
74 const data = Object.assign({ name }, additionalParams)
cef534ed
C
75 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data)
76
77 await waitJobs(servers)
78
dc133480 79 return { uuid: res.body.video.uuid, name }
cef534ed
C
80}
81
82describe('Test users notifications', function () {
83 let servers: ServerInfo[] = []
84 let userAccessToken: string
85 let userNotifications: UserNotification[] = []
86 let adminNotifications: UserNotification[] = []
dc133480 87 let adminNotificationsServer2: UserNotification[] = []
cef534ed 88 const emails: object[] = []
dc133480
C
89 let channelId: number
90
91 const allNotificationSettings: UserNotificationSetting = {
2f1548fd
C
92 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
93 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
94 videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
95 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
96 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
97 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
98 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
99 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
100 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
dc133480 101 }
cef534ed
C
102
103 before(async function () {
104 this.timeout(120000)
105
106 await MockSmtpServer.Instance.collectEmails(emails)
107
108 await flushTests()
109
110 const overrideConfig = {
111 smtp: {
112 hostname: 'localhost'
113 }
114 }
115 servers = await flushAndRunMultipleServers(2, overrideConfig)
116
117 // Get the access tokens
118 await setAccessTokensToServers(servers)
119
120 // Server 1 and server 2 follow each other
121 await doubleFollow(servers[0], servers[1])
122
123 await waitJobs(servers)
124
125 const user = {
126 username: 'user_1',
127 password: 'super password'
128 }
129 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000)
130 userAccessToken = await userLogin(servers[0], user)
131
dc133480
C
132 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
133 await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings)
134 await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
cef534ed
C
135
136 {
137 const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
138 socket.on('new-notification', n => userNotifications.push(n))
139 }
140 {
141 const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
142 socket.on('new-notification', n => adminNotifications.push(n))
143 }
dc133480
C
144 {
145 const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
146 socket.on('new-notification', n => adminNotificationsServer2.push(n))
147 }
148
149 {
150 const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
151 channelId = resChannel.body.videoChannels[0].id
152 }
cef534ed
C
153 })
154
155 describe('New video from my subscription notification', function () {
156 let baseParams: CheckerBaseParams
157
158 before(() => {
159 baseParams = {
160 server: servers[0],
161 emails,
162 socketNotifications: userNotifications,
163 token: userAccessToken
164 }
165 })
166
167 it('Should not send notifications if the user does not follow the video publisher', async function () {
dc133480 168 await uploadVideoByLocalAccount(servers)
cef534ed
C
169
170 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
171 expect(notification).to.be.undefined
172
173 expect(emails).to.have.lengthOf(0)
174 expect(userNotifications).to.have.lengthOf(0)
175 })
176
177 it('Should send a new video notification if the user follows the local video publisher', async function () {
89ada4e2 178 this.timeout(15000)
2f1548fd 179
cef534ed 180 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
2f1548fd 181 await waitJobs(servers)
cef534ed 182
dc133480
C
183 const { name, uuid } = await uploadVideoByLocalAccount(servers)
184 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
cef534ed
C
185 })
186
187 it('Should send a new video notification from a remote account', async function () {
188 this.timeout(50000) // Server 2 has transcoding enabled
189
190 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002')
2f1548fd 191 await waitJobs(servers)
cef534ed 192
dc133480
C
193 const { name, uuid } = await uploadVideoByRemoteAccount(servers)
194 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
cef534ed
C
195 })
196
197 it('Should send a new video notification on a scheduled publication', async function () {
198 this.timeout(20000)
199
cef534ed
C
200 // In 2 seconds
201 let updateAt = new Date(new Date().getTime() + 2000)
202
203 const data = {
204 privacy: VideoPrivacy.PRIVATE,
205 scheduleUpdate: {
206 updateAt: updateAt.toISOString(),
207 privacy: VideoPrivacy.PUBLIC
208 }
209 }
dc133480 210 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
cef534ed
C
211
212 await wait(6000)
dc133480 213 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
cef534ed
C
214 })
215
216 it('Should send a new video notification on a remote scheduled publication', async function () {
217 this.timeout(20000)
218
cef534ed
C
219 // In 2 seconds
220 let updateAt = new Date(new Date().getTime() + 2000)
221
222 const data = {
223 privacy: VideoPrivacy.PRIVATE,
224 scheduleUpdate: {
225 updateAt: updateAt.toISOString(),
226 privacy: VideoPrivacy.PUBLIC
227 }
228 }
dc133480 229 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
e8d246d5 230 await waitJobs(servers)
cef534ed
C
231
232 await wait(6000)
dc133480 233 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
cef534ed
C
234 })
235
236 it('Should not send a notification before the video is published', async function () {
237 this.timeout(20000)
238
cef534ed
C
239 let updateAt = new Date(new Date().getTime() + 100000)
240
241 const data = {
242 privacy: VideoPrivacy.PRIVATE,
243 scheduleUpdate: {
244 updateAt: updateAt.toISOString(),
245 privacy: VideoPrivacy.PUBLIC
246 }
247 }
dc133480 248 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
cef534ed
C
249
250 await wait(6000)
dc133480 251 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
cef534ed
C
252 })
253
254 it('Should send a new video notification when a video becomes public', async function () {
255 this.timeout(10000)
256
cef534ed 257 const data = { privacy: VideoPrivacy.PRIVATE }
dc133480 258 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
cef534ed 259
dc133480 260 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
cef534ed
C
261
262 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
263
264 await wait(500)
dc133480 265 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
cef534ed
C
266 })
267
268 it('Should send a new video notification when a remote video becomes public', async function () {
269 this.timeout(20000)
270
cef534ed 271 const data = { privacy: VideoPrivacy.PRIVATE }
dc133480 272 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
cef534ed 273
dc133480 274 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
cef534ed
C
275
276 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC })
277
278 await waitJobs(servers)
dc133480 279 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
cef534ed
C
280 })
281
282 it('Should not send a new video notification when a video becomes unlisted', async function () {
283 this.timeout(20000)
284
cef534ed 285 const data = { privacy: VideoPrivacy.PRIVATE }
dc133480 286 const { name, uuid } = await uploadVideoByLocalAccount(servers, data)
cef534ed
C
287
288 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
289
dc133480 290 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
cef534ed
C
291 })
292
293 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
294 this.timeout(20000)
295
cef534ed 296 const data = { privacy: VideoPrivacy.PRIVATE }
dc133480 297 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
cef534ed
C
298
299 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED })
300
301 await waitJobs(servers)
dc133480 302 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
cef534ed
C
303 })
304
305 it('Should send a new video notification after a video import', async function () {
306 this.timeout(30000)
307
dc133480 308 const name = 'video import ' + uuidv4()
cef534ed
C
309
310 const attributes = {
dc133480 311 name,
cef534ed
C
312 channelId,
313 privacy: VideoPrivacy.PUBLIC,
314 targetUrl: getYoutubeVideoUrl()
315 }
316 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
317 const uuid = res.body.video.uuid
318
319 await waitJobs(servers)
320
dc133480 321 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
cef534ed
C
322 })
323 })
324
325 describe('Comment on my video notifications', function () {
326 let baseParams: CheckerBaseParams
327
328 before(() => {
329 baseParams = {
330 server: servers[0],
331 emails,
332 socketNotifications: userNotifications,
333 token: userAccessToken
334 }
335 })
336
337 it('Should not send a new comment notification after a comment on another video', async function () {
338 this.timeout(10000)
339
340 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
341 const uuid = resVideo.body.video.uuid
342
343 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
344 const commentId = resComment.body.comment.id
345
346 await wait(500)
347 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
348 })
349
350 it('Should not send a new comment notification if I comment my own video', async function () {
351 this.timeout(10000)
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, userAccessToken, uuid, 'comment')
357 const commentId = resComment.body.comment.id
358
359 await wait(500)
360 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
361 })
362
dc133480
C
363 it('Should not send a new comment notification if the account is muted', async function () {
364 this.timeout(10000)
365
366 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
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, 'absence')
376
377 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
378 })
379
cef534ed
C
380 it('Should send a new comment notification after a local comment on my video', async function () {
381 this.timeout(10000)
382
383 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
384 const uuid = resVideo.body.video.uuid
385
386 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
387 const commentId = resComment.body.comment.id
388
389 await wait(500)
390 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
391 })
392
393 it('Should send a new comment notification after a remote comment 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 await waitJobs(servers)
400
401 const resComment = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
402 const commentId = resComment.body.comment.id
403
404 await waitJobs(servers)
405 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
406 })
407
408 it('Should send a new comment notification after a local reply on my video', async function () {
409 this.timeout(10000)
410
411 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
412 const uuid = resVideo.body.video.uuid
413
414 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
415 const threadId = resThread.body.comment.id
416
417 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
418 const commentId = resComment.body.comment.id
419
420 await wait(500)
421 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
422 })
423
424 it('Should send a new comment notification after a remote reply on my video', async function () {
425 this.timeout(10000)
426
427 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
428 const uuid = resVideo.body.video.uuid
429 await waitJobs(servers)
430
431 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
432 const threadId = resThread.body.comment.id
433
434 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply')
435 const commentId = resComment.body.comment.id
436
437 await waitJobs(servers)
438 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
439 })
440 })
441
f7cc67b4
C
442 describe('Mention notifications', function () {
443 let baseParams: CheckerBaseParams
444
445 before(async () => {
446 baseParams = {
447 server: servers[0],
448 emails,
449 socketNotifications: userNotifications,
450 token: userAccessToken
451 }
452
453 await updateMyUser({
454 url: servers[0].url,
455 accessToken: servers[0].accessToken,
456 displayName: 'super root name'
457 })
458
459 await updateMyUser({
460 url: servers[1].url,
461 accessToken: servers[1].accessToken,
462 displayName: 'super root 2 name'
463 })
464 })
465
466 it('Should not send a new mention comment notification if I mention the video owner', async function () {
467 this.timeout(10000)
468
469 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
470 const uuid = resVideo.body.video.uuid
471
472 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
473 const commentId = resComment.body.comment.id
474
475 await wait(500)
476 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
477 })
478
479 it('Should not send a new mention comment notification if I mention myself', async function () {
480 this.timeout(10000)
481
482 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
483 const uuid = resVideo.body.video.uuid
484
485 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
486 const commentId = resComment.body.comment.id
487
488 await wait(500)
489 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
490 })
491
492 it('Should not send a new mention notification if the account is muted', async function () {
493 this.timeout(10000)
494
495 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
496
497 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
498 const uuid = resVideo.body.video.uuid
499
500 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
501 const commentId = resComment.body.comment.id
502
503 await wait(500)
504 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
505
506 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
507 })
508
6e8cf67a
C
509 it('Should not send a new mention notification if the remote account mention a local account', async function () {
510 this.timeout(20000)
511
512 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
513 const uuid = resVideo.body.video.uuid
514
515 await waitJobs(servers)
516 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
517 const threadId = resThread.body.comment.id
518
519 await waitJobs(servers)
520 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
521 })
522
f7cc67b4
C
523 it('Should send a new mention notification after local comments', async function () {
524 this.timeout(10000)
525
526 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
527 const uuid = resVideo.body.video.uuid
528
529 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
530 const threadId = resThread.body.comment.id
531
532 await wait(500)
533 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
534
535 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
536 const commentId = resComment.body.comment.id
537
538 await wait(500)
539 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
540 })
541
542 it('Should send a new mention notification after remote comments', 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, 'hello @user_1@localhost:9001 1')
550 const threadId = resThread.body.comment.id
551
552 await waitJobs(servers)
553 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'presence')
554
555 const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001'
556 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, text)
557 const commentId = resComment.body.comment.id
558
559 await waitJobs(servers)
560 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root 2 name', 'presence')
561 })
562 })
563
cef534ed
C
564 describe('Video abuse for moderators notification' , function () {
565 let baseParams: CheckerBaseParams
566
567 before(() => {
568 baseParams = {
569 server: servers[0],
570 emails,
571 socketNotifications: adminNotifications,
572 token: servers[0].accessToken
573 }
574 })
575
576 it('Should send a notification to moderators on local video abuse', async function () {
577 this.timeout(10000)
578
dc133480
C
579 const name = 'video for abuse ' + uuidv4()
580 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
cef534ed
C
581 const uuid = resVideo.body.video.uuid
582
583 await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason')
584
585 await waitJobs(servers)
dc133480 586 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
cef534ed
C
587 })
588
589 it('Should send a notification to moderators on remote video abuse', async function () {
590 this.timeout(10000)
591
dc133480
C
592 const name = 'video for abuse ' + uuidv4()
593 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
cef534ed
C
594 const uuid = resVideo.body.video.uuid
595
596 await waitJobs(servers)
597
598 await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason')
599
600 await waitJobs(servers)
dc133480 601 await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence')
cef534ed
C
602 })
603 })
604
605 describe('Video blacklist on my video', function () {
606 let baseParams: CheckerBaseParams
607
608 before(() => {
609 baseParams = {
610 server: servers[0],
611 emails,
612 socketNotifications: userNotifications,
613 token: userAccessToken
614 }
615 })
616
617 it('Should send a notification to video owner on blacklist', async function () {
618 this.timeout(10000)
619
dc133480
C
620 const name = 'video for abuse ' + uuidv4()
621 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
cef534ed
C
622 const uuid = resVideo.body.video.uuid
623
624 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
625
626 await waitJobs(servers)
dc133480 627 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
cef534ed
C
628 })
629
630 it('Should send a notification to video owner on unblacklist', async function () {
631 this.timeout(10000)
632
dc133480
C
633 const name = 'video for abuse ' + uuidv4()
634 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
cef534ed
C
635 const uuid = resVideo.body.video.uuid
636
637 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid)
638
639 await waitJobs(servers)
640 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
641 await waitJobs(servers)
642
643 await wait(500)
dc133480
C
644 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
645 })
646 })
647
648 describe('My video is published', function () {
649 let baseParams: CheckerBaseParams
650
651 before(() => {
652 baseParams = {
653 server: servers[1],
654 emails,
655 socketNotifications: adminNotificationsServer2,
656 token: servers[1].accessToken
657 }
658 })
659
660 it('Should not send a notification if transcoding is not enabled', async function () {
661 const { name, uuid } = await uploadVideoByLocalAccount(servers)
662 await waitJobs(servers)
663
664 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
665 })
666
667 it('Should not send a notification if the wait transcoding is false', async function () {
668 this.timeout(50000)
669
670 await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
671 await waitJobs(servers)
672
673 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
674 if (notification) {
675 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
676 }
677 })
678
679 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
680 this.timeout(50000)
681
682 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
683 await waitJobs(servers)
684
685 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
686 })
687
688 it('Should send a notification with a transcoded video', async function () {
689 this.timeout(50000)
690
691 const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true })
692 await waitJobs(servers)
693
694 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
695 })
696
697 it('Should send a notification when an imported video is transcoded', async function () {
698 this.timeout(50000)
699
700 const name = 'video import ' + uuidv4()
701
702 const attributes = {
703 name,
704 channelId,
705 privacy: VideoPrivacy.PUBLIC,
706 targetUrl: getYoutubeVideoUrl(),
707 waitTranscoding: true
708 }
709 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
710 const uuid = res.body.video.uuid
711
712 await waitJobs(servers)
713 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
714 })
715
716 it('Should send a notification when the scheduled update has been proceeded', async function () {
717 this.timeout(70000)
718
719 // In 2 seconds
720 let updateAt = new Date(new Date().getTime() + 2000)
721
722 const data = {
723 privacy: VideoPrivacy.PRIVATE,
724 scheduleUpdate: {
725 updateAt: updateAt.toISOString(),
726 privacy: VideoPrivacy.PUBLIC
727 }
728 }
729 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
730
731 await wait(6000)
732 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
733 })
734 })
735
736 describe('My video is imported', function () {
737 let baseParams: CheckerBaseParams
738
739 before(() => {
740 baseParams = {
741 server: servers[0],
742 emails,
743 socketNotifications: adminNotifications,
744 token: servers[0].accessToken
745 }
746 })
747
748 it('Should send a notification when the video import failed', async function () {
749 this.timeout(70000)
750
751 const name = 'video import ' + uuidv4()
752
753 const attributes = {
754 name,
755 channelId,
756 privacy: VideoPrivacy.PRIVATE,
757 targetUrl: getBadVideoUrl()
758 }
759 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
760 const uuid = res.body.video.uuid
761
762 await waitJobs(servers)
763 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence')
764 })
765
766 it('Should send a notification when the video import succeeded', async function () {
767 this.timeout(70000)
768
769 const name = 'video import ' + uuidv4()
770
771 const attributes = {
772 name,
773 channelId,
774 privacy: VideoPrivacy.PRIVATE,
775 targetUrl: getYoutubeVideoUrl()
776 }
777 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
778 const uuid = res.body.video.uuid
779
780 await waitJobs(servers)
781 await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence')
cef534ed
C
782 })
783 })
784
f7cc67b4
C
785 describe('New registration', function () {
786 let baseParams: CheckerBaseParams
787
788 before(() => {
789 baseParams = {
790 server: servers[0],
791 emails,
792 socketNotifications: adminNotifications,
793 token: servers[0].accessToken
794 }
795 })
796
797 it('Should send a notification only to moderators when a user registers on the instance', async function () {
798 await registerUser(servers[0].url, 'user_45', 'password')
799
800 await waitJobs(servers)
801
802 await checkUserRegistered(baseParams, 'user_45', 'presence')
803
804 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
805 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence')
806 })
807 })
808
809 describe('New actor follow', function () {
810 let baseParams: CheckerBaseParams
811 let myChannelName = 'super channel name'
812 let myUserName = 'super user name'
813
814 before(async () => {
815 baseParams = {
816 server: servers[0],
817 emails,
818 socketNotifications: userNotifications,
819 token: userAccessToken
820 }
821
822 await updateMyUser({
823 url: servers[0].url,
824 accessToken: servers[0].accessToken,
825 displayName: 'super root name'
826 })
827
828 await updateMyUser({
829 url: servers[0].url,
830 accessToken: userAccessToken,
831 displayName: myUserName
832 })
833
834 await updateMyUser({
835 url: servers[1].url,
836 accessToken: servers[1].accessToken,
837 displayName: 'super root 2 name'
838 })
839
840 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName })
841 })
842
843 it('Should notify when a local channel is following one of our channel', async function () {
2f1548fd 844 this.timeout(10000)
f7cc67b4 845
2f1548fd 846 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
f7cc67b4
C
847 await waitJobs(servers)
848
849 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
850
851 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
852 })
853
854 it('Should notify when a remote channel is following one of our channel', async function () {
2f1548fd 855 this.timeout(10000)
f7cc67b4 856
2f1548fd 857 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
f7cc67b4
C
858 await waitJobs(servers)
859
860 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
861
862 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
863 })
864
865 it('Should notify when a local account is following one of our channel', async function () {
866 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001')
867
868 await waitJobs(servers)
869
870 await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
871 })
872
873 it('Should notify when a remote account is following one of our channel', async function () {
874 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001')
875
876 await waitJobs(servers)
877
878 await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence')
879 })
880 })
881
cef534ed
C
882 describe('Mark as read', function () {
883 it('Should mark as read some notifications', async function () {
dc133480 884 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
cef534ed
C
885 const ids = res.body.data.map(n => n.id)
886
dc133480 887 await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
cef534ed
C
888 })
889
890 it('Should have the notifications marked as read', async function () {
dc133480
C
891 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
892
893 const notifications = res.body.data as UserNotification[]
894 expect(notifications[ 0 ].read).to.be.false
895 expect(notifications[ 1 ].read).to.be.false
896 expect(notifications[ 2 ].read).to.be.true
897 expect(notifications[ 3 ].read).to.be.true
898 expect(notifications[ 4 ].read).to.be.true
899 expect(notifications[ 5 ].read).to.be.false
900 })
901
902 it('Should only list read notifications', async function () {
903 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
cef534ed
C
904
905 const notifications = res.body.data as UserNotification[]
dc133480
C
906 for (const notification of notifications) {
907 expect(notification.read).to.be.true
908 }
909 })
910
911 it('Should only list unread notifications', async function () {
912 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
913
914 const notifications = res.body.data as UserNotification[]
915 for (const notification of notifications) {
916 expect(notification.read).to.be.false
917 }
cef534ed 918 })
2f1548fd
C
919
920 it('Should mark as read all notifications', async function () {
921 await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
922
923 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
924
925 expect(res.body.total).to.equal(0)
926 expect(res.body.data).to.have.lengthOf(0)
927 })
cef534ed
C
928 })
929
930 describe('Notification settings', function () {
cef534ed
C
931 let baseParams: CheckerBaseParams
932
933 before(() => {
934 baseParams = {
935 server: servers[0],
936 emails,
937 socketNotifications: userNotifications,
938 token: userAccessToken
939 }
940 })
941
942 it('Should not have notifications', async function () {
dc133480 943 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
cef534ed
C
944 newVideoFromSubscription: UserNotificationSettingValue.NONE
945 }))
946
947 {
948 const res = await getMyUserInformation(servers[0].url, userAccessToken)
949 const info = res.body as User
950 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
951 }
952
dc133480 953 const { name, uuid } = await uploadVideoByLocalAccount(servers)
cef534ed
C
954
955 const check = { web: true, mail: true }
dc133480 956 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
cef534ed
C
957 })
958
959 it('Should only have web notifications', async function () {
dc133480 960 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
2f1548fd 961 newVideoFromSubscription: UserNotificationSettingValue.WEB
cef534ed
C
962 }))
963
964 {
965 const res = await getMyUserInformation(servers[0].url, userAccessToken)
966 const info = res.body as User
2f1548fd 967 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
cef534ed
C
968 }
969
dc133480 970 const { name, uuid } = await uploadVideoByLocalAccount(servers)
cef534ed
C
971
972 {
973 const check = { mail: true, web: false }
dc133480 974 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
cef534ed
C
975 }
976
977 {
978 const check = { mail: false, web: true }
dc133480 979 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
cef534ed
C
980 }
981 })
982
983 it('Should only have mail notifications', async function () {
dc133480 984 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
cef534ed
C
985 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
986 }))
987
988 {
989 const res = await getMyUserInformation(servers[0].url, userAccessToken)
990 const info = res.body as User
991 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
992 }
993
dc133480 994 const { name, uuid } = await uploadVideoByLocalAccount(servers)
cef534ed
C
995
996 {
997 const check = { mail: false, web: true }
dc133480 998 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
cef534ed
C
999 }
1000
1001 {
1002 const check = { mail: true, web: false }
dc133480 1003 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
cef534ed
C
1004 }
1005 })
1006
1007 it('Should have email and web notifications', async function () {
dc133480 1008 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
2f1548fd 1009 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
cef534ed
C
1010 }))
1011
1012 {
1013 const res = await getMyUserInformation(servers[0].url, userAccessToken)
1014 const info = res.body as User
2f1548fd
C
1015 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
1016 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1017 )
cef534ed
C
1018 }
1019
dc133480 1020 const { name, uuid } = await uploadVideoByLocalAccount(servers)
cef534ed 1021
dc133480 1022 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
cef534ed
C
1023 })
1024 })
1025
1026 after(async function () {
89ada4e2
C
1027 MockSmtpServer.Instance.kill()
1028
cef534ed
C
1029 killallServers(servers)
1030 })
1031})