]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/moderation/blocklist.ts
Introduce notifications command
[github/Chocobozzz/PeerTube.git] / server / tests / api / moderation / blocklist.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import {
6 BlocklistCommand,
7 cleanupTests,
8 CommentsCommand,
9 createUser,
10 doubleFollow,
11 flushAndRunMultipleServers,
12 getVideosList,
13 getVideosListWithToken,
14 ServerInfo,
15 setAccessTokensToServers,
16 uploadVideo,
17 userLogin,
18 waitJobs
19 } from '@shared/extra-utils'
20 import { UserNotificationType, Video } from '@shared/models'
21
22 const expect = chai.expect
23
24 async function checkAllVideos (server: ServerInfo, token: string) {
25 {
26 const res = await getVideosListWithToken(server.url, token)
27
28 expect(res.body.data).to.have.lengthOf(5)
29 }
30
31 {
32 const res = await getVideosList(server.url)
33
34 expect(res.body.data).to.have.lengthOf(5)
35 }
36 }
37
38 async function checkAllComments (server: ServerInfo, token: string, videoUUID: string) {
39 const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token })
40
41 const threads = data.filter(t => t.isDeleted === false)
42 expect(threads).to.have.lengthOf(2)
43
44 for (const thread of threads) {
45 const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId: thread.id, token })
46 expect(tree.children).to.have.lengthOf(1)
47 }
48 }
49
50 async function checkCommentNotification (
51 mainServer: ServerInfo,
52 comment: { server: ServerInfo, token: string, videoUUID: string, text: string },
53 check: 'presence' | 'absence'
54 ) {
55 const command = comment.server.commentsCommand
56
57 const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text })
58
59 await waitJobs([ mainServer, comment.server ])
60
61 const { data } = await mainServer.notificationsCommand.list({ start: 0, count: 30 })
62 const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
63
64 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
65 else expect(commentNotifications).to.have.lengthOf(0)
66
67 await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId })
68
69 await waitJobs([ mainServer, comment.server ])
70 }
71
72 describe('Test blocklist', function () {
73 let servers: ServerInfo[]
74 let videoUUID1: string
75 let videoUUID2: string
76 let videoUUID3: string
77 let userToken1: string
78 let userModeratorToken: string
79 let userToken2: string
80
81 let command: BlocklistCommand
82 let commentsCommand: CommentsCommand[]
83
84 before(async function () {
85 this.timeout(120000)
86
87 servers = await flushAndRunMultipleServers(3)
88 await setAccessTokensToServers(servers)
89
90 command = servers[0].blocklistCommand
91 commentsCommand = servers.map(s => s.commentsCommand)
92
93 {
94 const user = { username: 'user1', password: 'password' }
95 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
96
97 userToken1 = await userLogin(servers[0], user)
98 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
99 }
100
101 {
102 const user = { username: 'moderator', password: 'password' }
103 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
104
105 userModeratorToken = await userLogin(servers[0], user)
106 }
107
108 {
109 const user = { username: 'user2', password: 'password' }
110 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
111
112 userToken2 = await userLogin(servers[1], user)
113 await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' })
114 }
115
116 {
117 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' })
118 videoUUID1 = res.body.video.uuid
119 }
120
121 {
122 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' })
123 videoUUID2 = res.body.video.uuid
124 }
125
126 {
127 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' })
128 videoUUID3 = res.body.video.uuid
129 }
130
131 await doubleFollow(servers[0], servers[1])
132 await doubleFollow(servers[0], servers[2])
133
134 {
135 const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' })
136 const reply = await commentsCommand[0].addReply({
137 token: userToken1,
138 videoId: videoUUID1,
139 toCommentId: created.id,
140 text: 'comment user 1'
141 })
142 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' })
143 }
144
145 {
146 const created = await commentsCommand[0].createThread({ token: userToken1, videoId: videoUUID1, text: 'comment user 1' })
147 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: created.id, text: 'comment root 1' })
148 }
149
150 await waitJobs(servers)
151 })
152
153 describe('User blocklist', function () {
154
155 describe('When managing account blocklist', function () {
156 it('Should list all videos', function () {
157 return checkAllVideos(servers[0], servers[0].accessToken)
158 })
159
160 it('Should list the comments', function () {
161 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
162 })
163
164 it('Should block a remote account', async function () {
165 await command.addToMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
166 })
167
168 it('Should hide its videos', async function () {
169 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
170
171 const videos: Video[] = res.body.data
172 expect(videos).to.have.lengthOf(4)
173
174 const v = videos.find(v => v.name === 'video user 2')
175 expect(v).to.be.undefined
176 })
177
178 it('Should block a local account', async function () {
179 await command.addToMyBlocklist({ account: 'user1' })
180 })
181
182 it('Should hide its videos', async function () {
183 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
184
185 const videos: Video[] = res.body.data
186 expect(videos).to.have.lengthOf(3)
187
188 const v = videos.find(v => v.name === 'video user 1')
189 expect(v).to.be.undefined
190 })
191
192 it('Should hide its comments', async function () {
193 const { data } = await commentsCommand[0].listThreads({
194 token: servers[0].accessToken,
195 videoId: videoUUID1,
196 start: 0,
197 count: 25,
198 sort: '-createdAt'
199 })
200
201 expect(data).to.have.lengthOf(1)
202 expect(data[0].totalReplies).to.equal(1)
203
204 const t = data.find(t => t.text === 'comment user 1')
205 expect(t).to.be.undefined
206
207 for (const thread of data) {
208 const tree = await commentsCommand[0].getThread({
209 videoId: videoUUID1,
210 threadId: thread.id,
211 token: servers[0].accessToken
212 })
213 expect(tree.children).to.have.lengthOf(0)
214 }
215 })
216
217 it('Should not have notifications from blocked accounts', async function () {
218 this.timeout(20000)
219
220 {
221 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
222 await checkCommentNotification(servers[0], comment, 'absence')
223 }
224
225 {
226 const comment = {
227 server: servers[0],
228 token: userToken1,
229 videoUUID: videoUUID2,
230 text: 'hello @root@localhost:' + servers[0].port
231 }
232 await checkCommentNotification(servers[0], comment, 'absence')
233 }
234 })
235
236 it('Should list all the videos with another user', async function () {
237 return checkAllVideos(servers[0], userToken1)
238 })
239
240 it('Should list blocked accounts', async function () {
241 {
242 const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
243 expect(body.total).to.equal(2)
244
245 const block = body.data[0]
246 expect(block.byAccount.displayName).to.equal('root')
247 expect(block.byAccount.name).to.equal('root')
248 expect(block.blockedAccount.displayName).to.equal('user2')
249 expect(block.blockedAccount.name).to.equal('user2')
250 expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
251 }
252
253 {
254 const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
255 expect(body.total).to.equal(2)
256
257 const block = body.data[0]
258 expect(block.byAccount.displayName).to.equal('root')
259 expect(block.byAccount.name).to.equal('root')
260 expect(block.blockedAccount.displayName).to.equal('user1')
261 expect(block.blockedAccount.name).to.equal('user1')
262 expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
263 }
264 })
265
266 it('Should not allow a remote blocked user to comment my videos', async function () {
267 this.timeout(60000)
268
269 {
270 await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' })
271 await waitJobs(servers)
272
273 await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' })
274 await waitJobs(servers)
275
276 const commentId = await commentsCommand[1].findCommentId({ videoId: videoUUID3, text: 'uploader' })
277 const message = 'reply by user 2'
278 const reply = await commentsCommand[1].addReply({ token: userToken2, videoId: videoUUID3, toCommentId: commentId, text: message })
279 await commentsCommand[1].addReply({ videoId: videoUUID3, toCommentId: reply.id, text: 'another reply' })
280
281 await waitJobs(servers)
282 }
283
284 // Server 2 has all the comments
285 {
286 const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
287
288 expect(data).to.have.lengthOf(2)
289 expect(data[0].text).to.equal('uploader')
290 expect(data[1].text).to.equal('comment user 2')
291
292 const tree = await commentsCommand[1].getThread({ videoId: videoUUID3, threadId: data[0].id })
293 expect(tree.children).to.have.lengthOf(1)
294 expect(tree.children[0].comment.text).to.equal('reply by user 2')
295 expect(tree.children[0].children).to.have.lengthOf(1)
296 expect(tree.children[0].children[0].comment.text).to.equal('another reply')
297 }
298
299 // Server 1 and 3 should only have uploader comments
300 for (const server of [ servers[0], servers[2] ]) {
301 const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
302
303 expect(data).to.have.lengthOf(1)
304 expect(data[0].text).to.equal('uploader')
305
306 const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id })
307
308 if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0)
309 else expect(tree.children).to.have.lengthOf(1)
310 }
311 })
312
313 it('Should unblock the remote account', async function () {
314 await command.removeFromMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
315 })
316
317 it('Should display its videos', async function () {
318 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
319
320 const videos: Video[] = res.body.data
321 expect(videos).to.have.lengthOf(4)
322
323 const v = videos.find(v => v.name === 'video user 2')
324 expect(v).not.to.be.undefined
325 })
326
327 it('Should display its comments on my video', async function () {
328 for (const server of servers) {
329 const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
330
331 // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment
332 if (server.serverNumber === 3) {
333 expect(data).to.have.lengthOf(1)
334 continue
335 }
336
337 expect(data).to.have.lengthOf(2)
338 expect(data[0].text).to.equal('uploader')
339 expect(data[1].text).to.equal('comment user 2')
340
341 const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id })
342 expect(tree.children).to.have.lengthOf(1)
343 expect(tree.children[0].comment.text).to.equal('reply by user 2')
344 expect(tree.children[0].children).to.have.lengthOf(1)
345 expect(tree.children[0].children[0].comment.text).to.equal('another reply')
346 }
347 })
348
349 it('Should unblock the local account', async function () {
350 await command.removeFromMyBlocklist({ account: 'user1' })
351 })
352
353 it('Should display its comments', function () {
354 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
355 })
356
357 it('Should have a notification from a non blocked account', async function () {
358 this.timeout(20000)
359
360 {
361 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
362 await checkCommentNotification(servers[0], comment, 'presence')
363 }
364
365 {
366 const comment = {
367 server: servers[0],
368 token: userToken1,
369 videoUUID: videoUUID2,
370 text: 'hello @root@localhost:' + servers[0].port
371 }
372 await checkCommentNotification(servers[0], comment, 'presence')
373 }
374 })
375 })
376
377 describe('When managing server blocklist', function () {
378
379 it('Should list all videos', function () {
380 return checkAllVideos(servers[0], servers[0].accessToken)
381 })
382
383 it('Should list the comments', function () {
384 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
385 })
386
387 it('Should block a remote server', async function () {
388 await command.addToMyBlocklist({ server: 'localhost:' + servers[1].port })
389 })
390
391 it('Should hide its videos', async function () {
392 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
393
394 const videos: Video[] = res.body.data
395 expect(videos).to.have.lengthOf(3)
396
397 const v1 = videos.find(v => v.name === 'video user 2')
398 const v2 = videos.find(v => v.name === 'video server 2')
399
400 expect(v1).to.be.undefined
401 expect(v2).to.be.undefined
402 })
403
404 it('Should list all the videos with another user', async function () {
405 return checkAllVideos(servers[0], userToken1)
406 })
407
408 it('Should hide its comments', async function () {
409 this.timeout(10000)
410
411 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
412
413 await waitJobs(servers)
414
415 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
416
417 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
418 })
419
420 it('Should not have notifications from blocked server', async function () {
421 this.timeout(20000)
422
423 {
424 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
425 await checkCommentNotification(servers[0], comment, 'absence')
426 }
427
428 {
429 const comment = {
430 server: servers[1],
431 token: userToken2,
432 videoUUID: videoUUID1,
433 text: 'hello @root@localhost:' + servers[0].port
434 }
435 await checkCommentNotification(servers[0], comment, 'absence')
436 }
437 })
438
439 it('Should list blocked servers', async function () {
440 const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
441 expect(body.total).to.equal(1)
442
443 const block = body.data[0]
444 expect(block.byAccount.displayName).to.equal('root')
445 expect(block.byAccount.name).to.equal('root')
446 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
447 })
448
449 it('Should unblock the remote server', async function () {
450 await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port })
451 })
452
453 it('Should display its videos', function () {
454 return checkAllVideos(servers[0], servers[0].accessToken)
455 })
456
457 it('Should display its comments', function () {
458 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
459 })
460
461 it('Should have notification from unblocked server', async function () {
462 this.timeout(20000)
463
464 {
465 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
466 await checkCommentNotification(servers[0], comment, 'presence')
467 }
468
469 {
470 const comment = {
471 server: servers[1],
472 token: userToken2,
473 videoUUID: videoUUID1,
474 text: 'hello @root@localhost:' + servers[0].port
475 }
476 await checkCommentNotification(servers[0], comment, 'presence')
477 }
478 })
479 })
480 })
481
482 describe('Server blocklist', function () {
483
484 describe('When managing account blocklist', function () {
485 it('Should list all videos', async function () {
486 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
487 await checkAllVideos(servers[0], token)
488 }
489 })
490
491 it('Should list the comments', async function () {
492 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
493 await checkAllComments(servers[0], token, videoUUID1)
494 }
495 })
496
497 it('Should block a remote account', async function () {
498 await command.addToServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
499 })
500
501 it('Should hide its videos', async function () {
502 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
503 const res = await getVideosListWithToken(servers[0].url, token)
504
505 const videos: Video[] = res.body.data
506 expect(videos).to.have.lengthOf(4)
507
508 const v = videos.find(v => v.name === 'video user 2')
509 expect(v).to.be.undefined
510 }
511 })
512
513 it('Should block a local account', async function () {
514 await command.addToServerBlocklist({ account: 'user1' })
515 })
516
517 it('Should hide its videos', async function () {
518 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
519 const res = await getVideosListWithToken(servers[0].url, token)
520
521 const videos: Video[] = res.body.data
522 expect(videos).to.have.lengthOf(3)
523
524 const v = videos.find(v => v.name === 'video user 1')
525 expect(v).to.be.undefined
526 }
527 })
528
529 it('Should hide its comments', async function () {
530 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
531 const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token })
532 const threads = data.filter(t => t.isDeleted === false)
533
534 expect(threads).to.have.lengthOf(1)
535 expect(threads[0].totalReplies).to.equal(1)
536
537 const t = threads.find(t => t.text === 'comment user 1')
538 expect(t).to.be.undefined
539
540 for (const thread of threads) {
541 const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token })
542 expect(tree.children).to.have.lengthOf(0)
543 }
544 }
545 })
546
547 it('Should not have notification from blocked accounts by instance', async function () {
548 this.timeout(20000)
549
550 {
551 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
552 await checkCommentNotification(servers[0], comment, 'absence')
553 }
554
555 {
556 const comment = {
557 server: servers[1],
558 token: userToken2,
559 videoUUID: videoUUID1,
560 text: 'hello @root@localhost:' + servers[0].port
561 }
562 await checkCommentNotification(servers[0], comment, 'absence')
563 }
564 })
565
566 it('Should list blocked accounts', async function () {
567 {
568 const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
569 expect(body.total).to.equal(2)
570
571 const block = body.data[0]
572 expect(block.byAccount.displayName).to.equal('peertube')
573 expect(block.byAccount.name).to.equal('peertube')
574 expect(block.blockedAccount.displayName).to.equal('user2')
575 expect(block.blockedAccount.name).to.equal('user2')
576 expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
577 }
578
579 {
580 const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
581 expect(body.total).to.equal(2)
582
583 const block = body.data[0]
584 expect(block.byAccount.displayName).to.equal('peertube')
585 expect(block.byAccount.name).to.equal('peertube')
586 expect(block.blockedAccount.displayName).to.equal('user1')
587 expect(block.blockedAccount.name).to.equal('user1')
588 expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
589 }
590 })
591
592 it('Should unblock the remote account', async function () {
593 await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
594 })
595
596 it('Should display its videos', async function () {
597 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
598 const res = await getVideosListWithToken(servers[0].url, token)
599
600 const videos: Video[] = res.body.data
601 expect(videos).to.have.lengthOf(4)
602
603 const v = videos.find(v => v.name === 'video user 2')
604 expect(v).not.to.be.undefined
605 }
606 })
607
608 it('Should unblock the local account', async function () {
609 await command.removeFromServerBlocklist({ account: 'user1' })
610 })
611
612 it('Should display its comments', async function () {
613 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
614 await checkAllComments(servers[0], token, videoUUID1)
615 }
616 })
617
618 it('Should have notifications from unblocked accounts', async function () {
619 this.timeout(20000)
620
621 {
622 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' }
623 await checkCommentNotification(servers[0], comment, 'presence')
624 }
625
626 {
627 const comment = {
628 server: servers[1],
629 token: userToken2,
630 videoUUID: videoUUID1,
631 text: 'hello @root@localhost:' + servers[0].port
632 }
633 await checkCommentNotification(servers[0], comment, 'presence')
634 }
635 })
636 })
637
638 describe('When managing server blocklist', function () {
639 it('Should list all videos', async function () {
640 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
641 await checkAllVideos(servers[0], token)
642 }
643 })
644
645 it('Should list the comments', async function () {
646 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
647 await checkAllComments(servers[0], token, videoUUID1)
648 }
649 })
650
651 it('Should block a remote server', async function () {
652 await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port })
653 })
654
655 it('Should hide its videos', async function () {
656 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
657 const res1 = await getVideosList(servers[0].url)
658 const res2 = await getVideosListWithToken(servers[0].url, token)
659
660 for (const res of [ res1, res2 ]) {
661 const videos: Video[] = res.body.data
662 expect(videos).to.have.lengthOf(3)
663
664 const v1 = videos.find(v => v.name === 'video user 2')
665 const v2 = videos.find(v => v.name === 'video server 2')
666
667 expect(v1).to.be.undefined
668 expect(v2).to.be.undefined
669 }
670 }
671 })
672
673 it('Should hide its comments', async function () {
674 this.timeout(10000)
675
676 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
677
678 await waitJobs(servers)
679
680 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
681
682 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
683 })
684
685 it('Should not have notification from blocked instances by instance', async function () {
686 this.timeout(50000)
687
688 {
689 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
690 await checkCommentNotification(servers[0], comment, 'absence')
691 }
692
693 {
694 const comment = {
695 server: servers[1],
696 token: userToken2,
697 videoUUID: videoUUID1,
698 text: 'hello @root@localhost:' + servers[0].port
699 }
700 await checkCommentNotification(servers[0], comment, 'absence')
701 }
702
703 {
704 const now = new Date()
705 await servers[1].followsCommand.unfollow({ target: servers[0] })
706 await waitJobs(servers)
707 await servers[1].followsCommand.follow({ targets: [ servers[0].host ] })
708
709 await waitJobs(servers)
710
711 const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 })
712 const commentNotifications = data.filter(n => {
713 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
714 })
715
716 expect(commentNotifications).to.have.lengthOf(0)
717 }
718 })
719
720 it('Should list blocked servers', async function () {
721 const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
722 expect(body.total).to.equal(1)
723
724 const block = body.data[0]
725 expect(block.byAccount.displayName).to.equal('peertube')
726 expect(block.byAccount.name).to.equal('peertube')
727 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
728 })
729
730 it('Should unblock the remote server', async function () {
731 await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port })
732 })
733
734 it('Should list all videos', async function () {
735 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
736 await checkAllVideos(servers[0], token)
737 }
738 })
739
740 it('Should list the comments', async function () {
741 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
742 await checkAllComments(servers[0], token, videoUUID1)
743 }
744 })
745
746 it('Should have notification from unblocked instances', async function () {
747 this.timeout(50000)
748
749 {
750 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
751 await checkCommentNotification(servers[0], comment, 'presence')
752 }
753
754 {
755 const comment = {
756 server: servers[1],
757 token: userToken2,
758 videoUUID: videoUUID1,
759 text: 'hello @root@localhost:' + servers[0].port
760 }
761 await checkCommentNotification(servers[0], comment, 'presence')
762 }
763
764 {
765 const now = new Date()
766 await servers[1].followsCommand.unfollow({ target: servers[0] })
767 await waitJobs(servers)
768 await servers[1].followsCommand.follow({ targets: [ servers[0].host ] })
769
770 await waitJobs(servers)
771
772 const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 })
773 const commentNotifications = data.filter(n => {
774 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
775 })
776
777 expect(commentNotifications).to.have.lengthOf(1)
778 }
779 })
780 })
781 })
782
783 after(async function () {
784 await cleanupTests(servers)
785 })
786 })