]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/moderation/blocklist.ts
Merge branch 'release/4.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / moderation / blocklist.ts
index b767d38c7a1d6109145d86a977cca3342385ba61..b3fd8ecac8cfcf0894e32ff2a24a36bd88886c62 100644 (file)
 import 'mocha'
 import * as chai from 'chai'
 import {
-  addAccountToAccountBlocklist,
-  addAccountToServerBlocklist,
-  addServerToAccountBlocklist,
-  addServerToServerBlocklist,
-  addVideoCommentReply,
-  addVideoCommentThread,
+  BlocklistCommand,
   cleanupTests,
-  createUser,
-  deleteVideoComment,
+  CommentsCommand,
+  createMultipleServers,
   doubleFollow,
-  findCommentId,
-  flushAndRunMultipleServers,
-  follow,
-  getAccountBlocklistByAccount,
-  getAccountBlocklistByServer,
-  getServerBlocklistByAccount,
-  getServerBlocklistByServer,
-  getUserNotifications,
-  getVideoCommentThreads,
-  getVideosList,
-  getVideosListWithToken,
-  getVideoThreadComments,
-  removeAccountFromAccountBlocklist,
-  removeAccountFromServerBlocklist,
-  removeServerFromAccountBlocklist,
-  removeServerFromServerBlocklist,
-  ServerInfo,
+  PeerTubeServer,
   setAccessTokensToServers,
-  unfollow,
-  uploadVideo,
-  userLogin,
   waitJobs
 } from '@shared/extra-utils'
-import {
-  AccountBlock,
-  ServerBlock,
-  UserNotification,
-  UserNotificationType,
-  Video,
-  VideoComment,
-  VideoCommentThreadTree
-} from '@shared/models'
+import { UserNotificationType } from '@shared/models'
 
 const expect = chai.expect
 
-async function checkAllVideos (url: string, token: string) {
+async function checkAllVideos (server: PeerTubeServer, token: string) {
   {
-    const res = await getVideosListWithToken(url, token)
-
-    expect(res.body.data).to.have.lengthOf(5)
+    const { data } = await server.videos.listWithToken({ token })
+    expect(data).to.have.lengthOf(5)
   }
 
   {
-    const res = await getVideosList(url)
-
-    expect(res.body.data).to.have.lengthOf(5)
+    const { data } = await server.videos.list()
+    expect(data).to.have.lengthOf(5)
   }
 }
 
-async function checkAllComments (url: string, token: string, videoUUID: string) {
-  const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 25, '-createdAt', token)
+async function checkAllComments (server: PeerTubeServer, token: string, videoUUID: string) {
+  const { data } = await server.comments.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token })
 
-  const allThreads: VideoComment[] = resThreads.body.data
-  const threads = allThreads.filter(t => t.isDeleted === false)
+  const threads = data.filter(t => t.isDeleted === false)
   expect(threads).to.have.lengthOf(2)
 
   for (const thread of threads) {
-    const res = await getVideoThreadComments(url, videoUUID, thread.id, token)
-
-    const tree: VideoCommentThreadTree = res.body
+    const tree = await server.comments.getThread({ videoId: videoUUID, threadId: thread.id, token })
     expect(tree.children).to.have.lengthOf(1)
   }
 }
 
 async function checkCommentNotification (
-  mainServer: ServerInfo,
-  comment: { server: ServerInfo, token: string, videoUUID: string, text: string },
+  mainServer: PeerTubeServer,
+  comment: { server: PeerTubeServer, token: string, videoUUID: string, text: string },
   check: 'presence' | 'absence'
 ) {
-  const resComment = await addVideoCommentThread(comment.server.url, comment.token, comment.videoUUID, comment.text)
-  const created = resComment.body.comment as VideoComment
-  const threadId = created.id
-  const createdAt = created.createdAt
+  const command = comment.server.comments
+
+  const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text })
 
   await waitJobs([ mainServer, comment.server ])
 
-  const res = await getUserNotifications(mainServer.url, mainServer.accessToken, 0, 30)
-  const commentNotifications = (res.body.data as UserNotification[])
-                                  .filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
+  const { data } = await mainServer.notifications.list({ start: 0, count: 30 })
+  const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
 
   if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
   else expect(commentNotifications).to.have.lengthOf(0)
 
