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