1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { UserNotificationType } from '@shared/models'
10 createMultipleServers,
13 setAccessTokensToServers,
14 setDefaultAccountAvatar,
16 } from '@shared/server-commands'
18 const expect = chai.expect
20 async function checkAllVideos (server: PeerTubeServer, token: string) {
22 const { data } = await server.videos.listWithToken({ token })
23 expect(data).to.have.lengthOf(5)
27 const { data } = await server.videos.list()
28 expect(data).to.have.lengthOf(5)
32 async function checkAllComments (server: PeerTubeServer, token: string, videoUUID: string) {
33 const { data } = await server.comments.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token })
35 const threads = data.filter(t => t.isDeleted === false)
36 expect(threads).to.have.lengthOf(2)
38 for (const thread of threads) {
39 const tree = await server.comments.getThread({ videoId: videoUUID, threadId: thread.id, token })
40 expect(tree.children).to.have.lengthOf(1)
44 async function checkCommentNotification (
45 mainServer: PeerTubeServer,
46 comment: { server: PeerTubeServer, token: string, videoUUID: string, text: string },
47 check: 'presence' | 'absence'
49 const command = comment.server.comments
51 const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text })
53 await waitJobs([ mainServer, comment.server ])
55 const { data } = await mainServer.notifications.list({ start: 0, count: 30 })
56 const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
58 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
59 else expect(commentNotifications).to.have.lengthOf(0)
61 await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId })
63 await waitJobs([ mainServer, comment.server ])
66 describe('Test blocklist', function () {
67 let servers: PeerTubeServer[]
68 let videoUUID1: string
69 let videoUUID2: string
70 let videoUUID3: string
71 let userToken1: string
72 let userModeratorToken: string
73 let userToken2: string
75 let command: BlocklistCommand
76 let commentsCommand: CommentsCommand[]
78 before(async function () {
81 servers = await createMultipleServers(3)
82 await setAccessTokensToServers(servers)
83 await setDefaultAccountAvatar(servers)
85 command = servers[0].blocklist
86 commentsCommand = servers.map(s => s.comments)
89 const user = { username: 'user1', password: 'password' }
90 await servers[0].users.create({ username: user.username, password: user.password })
92 userToken1 = await servers[0].login.getAccessToken(user)
93 await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } })
97 const user = { username: 'moderator', password: 'password' }
98 await servers[0].users.create({ username: user.username, password: user.password })
100 userModeratorToken = await servers[0].login.getAccessToken(user)
104 const user = { username: 'user2', password: 'password' }
105 await servers[1].users.create({ username: user.username, password: user.password })
107 userToken2 = await servers[1].login.getAccessToken(user)
108 await servers[1].videos.upload({ token: userToken2, attributes: { name: 'video user 2' } })
112 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
117 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
122 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } })
126 await doubleFollow(servers[0], servers[1])
127 await doubleFollow(servers[0], servers[2])
130 const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' })
131 const reply = await commentsCommand[0].addReply({
134 toCommentId: created.id,
135 text: 'comment user 1'
137 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' })
141 const created = await commentsCommand[0].createThread({ token: userToken1, videoId: videoUUID1, text: 'comment user 1' })
142 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: created.id, text: 'comment root 1' })
145 await waitJobs(servers)
148 describe('User blocklist', function () {
150 describe('When managing account blocklist', function () {
151 it('Should list all videos', function () {
152 return checkAllVideos(servers[0], servers[0].accessToken)
155 it('Should list the comments', function () {
156 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
159 it('Should block a remote account', async function () {
160 await command.addToMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
163 it('Should hide its videos', async function () {
164 const { data } = await servers[0].videos.listWithToken()
166 expect(data).to.have.lengthOf(4)
168 const v = data.find(v => v.name === 'video user 2')
169 expect(v).to.be.undefined
172 it('Should block a local account', async function () {
173 await command.addToMyBlocklist({ account: 'user1' })
176 it('Should hide its videos', async function () {
177 const { data } = await servers[0].videos.listWithToken()
179 expect(data).to.have.lengthOf(3)
181 const v = data.find(v => v.name === 'video user 1')
182 expect(v).to.be.undefined
185 it('Should hide its comments', async function () {
186 const { data } = await commentsCommand[0].listThreads({
187 token: servers[0].accessToken,
194 expect(data).to.have.lengthOf(1)
195 expect(data[0].totalReplies).to.equal(1)
197 const t = data.find(t => t.text === 'comment user 1')
198 expect(t).to.be.undefined
200 for (const thread of data) {
201 const tree = await commentsCommand[0].getThread({
204 token: servers[0].accessToken
206 expect(tree.children).to.have.lengthOf(0)
210 it('Should not have notifications from blocked accounts', async function () {
214 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
215 await checkCommentNotification(servers[0], comment, 'absence')
222 videoUUID: videoUUID2,
223 text: 'hello @root@localhost:' + servers[0].port
225 await checkCommentNotification(servers[0], comment, 'absence')
229 it('Should list all the videos with another user', async function () {
230 return checkAllVideos(servers[0], userToken1)
233 it('Should list blocked accounts', async function () {
235 const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
236 expect(body.total).to.equal(2)
238 const block = body.data[0]
239 expect(block.byAccount.displayName).to.equal('root')
240 expect(block.byAccount.name).to.equal('root')
241 expect(block.blockedAccount.displayName).to.equal('user2')
242 expect(block.blockedAccount.name).to.equal('user2')
243 expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
247 const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
248 expect(body.total).to.equal(2)
250 const block = body.data[0]
251 expect(block.byAccount.displayName).to.equal('root')
252 expect(block.byAccount.name).to.equal('root')
253 expect(block.blockedAccount.displayName).to.equal('user1')
254 expect(block.blockedAccount.name).to.equal('user1')
255 expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
259 it('Should get blocked status', async function () {
260 const remoteHandle = 'user2@' + servers[1].host
261 const localHandle = 'user1@' + servers[0].host
262 const unknownHandle = 'user5@' + servers[0].host
265 const status = await command.getStatus({ accounts: [ remoteHandle ] })
266 expect(Object.keys(status.accounts)).to.have.lengthOf(1)
267 expect(status.accounts[remoteHandle].blockedByUser).to.be.false
268 expect(status.accounts[remoteHandle].blockedByServer).to.be.false
270 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
274 const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ remoteHandle ] })
275 expect(Object.keys(status.accounts)).to.have.lengthOf(1)
276 expect(status.accounts[remoteHandle].blockedByUser).to.be.true
277 expect(status.accounts[remoteHandle].blockedByServer).to.be.false
279 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
283 const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ localHandle, remoteHandle, unknownHandle ] })
284 expect(Object.keys(status.accounts)).to.have.lengthOf(3)
286 for (const handle of [ localHandle, remoteHandle ]) {
287 expect(status.accounts[handle].blockedByUser).to.be.true
288 expect(status.accounts[handle].blockedByServer).to.be.false
291 expect(status.accounts[unknownHandle].blockedByUser).to.be.false
292 expect(status.accounts[unknownHandle].blockedByServer).to.be.false
294 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
298 it('Should not allow a remote blocked user to comment my videos', async function () {
302 await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' })
303 await waitJobs(servers)
305 await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' })
306 await waitJobs(servers)
308 const commentId = await commentsCommand[1].findCommentId({ videoId: videoUUID3, text: 'uploader' })
309 const message = 'reply by user 2'
310 const reply = await commentsCommand[1].addReply({ token: userToken2, videoId: videoUUID3, toCommentId: commentId, text: message })
311 await commentsCommand[1].addReply({ videoId: videoUUID3, toCommentId: reply.id, text: 'another reply' })
313 await waitJobs(servers)
316 // Server 2 has all the comments
318 const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
320 expect(data).to.have.lengthOf(2)
321 expect(data[0].text).to.equal('uploader')
322 expect(data[1].text).to.equal('comment user 2')
324 const tree = await commentsCommand[1].getThread({ videoId: videoUUID3, threadId: data[0].id })
325 expect(tree.children).to.have.lengthOf(1)
326 expect(tree.children[0].comment.text).to.equal('reply by user 2')
327 expect(tree.children[0].children).to.have.lengthOf(1)
328 expect(tree.children[0].children[0].comment.text).to.equal('another reply')
331 // Server 1 and 3 should only have uploader comments
332 for (const server of [ servers[0], servers[2] ]) {
333 const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
335 expect(data).to.have.lengthOf(1)
336 expect(data[0].text).to.equal('uploader')
338 const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
340 if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0)
341 else expect(tree.children).to.have.lengthOf(1)
345 it('Should unblock the remote account', async function () {
346 await command.removeFromMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
349 it('Should display its videos', async function () {
350 const { data } = await servers[0].videos.listWithToken()
351 expect(data).to.have.lengthOf(4)
353 const v = data.find(v => v.name === 'video user 2')
354 expect(v).not.to.be.undefined
357 it('Should display its comments on my video', async function () {
358 for (const server of servers) {
359 const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
361 // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment
362 if (server.serverNumber === 3) {
363 expect(data).to.have.lengthOf(1)
367 expect(data).to.have.lengthOf(2)
368 expect(data[0].text).to.equal('uploader')
369 expect(data[1].text).to.equal('comment user 2')
371 const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
372 expect(tree.children).to.have.lengthOf(1)
373 expect(tree.children[0].comment.text).to.equal('reply by user 2')
374 expect(tree.children[0].children).to.have.lengthOf(1)
375 expect(tree.children[0].children[0].comment.text).to.equal('another reply')
379 it('Should unblock the local account', async function () {
380 await command.removeFromMyBlocklist({ account: 'user1' })
383 it('Should display its comments', function () {
384 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
387 it('Should have a notification from a non blocked account', async function () {
391 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
392 await checkCommentNotification(servers[0], comment, 'presence')
399 videoUUID: videoUUID2,
400 text: 'hello @root@localhost:' + servers[0].port
402 await checkCommentNotification(servers[0], comment, 'presence')
407 describe('When managing server blocklist', function () {
409 it('Should list all videos', function () {
410 return checkAllVideos(servers[0], servers[0].accessToken)
413 it('Should list the comments', function () {
414 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
417 it('Should block a remote server', async function () {
418 await command.addToMyBlocklist({ server: 'localhost:' + servers[1].port })
421 it('Should hide its videos', async function () {
422 const { data } = await servers[0].videos.listWithToken()
424 expect(data).to.have.lengthOf(3)
426 const v1 = data.find(v => v.name === 'video user 2')
427 const v2 = data.find(v => v.name === 'video server 2')
429 expect(v1).to.be.undefined
430 expect(v2).to.be.undefined
433 it('Should list all the videos with another user', async function () {
434 return checkAllVideos(servers[0], userToken1)
437 it('Should hide its comments', async function () {
440 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
442 await waitJobs(servers)
444 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
446 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
449 it('Should not have notifications from blocked server', async function () {
453 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
454 await checkCommentNotification(servers[0], comment, 'absence')
461 videoUUID: videoUUID1,
462 text: 'hello @root@localhost:' + servers[0].port
464 await checkCommentNotification(servers[0], comment, 'absence')
468 it('Should list blocked servers', async function () {
469 const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
470 expect(body.total).to.equal(1)
472 const block = body.data[0]
473 expect(block.byAccount.displayName).to.equal('root')
474 expect(block.byAccount.name).to.equal('root')
475 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
478 it('Should get blocklist status', async function () {
479 const blockedServer = servers[1].host
480 const notBlockedServer = 'example.com'
483 const status = await command.getStatus({ hosts: [ blockedServer, notBlockedServer ] })
484 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
486 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
487 expect(status.hosts[blockedServer].blockedByUser).to.be.false
488 expect(status.hosts[blockedServer].blockedByServer).to.be.false
490 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
491 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
495 const status = await command.getStatus({ token: servers[0].accessToken, hosts: [ blockedServer, notBlockedServer ] })
496 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
498 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
499 expect(status.hosts[blockedServer].blockedByUser).to.be.true
500 expect(status.hosts[blockedServer].blockedByServer).to.be.false
502 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
503 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
507 it('Should unblock the remote server', async function () {
508 await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port })
511 it('Should display its videos', function () {
512 return checkAllVideos(servers[0], servers[0].accessToken)
515 it('Should display its comments', function () {
516 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
519 it('Should have notification from unblocked server', async function () {
523 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
524 await checkCommentNotification(servers[0], comment, 'presence')
531 videoUUID: videoUUID1,
532 text: 'hello @root@localhost:' + servers[0].port
534 await checkCommentNotification(servers[0], comment, 'presence')
540 describe('Server blocklist', function () {
542 describe('When managing account blocklist', function () {
543 it('Should list all videos', async function () {
544 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
545 await checkAllVideos(servers[0], token)
549 it('Should list the comments', async function () {
550 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
551 await checkAllComments(servers[0], token, videoUUID1)
555 it('Should block a remote account', async function () {
556 await command.addToServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
559 it('Should hide its videos', async function () {
560 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
561 const { data } = await servers[0].videos.listWithToken({ token })
563 expect(data).to.have.lengthOf(4)
565 const v = data.find(v => v.name === 'video user 2')
566 expect(v).to.be.undefined
570 it('Should block a local account', async function () {
571 await command.addToServerBlocklist({ account: 'user1' })
574 it('Should hide its videos', async function () {
575 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
576 const { data } = await servers[0].videos.listWithToken({ token })
578 expect(data).to.have.lengthOf(3)
580 const v = data.find(v => v.name === 'video user 1')
581 expect(v).to.be.undefined
585 it('Should hide its comments', async function () {
586 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
587 const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token })
588 const threads = data.filter(t => t.isDeleted === false)
590 expect(threads).to.have.lengthOf(1)
591 expect(threads[0].totalReplies).to.equal(1)
593 const t = threads.find(t => t.text === 'comment user 1')
594 expect(t).to.be.undefined
596 for (const thread of threads) {
597 const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token })
598 expect(tree.children).to.have.lengthOf(0)
603 it('Should not have notification from blocked accounts by instance', async function () {
607 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
608 await checkCommentNotification(servers[0], comment, 'absence')
615 videoUUID: videoUUID1,
616 text: 'hello @root@localhost:' + servers[0].port
618 await checkCommentNotification(servers[0], comment, 'absence')
622 it('Should list blocked accounts', async function () {
624 const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
625 expect(body.total).to.equal(2)
627 const block = body.data[0]
628 expect(block.byAccount.displayName).to.equal('peertube')
629 expect(block.byAccount.name).to.equal('peertube')
630 expect(block.blockedAccount.displayName).to.equal('user2')
631 expect(block.blockedAccount.name).to.equal('user2')
632 expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
636 const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
637 expect(body.total).to.equal(2)
639 const block = body.data[0]
640 expect(block.byAccount.displayName).to.equal('peertube')
641 expect(block.byAccount.name).to.equal('peertube')
642 expect(block.blockedAccount.displayName).to.equal('user1')
643 expect(block.blockedAccount.name).to.equal('user1')
644 expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
648 it('Should get blocked status', async function () {
649 const remoteHandle = 'user2@' + servers[1].host
650 const localHandle = 'user1@' + servers[0].host
651 const unknownHandle = 'user5@' + servers[0].host
653 for (const token of [ undefined, servers[0].accessToken ]) {
654 const status = await command.getStatus({ token, accounts: [ localHandle, remoteHandle, unknownHandle ] })
655 expect(Object.keys(status.accounts)).to.have.lengthOf(3)
657 for (const handle of [ localHandle, remoteHandle ]) {
658 expect(status.accounts[handle].blockedByUser).to.be.false
659 expect(status.accounts[handle].blockedByServer).to.be.true
662 expect(status.accounts[unknownHandle].blockedByUser).to.be.false
663 expect(status.accounts[unknownHandle].blockedByServer).to.be.false
665 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
669 it('Should unblock the remote account', async function () {
670 await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
673 it('Should display its videos', async function () {
674 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
675 const { data } = await servers[0].videos.listWithToken({ token })
676 expect(data).to.have.lengthOf(4)
678 const v = data.find(v => v.name === 'video user 2')
679 expect(v).not.to.be.undefined
683 it('Should unblock the local account', async function () {
684 await command.removeFromServerBlocklist({ account: 'user1' })
687 it('Should display its comments', async function () {
688 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
689 await checkAllComments(servers[0], token, videoUUID1)
693 it('Should have notifications from unblocked accounts', async function () {
697 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' }
698 await checkCommentNotification(servers[0], comment, 'presence')
705 videoUUID: videoUUID1,
706 text: 'hello @root@localhost:' + servers[0].port
708 await checkCommentNotification(servers[0], comment, 'presence')
713 describe('When managing server blocklist', function () {
715 it('Should list all videos', async function () {
716 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
717 await checkAllVideos(servers[0], token)
721 it('Should list the comments', async function () {
722 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
723 await checkAllComments(servers[0], token, videoUUID1)
727 it('Should block a remote server', async function () {
728 await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port })
731 it('Should hide its videos', async function () {
732 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
734 servers[0].videos.list(),
735 servers[0].videos.listWithToken({ token })
738 for (const req of requests) {
739 const { data } = await req
740 expect(data).to.have.lengthOf(3)
742 const v1 = data.find(v => v.name === 'video user 2')
743 const v2 = data.find(v => v.name === 'video server 2')
745 expect(v1).to.be.undefined
746 expect(v2).to.be.undefined
751 it('Should hide its comments', async function () {
754 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
756 await waitJobs(servers)
758 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
760 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
763 it('Should not have notification from blocked instances by instance', async function () {
767 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
768 await checkCommentNotification(servers[0], comment, 'absence')
775 videoUUID: videoUUID1,
776 text: 'hello @root@localhost:' + servers[0].port
778 await checkCommentNotification(servers[0], comment, 'absence')
782 const now = new Date()
783 await servers[1].follows.unfollow({ target: servers[0] })
784 await waitJobs(servers)
785 await servers[1].follows.follow({ hosts: [ servers[0].host ] })
787 await waitJobs(servers)
789 const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
790 const commentNotifications = data.filter(n => {
791 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
794 expect(commentNotifications).to.have.lengthOf(0)
798 it('Should list blocked servers', async function () {
799 const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
800 expect(body.total).to.equal(1)
802 const block = body.data[0]
803 expect(block.byAccount.displayName).to.equal('peertube')
804 expect(block.byAccount.name).to.equal('peertube')
805 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
808 it('Should get blocklist status', async function () {
809 const blockedServer = servers[1].host
810 const notBlockedServer = 'example.com'
812 for (const token of [ undefined, servers[0].accessToken ]) {
813 const status = await command.getStatus({ token, hosts: [ blockedServer, notBlockedServer ] })
814 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
816 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
817 expect(status.hosts[blockedServer].blockedByUser).to.be.false
818 expect(status.hosts[blockedServer].blockedByServer).to.be.true
820 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
821 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
825 it('Should unblock the remote server', async function () {
826 await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port })
829 it('Should list all videos', async function () {
830 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
831 await checkAllVideos(servers[0], token)
835 it('Should list the comments', async function () {
836 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
837 await checkAllComments(servers[0], token, videoUUID1)
841 it('Should have notification from unblocked instances', async function () {
845 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
846 await checkCommentNotification(servers[0], comment, 'presence')
853 videoUUID: videoUUID1,
854 text: 'hello @root@localhost:' + servers[0].port
856 await checkCommentNotification(servers[0], comment, 'presence')
860 const now = new Date()
861 await servers[1].follows.unfollow({ target: servers[0] })
862 await waitJobs(servers)
863 await servers[1].follows.follow({ hosts: [ servers[0].host ] })
865 await waitJobs(servers)
867 const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
868 const commentNotifications = data.filter(n => {
869 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
872 expect(commentNotifications).to.have.lengthOf(1)
878 after(async function () {
879 await cleanupTests(servers)