-  await deleteVideoComment(comment.server.url, comment.token, comment.videoUUID, threadId)
+  await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId })
 
   await waitJobs([ mainServer, comment.server ])
 }
 
 describe('Test blocklist', function () {
-  let servers: ServerInfo[]
+  let servers: PeerTubeServer[]
   let videoUUID1: string
   let videoUUID2: string
   let videoUUID3: string
@@ -110,62 +71,73 @@ describe('Test blocklist', function () {
   let userModeratorToken: string
   let userToken2: string
 
+  let command: BlocklistCommand
+  let commentsCommand: CommentsCommand[]
+
   before(async function () {
     this.timeout(120000)
 
-    servers = await flushAndRunMultipleServers(3)
+    servers = await createMultipleServers(3)
     await setAccessTokensToServers(servers)
 
+    command = servers[0].blocklist
+    commentsCommand = servers.map(s => s.comments)
+
     {
       const user = { username: 'user1', password: 'password' }
-      await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
+      await servers[0].users.create({ username: user.username, password: user.password })
 
-      userToken1 = await userLogin(servers[0], user)
-      await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
+      userToken1 = await servers[0].login.getAccessToken(user)
+      await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } })
     }
 
     {
       const user = { username: 'moderator', password: 'password' }
-      await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
+      await servers[0].users.create({ username: user.username, password: user.password })
 
-      userModeratorToken = await userLogin(servers[0], user)
+      userModeratorToken = await servers[0].login.getAccessToken(user)
     }
 
     {
       const user = { username: 'user2', password: 'password' }
-      await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
+      await servers[1].users.create({ username: user.username, password: user.password })
 
-      userToken2 = await userLogin(servers[1], user)
-      await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' })
+      userToken2 = await servers[1].login.getAccessToken(user)
+      await servers[1].videos.upload({ token: userToken2, attributes: { name: 'video user 2' } })
     }
 
     {
-      const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' })
-      videoUUID1 = res.body.video.uuid
+      const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
+      videoUUID1 = uuid
     }
 
     {
-      const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' })
-      videoUUID2 = res.body.video.uuid
+      const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
+      videoUUID2 = uuid
     }
 
     {
-      const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' })
-      videoUUID3 = res.body.video.uuid
+      const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } })
+      videoUUID3 = uuid
     }
 
     await doubleFollow(servers[0], servers[1])
     await doubleFollow(servers[0], servers[2])
 
     {
-      const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID1, 'comment root 1')
-      const resReply = await addVideoCommentReply(servers[0].url, userToken1, videoUUID1, resComment.body.comment.id, 'comment user 1')
-      await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resReply.body.comment.id, 'comment root 1')
+      const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' })
+      const reply = await commentsCommand[0].addReply({
+        token: userToken1,
+        videoId: videoUUID1,
+        toCommentId: created.id,
+        text: 'comment user 1'
+      })
+      await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' })
     }
 
     {
-      const resComment = await addVideoCommentThread(servers[0].url, userToken1, videoUUID1, 'comment user 1')
-      await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resComment.body.comment.id, 'comment root 1')
+      const created = await commentsCommand[0].createThread({ token: userToken1, videoId: videoUUID1, text: 'comment user 1' })
+      await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: created.id, text: 'comment root 1' })
     }
 
     await waitJobs(servers)
