1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { UserNotificationType } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultAccountAvatar,
15 } from '@shared/server-commands'
17 async function checkAllVideos (server: PeerTubeServer, token: string) {
19 const { data } = await server.videos.listWithToken({ token })
20 expect(data).to.have.lengthOf(5)
24 const { data } = await server.videos.list()
25 expect(data).to.have.lengthOf(5)
29 async function checkAllComments (server: PeerTubeServer, token: string, videoUUID: string) {
30 const { data } = await server.comments.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token })
32 const threads = data.filter(t => t.isDeleted === false)
33 expect(threads).to.have.lengthOf(2)
35 for (const thread of threads) {
36 const tree = await server.comments.getThread({ videoId: videoUUID, threadId: thread.id, token })
37 expect(tree.children).to.have.lengthOf(1)
41 async function checkCommentNotification (
42 mainServer: PeerTubeServer,
43 comment: { server: PeerTubeServer, token: string, videoUUID: string, text: string },
44 check: 'presence' | 'absence'
46 const command = comment.server.comments
48 const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text })
50 await waitJobs([ mainServer, comment.server ])
52 const { data } = await mainServer.notifications.list({ start: 0, count: 30 })
53 const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
55 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
56 else expect(commentNotifications).to.have.lengthOf(0)
58 await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId })
60 await waitJobs([ mainServer, comment.server ])
63 describe('Test blocklist', function () {
64 let servers: PeerTubeServer[]
65 let videoUUID1: string
66 let videoUUID2: string
67 let videoUUID3: string
68 let userToken1: string
69 let userModeratorToken: string
70 let userToken2: string
72 let command: BlocklistCommand
73 let commentsCommand: CommentsCommand[]
75 before(async function () {
78 servers = await createMultipleServers(3)
79 await setAccessTokensToServers(servers)
80 await setDefaultAccountAvatar(servers)
82 command = servers[0].blocklist
83 commentsCommand = servers.map(s => s.comments)
86 const user = { username: 'user1', password: 'password' }
87 await servers[0].users.create({ username: user.username, password: user.password })
89 userToken1 = await servers[0].login.getAccessToken(user)
90 await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } })
94 const user = { username: 'moderator', password: 'password' }
95 await servers[0].users.create({ username: user.username, password: user.password })
97 userModeratorToken = await servers[0].login.getAccessToken(user)
101 const user = { username: 'user2', password: 'password' }
102 await servers[1].users.create({ username: user.username, password: user.password })
104 userToken2 = await servers[1].login.getAccessToken(user)
105 await servers[1].videos.upload({ token: userToken2, attributes: { name: 'video user 2' } })
109 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
114 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
119 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } })
123 await doubleFollow(servers[0], servers[1])
124 await doubleFollow(servers[0], servers[2])
127 const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' })
128 const reply = await commentsCommand[0].addReply({
131 toCommentId: created.id,
132 text: 'comment user 1'
134 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' })
138 const created = await commentsCommand[0].createThread({ token: userToken1, videoId: videoUUID1, text: 'comment user 1' })
139 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: created.id, text: 'comment root 1' })
142 await waitJobs(servers)
145 describe('User blocklist', function () {
147 describe('When managing account blocklist', function () {
148 it('Should list all videos', function () {
149 return checkAllVideos(servers[0], servers[0].accessToken)
152 it('Should list the comments', function () {
153 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
156 it('Should block a remote account', async function () {
157 await command.addToMyBlocklist({ account: 'user2@' + servers[1].host })
160 it('Should hide its videos', async function () {
161 const { data } = await servers[0].videos.listWithToken()
163 expect(data).to.have.lengthOf(4)
165 const v = data.find(v => v.name === 'video user 2')
166 expect(v).to.be.undefined
169 it('Should block a local account', async function () {
170 await command.addToMyBlocklist({ account: 'user1' })
173 it('Should hide its videos', async function () {
174 const { data } = await servers[0].videos.listWithToken()
176 expect(data).to.have.lengthOf(3)
178 const v = data.find(v => v.name === 'video user 1')
179 expect(v).to.be.undefined
182 it('Should hide its comments', async function () {
183 const { data } = await commentsCommand[0].listThreads({
184 token: servers[0].accessToken,
191 expect(data).to.have.lengthOf(1)
192 expect(data[0].totalReplies).to.equal(1)
194 const t = data.find(t => t.text === 'comment user 1')
195 expect(t).to.be.undefined
197 for (const thread of data) {
198 const tree = await commentsCommand[0].getThread({
201 token: servers[0].accessToken
203 expect(tree.children).to.have.lengthOf(0)
207 it('Should not have notifications from blocked accounts', async function () {
211 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
212 await checkCommentNotification(servers[0], comment, 'absence')
219 videoUUID: videoUUID2,
220 text: 'hello @root@' + servers[0].host
222 await checkCommentNotification(servers[0], comment, 'absence')
226 it('Should list all the videos with another user', async function () {
227 return checkAllVideos(servers[0], userToken1)
230 it('Should list blocked accounts', async function () {
232 const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
233 expect(body.total).to.equal(2)
235 const block = body.data[0]
236 expect(block.byAccount.displayName).to.equal('root')
237 expect(block.byAccount.name).to.equal('root')
238 expect(block.blockedAccount.displayName).to.equal('user2')
239 expect(block.blockedAccount.name).to.equal('user2')
240 expect(block.blockedAccount.host).to.equal('' + servers[1].host)
244 const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
245 expect(body.total).to.equal(2)
247 const block = body.data[0]
248 expect(block.byAccount.displayName).to.equal('root')
249 expect(block.byAccount.name).to.equal('root')
250 expect(block.blockedAccount.displayName).to.equal('user1')
251 expect(block.blockedAccount.name).to.equal('user1')
252 expect(block.blockedAccount.host).to.equal('' + servers[0].host)
256 it('Should search blocked accounts', async function () {
257 const body = await command.listMyAccountBlocklist({ start: 0, count: 10, search: 'user2' })
258 expect(body.total).to.equal(1)
260 expect(body.data[0].blockedAccount.name).to.equal('user2')
263 it('Should get blocked status', async function () {
264 const remoteHandle = 'user2@' + servers[1].host
265 const localHandle = 'user1@' + servers[0].host
266 const unknownHandle = 'user5@' + servers[0].host
269 const status = await command.getStatus({ accounts: [ remoteHandle ] })
270 expect(Object.keys(status.accounts)).to.have.lengthOf(1)
271 expect(status.accounts[remoteHandle].blockedByUser).to.be.false
272 expect(status.accounts[remoteHandle].blockedByServer).to.be.false
274 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
278 const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ remoteHandle ] })
279 expect(Object.keys(status.accounts)).to.have.lengthOf(1)
280 expect(status.accounts[remoteHandle].blockedByUser).to.be.true
281 expect(status.accounts[remoteHandle].blockedByServer).to.be.false
283 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
287 const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ localHandle, remoteHandle, unknownHandle ] })
288 expect(Object.keys(status.accounts)).to.have.lengthOf(3)
290 for (const handle of [ localHandle, remoteHandle ]) {
291 expect(status.accounts[handle].blockedByUser).to.be.true
292 expect(status.accounts[handle].blockedByServer).to.be.false
295 expect(status.accounts[unknownHandle].blockedByUser).to.be.false
296 expect(status.accounts[unknownHandle].blockedByServer).to.be.false
298 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
302 it('Should not allow a remote blocked user to comment my videos', async function () {
306 await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' })
307 await waitJobs(servers)
309 await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' })
310 await waitJobs(servers)
312 const commentId = await commentsCommand[1].findCommentId({ videoId: videoUUID3, text: 'uploader' })
313 const message = 'reply by user 2'
314 const reply = await commentsCommand[1].addReply({ token: userToken2, videoId: videoUUID3, toCommentId: commentId, text: message })
315 await commentsCommand[1].addReply({ videoId: videoUUID3, toCommentId: reply.id, text: 'another reply' })
317 await waitJobs(servers)
320 // Server 2 has all the comments
322 const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
324 expect(data).to.have.lengthOf(2)
325 expect(data[0].text).to.equal('uploader')
326 expect(data[1].text).to.equal('comment user 2')
328 const tree = await commentsCommand[1].getThread({ videoId: videoUUID3, threadId: data[0].id })
329 expect(tree.children).to.have.lengthOf(1)
330 expect(tree.children[0].comment.text).to.equal('reply by user 2')
331 expect(tree.children[0].children).to.have.lengthOf(1)
332 expect(tree.children[0].children[0].comment.text).to.equal('another reply')
335 // Server 1 and 3 should only have uploader comments
336 for (const server of [ servers[0], servers[2] ]) {
337 const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
339 expect(data).to.have.lengthOf(1)
340 expect(data[0].text).to.equal('uploader')
342 const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
344 if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0)
345 else expect(tree.children).to.have.lengthOf(1)
349 it('Should unblock the remote account', async function () {
350 await command.removeFromMyBlocklist({ account: 'user2@' + servers[1].host })
353 it('Should display its videos', async function () {
354 const { data } = await servers[0].videos.listWithToken()
355 expect(data).to.have.lengthOf(4)
357 const v = data.find(v => v.name === 'video user 2')
358 expect(v).not.to.be.undefined
361 it('Should display its comments on my video', async function () {
362 for (const server of servers) {
363 const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
365 // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment
366 if (server.serverNumber === 3) {
367 expect(data).to.have.lengthOf(1)
371 expect(data).to.have.lengthOf(2)
372 expect(data[0].text).to.equal('uploader')
373 expect(data[1].text).to.equal('comment user 2')
375 const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
376 expect(tree.children).to.have.lengthOf(1)
377 expect(tree.children[0].comment.text).to.equal('reply by user 2')
378 expect(tree.children[0].children).to.have.lengthOf(1)
379 expect(tree.children[0].children[0].comment.text).to.equal('another reply')
383 it('Should unblock the local account', async function () {
384 await command.removeFromMyBlocklist({ account: 'user1' })
387 it('Should display its comments', function () {
388 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
391 it('Should have a notification from a non blocked account', async function () {
395 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
396 await checkCommentNotification(servers[0], comment, 'presence')
403 videoUUID: videoUUID2,
404 text: 'hello @root@' + servers[0].host
406 await checkCommentNotification(servers[0], comment, 'presence')
411 describe('When managing server blocklist', function () {
413 it('Should list all videos', function () {
414 return checkAllVideos(servers[0], servers[0].accessToken)
417 it('Should list the comments', function () {
418 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
421 it('Should block a remote server', async function () {
422 await command.addToMyBlocklist({ server: '' + servers[1].host })
425 it('Should hide its videos', async function () {
426 const { data } = await servers[0].videos.listWithToken()
428 expect(data).to.have.lengthOf(3)
430 const v1 = data.find(v => v.name === 'video user 2')
431 const v2 = data.find(v => v.name === 'video server 2')
433 expect(v1).to.be.undefined
434 expect(v2).to.be.undefined
437 it('Should list all the videos with another user', async function () {
438 return checkAllVideos(servers[0], userToken1)
441 it('Should hide its comments', async function () {
444 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
446 await waitJobs(servers)
448 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
450 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
453 it('Should not have notifications from blocked server', async function () {
457 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
458 await checkCommentNotification(servers[0], comment, 'absence')
465 videoUUID: videoUUID1,
466 text: 'hello @root@' + servers[0].host
468 await checkCommentNotification(servers[0], comment, 'absence')
472 it('Should list blocked servers', async function () {
473 const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
474 expect(body.total).to.equal(1)
476 const block = body.data[0]
477 expect(block.byAccount.displayName).to.equal('root')
478 expect(block.byAccount.name).to.equal('root')
479 expect(block.blockedServer.host).to.equal('' + servers[1].host)
482 it('Should search blocked servers', async function () {
483 const body = await command.listMyServerBlocklist({ start: 0, count: 10, search: servers[1].host })
484 expect(body.total).to.equal(1)
486 expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
489 it('Should get blocklist status', async function () {
490 const blockedServer = servers[1].host
491 const notBlockedServer = 'example.com'
494 const status = await command.getStatus({ hosts: [ blockedServer, notBlockedServer ] })
495 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
497 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
498 expect(status.hosts[blockedServer].blockedByUser).to.be.false
499 expect(status.hosts[blockedServer].blockedByServer).to.be.false
501 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
502 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
506 const status = await command.getStatus({ token: servers[0].accessToken, hosts: [ blockedServer, notBlockedServer ] })
507 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
509 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
510 expect(status.hosts[blockedServer].blockedByUser).to.be.true
511 expect(status.hosts[blockedServer].blockedByServer).to.be.false
513 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
514 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
518 it('Should unblock the remote server', async function () {
519 await command.removeFromMyBlocklist({ server: '' + servers[1].host })
522 it('Should display its videos', function () {
523 return checkAllVideos(servers[0], servers[0].accessToken)
526 it('Should display its comments', function () {
527 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
530 it('Should have notification from unblocked server', async function () {
534 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
535 await checkCommentNotification(servers[0], comment, 'presence')
542 videoUUID: videoUUID1,
543 text: 'hello @root@' + servers[0].host
545 await checkCommentNotification(servers[0], comment, 'presence')
551 describe('Server blocklist', function () {
553 describe('When managing account blocklist', function () {
554 it('Should list all videos', async function () {
555 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
556 await checkAllVideos(servers[0], token)
560 it('Should list the comments', async function () {
561 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
562 await checkAllComments(servers[0], token, videoUUID1)
566 it('Should block a remote account', async function () {
567 await command.addToServerBlocklist({ account: 'user2@' + servers[1].host })
570 it('Should hide its videos', async function () {
571 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
572 const { data } = await servers[0].videos.listWithToken({ token })
574 expect(data).to.have.lengthOf(4)
576 const v = data.find(v => v.name === 'video user 2')
577 expect(v).to.be.undefined
581 it('Should block a local account', async function () {
582 await command.addToServerBlocklist({ account: 'user1' })
585 it('Should hide its videos', async function () {
586 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
587 const { data } = await servers[0].videos.listWithToken({ token })
589 expect(data).to.have.lengthOf(3)
591 const v = data.find(v => v.name === 'video user 1')
592 expect(v).to.be.undefined
596 it('Should hide its comments', async function () {
597 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
598 const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token })
599 const threads = data.filter(t => t.isDeleted === false)
601 expect(threads).to.have.lengthOf(1)
602 expect(threads[0].totalReplies).to.equal(1)
604 const t = threads.find(t => t.text === 'comment user 1')
605 expect(t).to.be.undefined
607 for (const thread of threads) {
608 const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token })
609 expect(tree.children).to.have.lengthOf(0)
614 it('Should not have notification from blocked accounts by instance', async function () {
618 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
619 await checkCommentNotification(servers[0], comment, 'absence')
626 videoUUID: videoUUID1,
627 text: 'hello @root@' + servers[0].host
629 await checkCommentNotification(servers[0], comment, 'absence')
633 it('Should list blocked accounts', async function () {
635 const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
636 expect(body.total).to.equal(2)
638 const block = body.data[0]
639 expect(block.byAccount.displayName).to.equal('peertube')
640 expect(block.byAccount.name).to.equal('peertube')
641 expect(block.blockedAccount.displayName).to.equal('user2')
642 expect(block.blockedAccount.name).to.equal('user2')
643 expect(block.blockedAccount.host).to.equal('' + servers[1].host)
647 const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
648 expect(body.total).to.equal(2)
650 const block = body.data[0]
651 expect(block.byAccount.displayName).to.equal('peertube')
652 expect(block.byAccount.name).to.equal('peertube')
653 expect(block.blockedAccount.displayName).to.equal('user1')
654 expect(block.blockedAccount.name).to.equal('user1')
655 expect(block.blockedAccount.host).to.equal('' + servers[0].host)
659 it('Should search blocked accounts', async function () {
660 const body = await command.listServerAccountBlocklist({ start: 0, count: 10, search: 'user2' })
661 expect(body.total).to.equal(1)
663 expect(body.data[0].blockedAccount.name).to.equal('user2')
666 it('Should get blocked status', async function () {
667 const remoteHandle = 'user2@' + servers[1].host
668 const localHandle = 'user1@' + servers[0].host
669 const unknownHandle = 'user5@' + servers[0].host
671 for (const token of [ undefined, servers[0].accessToken ]) {
672 const status = await command.getStatus({ token, accounts: [ localHandle, remoteHandle, unknownHandle ] })
673 expect(Object.keys(status.accounts)).to.have.lengthOf(3)
675 for (const handle of [ localHandle, remoteHandle ]) {
676 expect(status.accounts[handle].blockedByUser).to.be.false
677 expect(status.accounts[handle].blockedByServer).to.be.true
680 expect(status.accounts[unknownHandle].blockedByUser).to.be.false
681 expect(status.accounts[unknownHandle].blockedByServer).to.be.false
683 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
687 it('Should unblock the remote account', async function () {
688 await command.removeFromServerBlocklist({ account: 'user2@' + servers[1].host })
691 it('Should display its videos', async function () {
692 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
693 const { data } = await servers[0].videos.listWithToken({ token })
694 expect(data).to.have.lengthOf(4)
696 const v = data.find(v => v.name === 'video user 2')
697 expect(v).not.to.be.undefined
701 it('Should unblock the local account', async function () {
702 await command.removeFromServerBlocklist({ account: 'user1' })
705 it('Should display its comments', async function () {
706 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
707 await checkAllComments(servers[0], token, videoUUID1)
711 it('Should have notifications from unblocked accounts', async function () {
715 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' }
716 await checkCommentNotification(servers[0], comment, 'presence')
723 videoUUID: videoUUID1,
724 text: 'hello @root@' + servers[0].host
726 await checkCommentNotification(servers[0], comment, 'presence')
731 describe('When managing server blocklist', function () {
733 it('Should list all videos', async function () {
734 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
735 await checkAllVideos(servers[0], token)
739 it('Should list the comments', async function () {
740 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
741 await checkAllComments(servers[0], token, videoUUID1)
745 it('Should block a remote server', async function () {
746 await command.addToServerBlocklist({ server: '' + servers[1].host })
749 it('Should hide its videos', async function () {
750 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
752 servers[0].videos.list(),
753 servers[0].videos.listWithToken({ token })
756 for (const req of requests) {
757 const { data } = await req
758 expect(data).to.have.lengthOf(3)
760 const v1 = data.find(v => v.name === 'video user 2')
761 const v2 = data.find(v => v.name === 'video server 2')
763 expect(v1).to.be.undefined
764 expect(v2).to.be.undefined
769 it('Should hide its comments', async function () {
772 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
774 await waitJobs(servers)
776 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
778 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
781 it('Should not have notification from blocked instances by instance', async function () {
785 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
786 await checkCommentNotification(servers[0], comment, 'absence')
793 videoUUID: videoUUID1,
794 text: 'hello @root@' + servers[0].host
796 await checkCommentNotification(servers[0], comment, 'absence')
800 const now = new Date()
801 await servers[1].follows.unfollow({ target: servers[0] })
802 await waitJobs(servers)
803 await servers[1].follows.follow({ hosts: [ servers[0].host ] })
805 await waitJobs(servers)
807 const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
808 const commentNotifications = data.filter(n => {
809 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
812 expect(commentNotifications).to.have.lengthOf(0)
816 it('Should list blocked servers', async function () {
817 const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
818 expect(body.total).to.equal(1)
820 const block = body.data[0]
821 expect(block.byAccount.displayName).to.equal('peertube')
822 expect(block.byAccount.name).to.equal('peertube')
823 expect(block.blockedServer.host).to.equal('' + servers[1].host)
826 it('Should search blocked servers', async function () {
827 const body = await command.listServerServerBlocklist({ start: 0, count: 10, search: servers[1].host })
828 expect(body.total).to.equal(1)
830 expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
833 it('Should get blocklist status', async function () {
834 const blockedServer = servers[1].host
835 const notBlockedServer = 'example.com'
837 for (const token of [ undefined, servers[0].accessToken ]) {
838 const status = await command.getStatus({ token, hosts: [ blockedServer, notBlockedServer ] })
839 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
841 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
842 expect(status.hosts[blockedServer].blockedByUser).to.be.false
843 expect(status.hosts[blockedServer].blockedByServer).to.be.true
845 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
846 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
850 it('Should unblock the remote server', async function () {
851 await command.removeFromServerBlocklist({ server: '' + servers[1].host })
854 it('Should list all videos', async function () {
855 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
856 await checkAllVideos(servers[0], token)
860 it('Should list the comments', async function () {
861 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
862 await checkAllComments(servers[0], token, videoUUID1)
866 it('Should have notification from unblocked instances', async function () {
870 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
871 await checkCommentNotification(servers[0], comment, 'presence')
878 videoUUID: videoUUID1,
879 text: 'hello @root@' + servers[0].host
881 await checkCommentNotification(servers[0], comment, 'presence')
885 const now = new Date()
886 await servers[1].follows.unfollow({ target: servers[0] })
887 await waitJobs(servers)
888 await servers[1].follows.follow({ hosts: [ servers[0].host ] })
890 await waitJobs(servers)
892 const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
893 const commentNotifications = data.filter(n => {
894 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
897 expect(commentNotifications).to.have.lengthOf(1)
903 after(async function () {
904 await cleanupTests(servers)