@@ -175,55 +147,60 @@ describe('Test blocklist', function () {
 
     describe('When managing account blocklist', function () {
       it('Should list all videos', function () {
-        return checkAllVideos(servers[0].url, servers[0].accessToken)
+        return checkAllVideos(servers[0], servers[0].accessToken)
       })
 
       it('Should list the comments', function () {
-        return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
+        return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
       })
 
       it('Should block a remote account', async function () {
-        await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
+        await command.addToMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
       })
 
       it('Should hide its videos', async function () {
-        const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
+        const { data } = await servers[0].videos.listWithToken()
 
-        const videos: Video[] = res.body.data
-        expect(videos).to.have.lengthOf(4)
+        expect(data).to.have.lengthOf(4)
 
-        const v = videos.find(v => v.name === 'video user 2')
+        const v = data.find(v => v.name === 'video user 2')
         expect(v).to.be.undefined
       })
 
       it('Should block a local account', async function () {
-        await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1')
+        await command.addToMyBlocklist({ account: 'user1' })
       })
 
       it('Should hide its videos', async function () {
-        const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
+        const { data } = await servers[0].videos.listWithToken()
 
-        const videos: Video[] = res.body.data
-        expect(videos).to.have.lengthOf(3)
+        expect(data).to.have.lengthOf(3)
 
-        const v = videos.find(v => v.name === 'video user 1')
+        const v = data.find(v => v.name === 'video user 1')
         expect(v).to.be.undefined
       })
 
       it('Should hide its comments', async function () {
-        const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 25, '-createdAt', servers[0].accessToken)
-
-        const threads: VideoComment[] = resThreads.body.data
-        expect(threads).to.have.lengthOf(1)
-        expect(threads[0].totalReplies).to.equal(0)
-
-        const t = threads.find(t => t.text === 'comment user 1')
+        const { data } = await commentsCommand[0].listThreads({
+          token: servers[0].accessToken,
+          videoId: videoUUID1,
+          start: 0,
+          count: 25,
+          sort: '-createdAt'
+        })
+
+        expect(data).to.have.lengthOf(1)
+        expect(data[0].totalReplies).to.equal(1)
+
+        const t = data.find(t => t.text === 'comment user 1')
         expect(t).to.be.undefined
 
-        for (const thread of threads) {
-          const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, servers[0].accessToken)
-
-          const tree: VideoCommentThreadTree = res.body
+        for (const thread of data) {
+          const tree = await commentsCommand[0].getThread({
+            videoId: videoUUID1,
+            threadId: thread.id,
+            token: servers[0].accessToken
+          })
           expect(tree.children).to.have.lengthOf(0)
         }
       })
@@ -248,17 +225,15 @@ describe('Test blocklist', function () {
       })
 
       it('Should list all the videos with another user', async function () {
-        return checkAllVideos(servers[0].url, userToken1)
+        return checkAllVideos(servers[0], userToken1)
       })
 
       it('Should list blocked accounts', async function () {
         {
-          const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
-          const blocks: AccountBlock[] = res.body.data
-
-          expect(res.body.total).to.equal(2)
+          const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
+          expect(body.total).to.equal(2)
 
-          const block = blocks[0]
+          const block = body.data[0]
           expect(block.byAccount.displayName).to.equal('root')
           expect(block.byAccount.name).to.equal('root')
           expect(block.blockedAccount.displayName).to.equal('user2')
@@ -267,12 +242,10 @@ describe('Test blocklist', function () {
         }
 
         {
-          const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt')
-          const blocks: AccountBlock[] = res.body.data
-
-          expect(res.body.total).to.equal(2)
+          const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
+          expect(body.total).to.equal(2)
 
-          const block = blocks[0]
+          const block = body.data[0]
           expect(block.byAccount.displayName).to.equal('root')
           expect(block.byAccount.name).to.equal('root')
           expect(block.blockedAccount.displayName).to.equal('user1')
@@ -281,36 +254,72 @@ describe('Test blocklist', function () {
         }
       })
 
+      it('Should get blocked status', async function () {
+        const remoteHandle = 'user2@' + servers[1].host
+        const localHandle = 'user1@' + servers[0].host
+        const unknownHandle = 'user5@' + servers[0].host
+
+        {
+          const status = await command.getStatus({ accounts: [ remoteHandle ] })
+          expect(Object.keys(status.accounts)).to.have.lengthOf(1)
+          expect(status.accounts[remoteHandle].blockedByUser).to.be.false
+          expect(status.accounts[remoteHandle].blockedByServer).to.be.false
+
+          expect(Object.keys(status.hosts)).to.have.lengthOf(0)
+        }
+
+        {
+          const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ remoteHandle ] })
+          expect(Object.keys(status.accounts)).to.have.lengthOf(1)
+          expect(status.accounts[remoteHandle].blockedByUser).to.be.true
+          expect(status.accounts[remoteHandle].blockedByServer).to.be.false
+
+          expect(Object.keys(status.hosts)).to.have.lengthOf(0)
+        }
+
+        {
+          const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ localHandle, remoteHandle, unknownHandle ] })
+          expect(Object.keys(status.accounts)).to.have.lengthOf(3)
+
+          for (const handle of [ localHandle, remoteHandle ]) {
+            expect(status.accounts[handle].blockedByUser).to.be.true
+            expect(status.accounts[handle].blockedByServer).to.be.false
+          }
+
+          expect(status.accounts[unknownHandle].blockedByUser).to.be.false
+          expect(status.accounts[unknownHandle].blockedByServer).to.be.false
+
+          expect(Object.keys(status.hosts)).to.have.lengthOf(0)
+        }
+      })
+
       it('Should not allow a remote blocked user to comment my videos', async function () {
         this.timeout(60000)
 
         {
-          await addVideoCommentThread(servers[1].url, userToken2, videoUUID3, 'comment user 2')
+          await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' })
           await waitJobs(servers)
 
-          await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID3, 'uploader')
+          await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' })
           await waitJobs(servers)
 
-          const commentId = await findCommentId(servers[1].url, videoUUID3, 'uploader')
+          const commentId = await commentsCommand[1].findCommentId({ videoId: videoUUID3, text: 'uploader' })
           const message = 'reply by user 2'
-          const resReply = await addVideoCommentReply(servers[1].url, userToken2, videoUUID3, commentId, message)
-          await addVideoCommentReply(servers[1].url, servers[1].accessToken, videoUUID3, resReply.body.comment.id, 'another reply')
+          const reply = await commentsCommand[1].addReply({ token: userToken2, videoId: videoUUID3, toCommentId: commentId, text: message })
+          await commentsCommand[1].addReply({ videoId: videoUUID3, toCommentId: reply.id, text: 'another reply' })
 
           await waitJobs(servers)
         }
 
         // Server 2 has all the comments
         {
-          const resThreads = await getVideoCommentThreads(servers[1].url, videoUUID3, 0, 25, '-createdAt')
-          const threads: VideoComment[] = resThreads.body.data
+          const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
 
-          expect(threads).to.have.lengthOf(2)
-          expect(threads[0].text).to.equal('uploader')
-          expect(threads[1].text).to.equal('comment user 2')
+          expect(data).to.have.lengthOf(2)
+          expect(data[0].text).to.equal('uploader')
+          expect(data[1].text).to.equal('comment user 2')
 
-          const resReplies = await getVideoThreadComments(servers[1].url, videoUUID3, threads[0].id)
-
-          const tree: VideoCommentThreadTree = resReplies.body
+          const tree = await commentsCommand[1].getThread({ videoId: videoUUID3, threadId: data[0].id })
           expect(tree.children).to.have.lengthOf(1)
           expect(tree.children[0].comment.text).to.equal('reply by user 2')
           expect(tree.children[0].children).to.have.lengthOf(1)
@@ -319,55 +328,45 @@ describe('Test blocklist', function () {
 
         // Server 1 and 3 should only have uploader comments
         for (const server of [ servers[0], servers[2] ]) {
-          const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt')
-          const threads: VideoComment[] = resThreads.body.data
+          const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
 
-          expect(threads).to.have.lengthOf(1)
-          expect(threads[0].text).to.equal('uploader')
+          expect(data).to.have.lengthOf(1)
+          expect(data[0].text).to.equal('uploader')
 
-          const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id)
+          const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
 
-          const tree: VideoCommentThreadTree = resReplies.body
-          if (server.serverNumber === 1) {
-            expect(tree.children).to.have.lengthOf(0)
-          } else {
-            expect(tree.children).to.have.lengthOf(1)
-          }
+          if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0)
+          else expect(tree.children).to.have.lengthOf(1)
         }
       })
 
       it('Should unblock the remote account', async function () {
-        await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
+        await command.removeFromMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
       })
 
       it('Should display its videos', async function () {
-        const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
+        const { data } = await servers[0].videos.listWithToken()
+        expect(data).to.have.lengthOf(4)
 
-        const videos: Video[] = res.body.data
-        expect(videos).to.have.lengthOf(4)
-
-        const v = videos.find(v => v.name === 'video user 2')
+        const v = data.find(v => v.name === 'video user 2')
         expect(v).not.to.be.undefined
       })
 
       it('Should display its comments on my video', async function () {
         for (const server of servers) {
-          const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt')
-          const threads: VideoComment[] = resThreads.body.data
+          const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
 
           // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment
           if (server.serverNumber === 3) {
-            expect(threads).to.have.lengthOf(1)
+            expect(data).to.have.lengthOf(1)
             continue
           }
 
-          expect(threads).to.have.lengthOf(2)
-          expect(threads[0].text).to.equal('uploader')
-          expect(threads[1].text).to.equal('comment user 2')
-
-          const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id)
+          expect(data).to.have.lengthOf(2)
+          expect(data[0].text).to.equal('uploader')
+          expect(data[1].text).to.equal('comment user 2')
 
-          const tree: VideoCommentThreadTree = resReplies.body
+          const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
           expect(tree.children).to.have.lengthOf(1)
           expect(tree.children[0].comment.text).to.equal('reply by user 2')
           expect(tree.children[0].children).to.have.lengthOf(1)
@@ -376,11 +375,11 @@ describe('Test blocklist', function () {
       })
 
       it('Should unblock the local account', async function () {
-        await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1')
+        await command.removeFromMyBlocklist({ account: 'user1' })
       })
 
       it('Should display its comments', function () {
-        return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
+        return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
       })
 
       it('Should have a notification from a non blocked account', async function () {
@@ -404,46 +403,45 @@ describe('Test blocklist', function () {
     })
 
     describe('When managing server blocklist', function () {
+
       it('Should list all videos', function () {
-        return checkAllVideos(servers[0].url, servers[0].accessToken)
+        return checkAllVideos(servers[0], servers[0].accessToken)
       })
 
       it('Should list the comments', function () {
-        return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
+        return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
       })
 
       it('Should block a remote server', async function () {
-        await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
+        await command.addToMyBlocklist({ server: 'localhost:' + servers[1].port })
       })
 
       it('Should hide its videos', async function () {
-        const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
+        const { data } = await servers[0].videos.listWithToken()
 
-        const videos: Video[] = res.body.data
-        expect(videos).to.have.lengthOf(3)
+        expect(data).to.have.lengthOf(3)
 
-        const v1 = videos.find(v => v.name === 'video user 2')
-        const v2 = videos.find(v => v.name === 'video server 2')
+        const v1 = data.find(v => v.name === 'video user 2')
+        const v2 = data.find(v => v.name === 'video server 2')
 
         expect(v1).to.be.undefined
         expect(v2).to.be.undefined
       })
 
       it('Should list all the videos with another user', async function () {
-        return checkAllVideos(servers[0].url, userToken1)
+        return checkAllVideos(servers[0], userToken1)
       })
 
       it('Should hide its comments', async function () {
         this.timeout(10000)
 
-        const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2')
-        const threadId = resThreads.body.comment.id
+        const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
 
         await waitJobs(servers)
 
-        await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
+        await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
 
-        await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId)
+        await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
       })
 
       it('Should not have notifications from blocked server', async function () {
@@ -466,27 +464,54 @@ describe('Test blocklist', function () {
       })
 
       it('Should list blocked servers', async function () {
-        const res = await getServerBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
-        const blocks: ServerBlock[] = res.body.data
-
-        expect(res.body.total).to.equal(1)
+        const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
+        expect(body.total).to.equal(1)
 
-        const block = blocks[0]
+        const block = body.data[0]
         expect(block.byAccount.displayName).to.equal('root')
         expect(block.byAccount.name).to.equal('root')
         expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
       })
 
+      it('Should get blocklist status', async function () {
+        const blockedServer = servers[1].host
+        const notBlockedServer = 'example.com'
+
+        {
+          const status = await command.getStatus({ hosts: [ blockedServer, notBlockedServer ] })
+          expect(Object.keys(status.accounts)).to.have.lengthOf(0)
+
+          expect(Object.keys(status.hosts)).to.have.lengthOf(2)
+          expect(status.hosts[blockedServer].blockedByUser).to.be.false
+          expect(status.hosts[blockedServer].blockedByServer).to.be.false
+
+          expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
+          expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
+        }
+
+        {
+          const status = await command.getStatus({ token: servers[0].accessToken, hosts: [ blockedServer, notBlockedServer ] })
+          expect(Object.keys(status.accounts)).to.have.lengthOf(0)
+
+          expect(Object.keys(status.hosts)).to.have.lengthOf(2)
+          expect(status.hosts[blockedServer].blockedByUser).to.be.true
+          expect(status.hosts[blockedServer].blockedByServer).to.be.false
+
+          expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
+          expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
+        }
+      })
+
       it('Should unblock the remote server', async function () {
-        await removeServerFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
+        await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port })
       })
 
       it('Should display its videos', function () {
-        return checkAllVideos(servers[0].url, servers[0].accessToken)
+        return checkAllVideos(servers[0], servers[0].accessToken)
       })
 
       it('Should display its comments', function () {
-        return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
+        return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
       })
 
       it('Should have notification from unblocked server', async function () {
@@ -515,65 +540,59 @@ describe('Test blocklist', function () {
     describe('When managing account blocklist', function () {
       it('Should list all videos', async function () {
         for (const token of [ userModeratorToken, servers[0].accessToken ]) {
-          await checkAllVideos(servers[0].url, token)
+          await checkAllVideos(servers[0], token)
         }
       })
 
       it('Should list the comments', async function () {
         for (const token of [ userModeratorToken, servers[0].accessToken ]) {
-          await checkAllComments(servers[0].url, token, videoUUID1)
+          await checkAllComments(servers[0], token, videoUUID1)
         }
       })
 
       it('Should block a remote account', async function () {
-        await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
+        await command.addToServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
       })
 
       it('Should hide its videos', async function () {
         for (const token of [ userModeratorToken, servers[0].accessToken ]) {
-          const res = await getVideosListWithToken(servers[0].url, token)
+          const { data } = await servers[0].videos.listWithToken({ token })
 
-          const videos: Video[] = res.body.data
-          expect(videos).to.have.lengthOf(4)
+          expect(data).to.have.lengthOf(4)
 
-          const v = videos.find(v => v.name === 'video user 2')
+          const v = data.find(v => v.name === 'video user 2')
           expect(v).to.be.undefined
         }
       })
 
       it('Should block a local account', async function () {
-        await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user1')
+        await command.addToServerBlocklist({ account: 'user1' })
       })
 
       it('Should hide its videos', async function () {
         for (const token of [ userModeratorToken, servers[0].accessToken ]) {
-          const res = await getVideosListWithToken(servers[0].url, token)
+          const { data } = await servers[0].videos.listWithToken({ token })
 
-          const videos: Video[] = res.body.data
-          expect(videos).to.have.lengthOf(3)
+          expect(data).to.have.lengthOf(3)
 
-          const v = videos.find(v => v.name === 'video user 1')
+          const v = data.find(v => v.name === 'video user 1')
           expect(v).to.be.undefined
         }
       })
 
       it('Should hide its comments', async function () {
         for (const token of [ userModeratorToken, servers[0].accessToken ]) {
-          const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 20, '-createdAt', token)
-
-          let threads: VideoComment[] = resThreads.body.data
-          threads = threads.filter(t => t.isDeleted === false)
+          const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token })
+          const threads = data.filter(t => t.isDeleted === false)
 
           expect(threads).to.have.lengthOf(1)
-          expect(threads[0].totalReplies).to.equal(0)
+          expect(threads[0].totalReplies).to.equal(1)
 
           const t = threads.find(t => t.text === 'comment user 1')
           expect(t).to.be.undefined
 
           for (const thread of threads) {
-            const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, token)
-
-            const tree: VideoCommentThreadTree = res.body
+            const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token })
             expect(tree.children).to.have.lengthOf(0)
           }
         }
@@ -600,12 +619,10 @@ describe('Test blocklist', function () {
 
       it('Should list blocked accounts', async function () {
         {
-          const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
-          const blocks: AccountBlock[] = res.body.data
+          const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
+          expect(body.total).to.equal(2)
 
-          expect(res.body.total).to.equal(2)
-
-          const block = blocks[0]
+          const block = body.data[0]
           expect(block.byAccount.displayName).to.equal('peertube')
           expect(block.byAccount.name).to.equal('peertube')
           expect(block.blockedAccount.displayName).to.equal('user2')
@@ -614,12 +631,10 @@ describe('Test blocklist', function () {
         }
 
         {
-          const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt')
-          const blocks: AccountBlock[] = res.body.data
-
-          expect(res.body.total).to.equal(2)
+          const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
+          expect(body.total).to.equal(2)
 
-          const block = blocks[0]
+          const block = body.data[0]
           expect(block.byAccount.displayName).to.equal('peertube')
           expect(block.byAccount.name).to.equal('peertube')
           expect(block.blockedAccount.displayName).to.equal('user1')
@@ -628,29 +643,48 @@ describe('Test blocklist', function () {
         }
       })
 
+      it('Should get blocked status', async function () {
+        const remoteHandle = 'user2@' + servers[1].host
+        const localHandle = 'user1@' + servers[0].host
+        const unknownHandle = 'user5@' + servers[0].host
+
+        for (const token of [ undefined, servers[0].accessToken ]) {
+          const status = await command.getStatus({ token, accounts: [ localHandle, remoteHandle, unknownHandle ] })
+          expect(Object.keys(status.accounts)).to.have.lengthOf(3)
+
+          for (const handle of [ localHandle, remoteHandle ]) {
+            expect(status.accounts[handle].blockedByUser).to.be.false
+            expect(status.accounts[handle].blockedByServer).to.be.true
+          }
+
+          expect(status.accounts[unknownHandle].blockedByUser).to.be.false
+          expect(status.accounts[unknownHandle].blockedByServer).to.be.false
+
+          expect(Object.keys(status.hosts)).to.have.lengthOf(0)
+        }
+      })
+
       it('Should unblock the remote account', async function () {
-        await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
+        await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
       })
 
       it('Should display its videos', async function () {
         for (const token of [ userModeratorToken, servers[0].accessToken ]) {
-          const res = await getVideosListWithToken(servers[0].url, token)
-
-          const videos: Video[] = res.body.data
-          expect(videos).to.have.lengthOf(4)
+          const { data } = await servers[0].videos.listWithToken({ token })
+          expect(data).to.have.lengthOf(4)
 
-          const v = videos.find(v => v.name === 'video user 2')
+          const v = data.find(v => v.name === 'video user 2')
           expect(v).not.to.be.undefined
         }
       })
 
       it('Should unblock the local account', async function () {
-        await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user1')
+        await command.removeFromServerBlocklist({ account: 'user1' })
       })
 
       it('Should display its comments', async function () {
         for (const token of [ userModeratorToken, servers[0].accessToken ]) {
-          await checkAllComments(servers[0].url, token, videoUUID1)
+          await checkAllComments(servers[0], token, videoUUID1)
         }
       })
 
@@ -675,33 +709,36 @@ describe('Test blocklist', function () {
     })
 
     describe('When managing server blocklist', function () {
+
       it('Should list all videos', async function () {
         for (const token of [ userModeratorToken, servers[0].accessToken ]) {
-          await checkAllVideos(servers[0].url, token)
+          await checkAllVideos(servers[0], token)
         }
       })
 
       it('Should list the comments', async function () {
         for (const token of [ userModeratorToken, servers[0].accessToken ]) {
-          await checkAllComments(servers[0].url, token, videoUUID1)
+          await checkAllComments(servers[0], token, videoUUID1)
         }
       })
 
       it('Should block a remote server', async function () {
-        await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
+        await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port })
       })
 
       it('Should hide its videos', async function () {
         for (const token of [ userModeratorToken, servers[0].accessToken ]) {
-          const res1 = await getVideosList(servers[0].url)
-          const res2 = await getVideosListWithToken(servers[0].url, token)
+          const requests = [
+            servers[0].videos.list(),
+            servers[0].videos.listWithToken({ token })
+          ]
 
-          for (const res of [ res1, res2 ]) {
-            const videos: Video[] = res.body.data
-            expect(videos).to.have.lengthOf(3)
+          for (const req of requests) {
+            const { data } = await req
+            expect(data).to.have.lengthOf(3)
 
-            const v1 = videos.find(v => v.name === 'video user 2')
-            const v2 = videos.find(v => v.name === 'video server 2')
+            const v1 = data.find(v => v.name === 'video user 2')
+            const v2 = data.find(v => v.name === 'video server 2')
 
             expect(v1).to.be.undefined
             expect(v2).to.be.undefined
@@ -712,14 +749,13 @@ describe('Test blocklist', function () {
       it('Should hide its comments', async function () {
         this.timeout(10000)
 
-        const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2')
-        const threadId = resThreads.body.comment.id
+        const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
 
         await waitJobs(servers)
 
-        await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
+        await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
 
-        await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId)
+        await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
       })
 
       it('Should not have notification from blocked instances by instance', async function () {
@@ -742,48 +778,61 @@ describe('Test blocklist', function () {
 
         {
           const now = new Date()
-          await unfollow(servers[1].url, servers[1].accessToken, servers[0])
+          await servers[1].follows.unfollow({ target: servers[0] })
           await waitJobs(servers)
-          await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken)
+          await servers[1].follows.follow({ hosts: [ servers[0].host ] })
 
           await waitJobs(servers)
 
-          const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30)
-          const commentNotifications = (res.body.data as UserNotification[])
-                                          .filter(n => {
-                                            return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER &&
-                                            n.createdAt >= now.toISOString()
-                                          })
+          const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
+          const commentNotifications = data.filter(n => {
+            return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
+          })
 
           expect(commentNotifications).to.have.lengthOf(0)
         }
       })
 
       it('Should list blocked servers', async function () {
-        const res = await getServerBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
-        const blocks: ServerBlock[] = res.body.data
-
-        expect(res.body.total).to.equal(1)
+        const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
+        expect(body.total).to.equal(1)
 
-        const block = blocks[0]
+        const block = body.data[0]
         expect(block.byAccount.displayName).to.equal('peertube')
         expect(block.byAccount.name).to.equal('peertube')
         expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
       })
 
+      it('Should get blocklist status', async function () {
+        const blockedServer = servers[1].host
+        const notBlockedServer = 'example.com'
+
+        for (const token of [ undefined, servers[0].accessToken ]) {
+          const status = await command.getStatus({ token, hosts: [ blockedServer, notBlockedServer ] })
+          expect(Object.keys(status.accounts)).to.have.lengthOf(0)
+
+          expect(Object.keys(status.hosts)).to.have.lengthOf(2)
+          expect(status.hosts[blockedServer].blockedByUser).to.be.false
+          expect(status.hosts[blockedServer].blockedByServer).to.be.true
+
+          expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
+          expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
+        }
+      })
+
       it('Should unblock the remote server', async function () {
-        await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
+        await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port })
       })
 
       it('Should list all videos', async function () {
         for (const token of [ userModeratorToken, servers[0].accessToken ]) {
-          await checkAllVideos(servers[0].url, token)
+          await checkAllVideos(servers[0], token)
         }
       })
 
       it('Should list the comments', async function () {
         for (const token of [ userModeratorToken, servers[0].accessToken ]) {
-          await checkAllComments(servers[0].url, token, videoUUID1)
+          await checkAllComments(servers[0], token, videoUUID1)
         }
       })
 
@@ -807,18 +856,16 @@ describe('Test blocklist', function () {
 
         {
           const now = new Date()
-          await unfollow(servers[1].url, servers[1].accessToken, servers[0])
+          await servers[1].follows.unfollow({ target: servers[0] })
           await waitJobs(servers)
-          await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken)
+          await servers[1].follows.follow({ hosts: [ servers[0].host ] })
 
           await waitJobs(servers)
 
-          const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30)
-          const commentNotifications = (res.body.data as UserNotification[])
-                                          .filter(n => {
-                                            return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER &&
-                                            n.createdAt >= now.toISOString()
-                                          })
+          const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
+          const commentNotifications = data.filter(n => {
+            return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
+          })
 
           expect(commentNotifications).to.have.lengthOf(1)
         }