]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Introduce follows command
authorChocobozzz <me@florianbigard.com>
Wed, 7 Jul 2021 07:16:40 +0000 (09:16 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 20 Jul 2021 13:27:17 +0000 (15:27 +0200)
20 files changed:
server/tests/api/moderation/blocklist.ts
server/tests/api/notifications/moderation-notifications.ts
server/tests/api/redundancy/redundancy-constraints.ts
server/tests/api/redundancy/redundancy.ts
server/tests/api/server/auto-follows.ts
server/tests/api/server/follow-constraints.ts
server/tests/api/server/follows-moderation.ts
server/tests/api/server/follows.ts
server/tests/api/server/handle-down.ts
server/tests/api/server/jobs.ts
server/tests/api/server/stats.ts
server/tests/api/users/user-subscriptions.ts
server/tests/api/users/users.ts
server/tests/api/videos/video-description.ts
server/tests/api/videos/video-playlists.ts
shared/extra-utils/index.ts
shared/extra-utils/server/follows-command.ts [new file with mode: 0644]
shared/extra-utils/server/follows.ts
shared/extra-utils/server/index.ts
shared/extra-utils/server/servers.ts

index 793abbcb4209a1514d06efd03fc742ec140b62cb..9ca6324c2e2adfb84fd5add316f38d1b824881de 100644 (file)
@@ -15,7 +15,6 @@ import {
   doubleFollow,
   findCommentId,
   flushAndRunMultipleServers,
-  follow,
   getAccountBlocklistByAccount,
   getAccountBlocklistByServer,
   getServerBlocklistByAccount,
@@ -31,7 +30,6 @@ import {
   removeServerFromServerBlocklist,
   ServerInfo,
   setAccessTokensToServers,
-  unfollow,
   uploadVideo,
   userLogin,
   waitJobs
@@ -742,9 +740,9 @@ describe('Test blocklist', function () {
 
         {
           const now = new Date()
-          await unfollow(servers[1].url, servers[1].accessToken, servers[0])
+          await servers[1].followsCommand.unfollow({ target: servers[0] })
           await waitJobs(servers)
-          await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken)
+          await servers[1].followsCommand.follow({ targets: [ servers[0].host ] })
 
           await waitJobs(servers)
 
@@ -807,9 +805,9 @@ describe('Test blocklist', function () {
 
         {
           const now = new Date()
-          await unfollow(servers[1].url, servers[1].accessToken, servers[0])
+          await servers[1].followsCommand.unfollow({ target: servers[0] })
           await waitJobs(servers)
-          await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken)
+          await servers[1].followsCommand.follow({ targets: [ servers[0].host ] })
 
           await waitJobs(servers)
 
index c4f63200a41097ca489271fd600719a832943149..9a93ce401bd225c83bb67ded30982276b03ce216 100644 (file)
@@ -21,7 +21,6 @@ import {
   checkVideoIsPublished,
   cleanupTests,
   createUser,
-  follow,
   generateUserAccessToken,
   getAccount,
   getCustomConfig,
@@ -35,7 +34,6 @@ import {
   removeUserSubscription,
   removeVideoFromBlacklist,
   ServerInfo,
-  unfollow,
   updateCustomConfig,
   updateCustomSubConfig,
   uploadVideo,
@@ -386,7 +384,7 @@ describe('Test moderation notifications', function () {
     it('Should send a notification only to admin when there is a new instance follower', async function () {
       this.timeout(20000)
 
-      await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
+      await servers[2].followsCommand.follow({ targets: [ servers[0].url ] })
 
       await waitJobs(servers)
 
@@ -399,7 +397,7 @@ describe('Test moderation notifications', function () {
     it('Should send a notification on auto follow back', async function () {
       this.timeout(40000)
 
-      await unfollow(servers[2].url, servers[2].accessToken, servers[0])
+      await servers[2].followsCommand.unfollow({ target: servers[0] })
       await waitJobs(servers)
 
       const config = {
@@ -411,7 +409,7 @@ describe('Test moderation notifications', function () {
       }
       await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
 
-      await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
+      await servers[2].followsCommand.follow({ targets: [ servers[0].url ] })
 
       await waitJobs(servers)
 
@@ -424,13 +422,13 @@ describe('Test moderation notifications', function () {
 
       config.followings.instance.autoFollowBack.enabled = false
       await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
-      await unfollow(servers[0].url, servers[0].accessToken, servers[2])
-      await unfollow(servers[2].url, servers[2].accessToken, servers[0])
+      await servers[0].followsCommand.unfollow({ target: servers[2] })
+      await servers[2].followsCommand.unfollow({ target: servers[0] })
     })
 
     it('Should send a notification on auto instances index follow', async function () {
       this.timeout(30000)
-      await unfollow(servers[0].url, servers[0].accessToken, servers[1])
+      await servers[0].followsCommand.unfollow({ target: servers[1] })
 
       await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
 
@@ -443,7 +441,7 @@ describe('Test moderation notifications', function () {
 
       config.followings.instance.autoFollowIndex.enabled = false
       await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
-      await unfollow(servers[0].url, servers[0].accessToken, servers[1])
+      await servers[0].followsCommand.unfollow({ target: servers[1] })
     })
   })
 
index 1cb1603bc0a3989bb958bc9731bfb0ccd1f16204..602f4bc1b88c0b4bafd941f13b9ca4fab1394ca6 100644 (file)
@@ -7,7 +7,6 @@ import { VideoPrivacy } from '@shared/models'
 import {
   cleanupTests,
   flushAndRunServer,
-  follow,
   killallServers,
   reRunServer,
   ServerInfo,
@@ -98,7 +97,7 @@ describe('Test redundancy constraints', function () {
     await waitJobs(servers)
 
     // Server 1 and server 2 follow each other
-    await follow(remoteServer.url, [ localServer.url ], remoteServer.accessToken)
+    await remoteServer.followsCommand.follow({ targets: [ localServer.url ] })
     await waitJobs(servers)
     await updateRedundancy(remoteServer.url, remoteServer.accessToken, localServer.host, true)
 
@@ -184,7 +183,7 @@ describe('Test redundancy constraints', function () {
   it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () {
     this.timeout(120000)
 
-    await follow(localServer.url, [ remoteServer.url ], localServer.accessToken)
+    await localServer.followsCommand.follow({ targets: [ remoteServer.url ] })
     await waitJobs(servers)
 
     await uploadWrapper('video 4 server 2')
index 0e0a73b9ddc3b9a0063fdd5a4178b07616d0c98b..dfe8099edfc4d30f2a000597f0dd9684725f95e0 100644 (file)
@@ -12,7 +12,6 @@ import {
   cleanupTests,
   doubleFollow,
   flushAndRunMultipleServers,
-  getFollowingListPaginationAndSort,
   getVideo,
   getVideoWithToken,
   immutableAssign,
@@ -23,7 +22,6 @@ import {
   root,
   ServerInfo,
   setAccessTokensToServers,
-  unfollow,
   updateVideo,
   uploadVideo,
   viewVideo,
@@ -38,7 +36,6 @@ import {
   updateRedundancy
 } from '../../../../shared/extra-utils/server/redundancy'
 import { getStats } from '../../../../shared/extra-utils/server/stats'
-import { ActorFollow } from '../../../../shared/models/actors'
 import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy'
 import { ServerStats } from '../../../../shared/models/server/server-stats.model'
 import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
@@ -272,13 +269,19 @@ async function checkStatsWithoutRedundancy (strategy: VideoRedundancyStrategyWit
   expect(stat.totalVideos).to.equal(0)
 }
 
+async function findServerFollows () {
+  const body = await servers[0].followsCommand.getFollowings({ start: 0, count: 5, sort: '-createdAt' })
+  const follows = body.data
+  const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`)
+  const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`)
+
+  return { server2, server3 }
+}
+
 async function enableRedundancyOnServer1 () {
   await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true)
 
-  const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: '-createdAt' })
-  const follows: ActorFollow[] = res.body.data
-  const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`)
-  const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`)
+  const { server2, server3 } = await findServerFollows()
 
   expect(server3).to.not.be.undefined
   expect(server3.following.hostRedundancyAllowed).to.be.false
@@ -290,10 +293,7 @@ async function enableRedundancyOnServer1 () {
 async function disableRedundancyOnServer1 () {
   await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, false)
 
-  const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: '-createdAt' })
-  const follows: ActorFollow[] = res.body.data
-  const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`)
-  const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`)
+  const { server2, server3 } = await findServerFollows()
 
   expect(server3).to.not.be.undefined
   expect(server3.following.hostRedundancyAllowed).to.be.false
@@ -388,7 +388,7 @@ describe('Test videos redundancy', function () {
     it('Should unfollow on server 1 and remove duplicated videos', async function () {
       this.timeout(80000)
 
-      await unfollow(servers[0].url, servers[0].accessToken, servers[1])
+      await servers[0].followsCommand.unfollow({ target: servers[1] })
 
       await waitJobs(servers)
       await wait(5000)
index 1519b263fb0eb54dac0c53d3b69b817a83fd800b..02389b1e98cad2f22e1b5220e17c0f97994262e2 100644 (file)
@@ -3,64 +3,46 @@
 import 'mocha'
 import * as chai from 'chai'
 import {
-  acceptFollower,
   cleanupTests,
   flushAndRunMultipleServers,
   MockInstancesIndex,
   ServerInfo,
   setAccessTokensToServers,
-  unfollow,
   updateCustomSubConfig,
-  wait
-} from '../../../../shared/extra-utils/index'
-import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort } from '../../../../shared/extra-utils/server/follows'
-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
-import { ActorFollow } from '../../../../shared/models/actors'
+  wait,
+  waitJobs
+} from '@shared/extra-utils'
 
 const expect = chai.expect
 
 async function checkFollow (follower: ServerInfo, following: ServerInfo, exists: boolean) {
   {
-    const res = await getFollowersListPaginationAndSort({ url: following.url, start: 0, count: 5, sort: '-createdAt' })
-    const follows = res.body.data as ActorFollow[]
+    const body = await following.followsCommand.getFollowers({ start: 0, count: 5, sort: '-createdAt' })
+    const follow = body.data.find(f => f.follower.host === follower.host && f.state === 'accepted')
 
-    const follow = follows.find(f => {
-      return f.follower.host === follower.host && f.state === 'accepted'
-    })
-
-    if (exists === true) {
-      expect(follow).to.exist
-    } else {
-      expect(follow).to.be.undefined
-    }
+    if (exists === true) expect(follow).to.exist
+    else expect(follow).to.be.undefined
   }
 
   {
-    const res = await getFollowingListPaginationAndSort({ url: follower.url, start: 0, count: 5, sort: '-createdAt' })
-    const follows = res.body.data as ActorFollow[]
-
-    const follow = follows.find(f => {
-      return f.following.host === following.host && f.state === 'accepted'
-    })
+    const body = await follower.followsCommand.getFollowings({ start: 0, count: 5, sort: '-createdAt' })
+    const follow = body.data.find(f => f.following.host === following.host && f.state === 'accepted')
 
-    if (exists === true) {
-      expect(follow).to.exist
-    } else {
-      expect(follow).to.be.undefined
-    }
+    if (exists === true) expect(follow).to.exist
+    else expect(follow).to.be.undefined
   }
 }
 
 async function server1Follows2 (servers: ServerInfo[]) {
-  await follow(servers[0].url, [ servers[1].host ], servers[0].accessToken)
+  await servers[0].followsCommand.follow({ targets: [ servers[1].host ] })
 
   await waitJobs(servers)
 }
 
 async function resetFollows (servers: ServerInfo[]) {
   try {
-    await unfollow(servers[0].url, servers[0].accessToken, servers[1])
-    await unfollow(servers[1].url, servers[1].accessToken, servers[0])
+    await servers[0].followsCommand.unfollow({ target: servers[1] })
+    await servers[1].followsCommand.unfollow({ target: servers[0] })
   } catch { /* empty */
   }
 
@@ -137,7 +119,7 @@ describe('Test auto follows', function () {
       await checkFollow(servers[0], servers[1], false)
       await checkFollow(servers[1], servers[0], false)
 
-      await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@' + servers[0].host)
+      await servers[1].followsCommand.acceptFollower({ follower: 'peertube@' + servers[0].host })
       await waitJobs(servers)
 
       await checkFollow(servers[0], servers[1], true)
index 3f2f71f46762a32b54635025ef5aa7b10d9daac6..0f1c6264d1067437b28260a6d15288c8c0198f6a 100644 (file)
@@ -1,9 +1,12 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import * as chai from 'chai'
 import 'mocha'
+import * as chai from 'chai'
+import { HttpStatusCode } from '@shared/core-utils'
+import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
 import {
   cleanupTests,
+  createUser,
   doubleFollow,
   flushAndRunMultipleServers,
   getAccountVideos,
@@ -12,13 +15,9 @@ import {
   getVideoWithToken,
   ServerInfo,
   setAccessTokensToServers,
-  uploadVideo
+  uploadVideo,
+  userLogin
 } from '../../../../shared/extra-utils'
-import { unfollow } from '../../../../shared/extra-utils/server/follows'
-import { userLogin } from '../../../../shared/extra-utils/users/login'
-import { createUser } from '../../../../shared/extra-utils/users/users'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
-import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
 
 const expect = chai.expect
 
@@ -144,7 +143,7 @@ describe('Test follow constraints', function () {
     before(async function () {
       this.timeout(30000)
 
-      await unfollow(servers[0].url, servers[0].accessToken, servers[1])
+      await servers[0].followsCommand.unfollow({ target: servers[1] })
     })
 
     describe('With an unlogged user', function () {
index 73c212a32333771236602488d6e02b669786c032..4853b647da3465be852ad2bb48bac8f00ab127f3 100644 (file)
@@ -1,43 +1,30 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import * as chai from 'chai'
 import 'mocha'
+import * as chai from 'chai'
 import {
-  acceptFollower,
   cleanupTests,
   flushAndRunMultipleServers,
+  FollowsCommand,
   ServerInfo,
   setAccessTokensToServers,
-  updateCustomSubConfig
-} from '../../../../shared/extra-utils/index'
-import {
-  follow,
-  getFollowersListPaginationAndSort,
-  getFollowingListPaginationAndSort,
-  rejectFollower,
-  removeFollower
-} from '../../../../shared/extra-utils/server/follows'
-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
-import { ActorFollow } from '../../../../shared/models/actors'
+  updateCustomSubConfig,
+  waitJobs
+} from '@shared/extra-utils'
 
 const expect = chai.expect
 
 async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'accepted') {
-  {
-    const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' })
-    expect(res.body.total).to.equal(1)
+  const fns = [
+    servers[0].followsCommand.getFollowings.bind(servers[0].followsCommand),
+    servers[1].followsCommand.getFollowers.bind(servers[1].followsCommand)
+  ]
 
-    const follow = res.body.data[0] as ActorFollow
-    expect(follow.state).to.equal(state)
-    expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + '/accounts/peertube')
-    expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube')
-  }
-
-  {
-    const res = await getFollowersListPaginationAndSort({ url: servers[1].url, start: 0, count: 5, sort: 'createdAt' })
-    expect(res.body.total).to.equal(1)
+  for (const fn of fns) {
+    const body = await fn({ start: 0, count: 5, sort: 'createdAt' })
+    expect(body.total).to.equal(1)
 
-    const follow = res.body.data[0] as ActorFollow
+    const follow = body.data[0]
     expect(follow.state).to.equal(state)
     expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + '/accounts/peertube')
     expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube')
@@ -45,19 +32,20 @@ async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'acc
 }
 
 async function checkNoFollowers (servers: ServerInfo[]) {
-  {
-    const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' })
-    expect(res.body.total).to.equal(0)
-  }
-
-  {
-    const res = await getFollowersListPaginationAndSort({ url: servers[1].url, start: 0, count: 5, sort: 'createdAt' })
-    expect(res.body.total).to.equal(0)
+  const fns = [
+    servers[0].followsCommand.getFollowings.bind(servers[0].followsCommand),
+    servers[1].followsCommand.getFollowers.bind(servers[1].followsCommand)
+  ]
+
+  for (const fn of fns) {
+    const body = await fn({ start: 0, count: 5, sort: 'createdAt' })
+    expect(body.total).to.equal(0)
   }
 }
 
 describe('Test follows moderation', function () {
   let servers: ServerInfo[] = []
+  let commands: FollowsCommand[]
 
   before(async function () {
     this.timeout(30000)
@@ -66,12 +54,14 @@ describe('Test follows moderation', function () {
 
     // Get the access tokens
     await setAccessTokensToServers(servers)
+
+    commands = servers.map(s => s.followsCommand)
   })
 
   it('Should have server 1 following server 2', async function () {
     this.timeout(30000)
 
-    await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
+    await commands[0].follow({ targets: [ servers[1].url ] })
 
     await waitJobs(servers)
   })
@@ -83,7 +73,7 @@ describe('Test follows moderation', function () {
   it('Should remove follower on server 2', async function () {
     this.timeout(10000)
 
-    await removeFollower(servers[1].url, servers[1].accessToken, servers[0])
+    await commands[1].removeFollower({ follower: servers[0] })
 
     await waitJobs(servers)
   })
@@ -106,7 +96,7 @@ describe('Test follows moderation', function () {
 
     await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
 
-    await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
+    await commands[0].follow({ targets: [ servers[1].url ] })
     await waitJobs(servers)
 
     await checkNoFollowers(servers)
@@ -126,7 +116,7 @@ describe('Test follows moderation', function () {
 
     await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
 
-    await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
+    await commands[0].follow({ targets: [ servers[1].url ] })
     await waitJobs(servers)
 
     await checkServer1And2HasFollowers(servers)
@@ -135,7 +125,7 @@ describe('Test follows moderation', function () {
   it('Should manually approve followers', async function () {
     this.timeout(20000)
 
-    await removeFollower(servers[1].url, servers[1].accessToken, servers[0])
+    await commands[1].removeFollower({ follower: servers[0] })
     await waitJobs(servers)
 
     const subConfig = {
@@ -150,7 +140,7 @@ describe('Test follows moderation', function () {
     await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
     await updateCustomSubConfig(servers[2].url, servers[2].accessToken, subConfig)
 
-    await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
+    await commands[0].follow({ targets: [ servers[1].url ] })
     await waitJobs(servers)
 
     await checkServer1And2HasFollowers(servers, 'pending')
@@ -159,7 +149,7 @@ describe('Test follows moderation', function () {
   it('Should accept a follower', async function () {
     this.timeout(10000)
 
-    await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@localhost:' + servers[0].port)
+    await commands[1].acceptFollower({ follower: 'peertube@localhost:' + servers[0].port })
     await waitJobs(servers)
 
     await checkServer1And2HasFollowers(servers)
@@ -168,32 +158,32 @@ describe('Test follows moderation', function () {
   it('Should reject another follower', async function () {
     this.timeout(20000)
 
-    await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken)
+    await commands[0].follow({ targets: [ servers[2].url ] })
     await waitJobs(servers)
 
     {
-      const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' })
-      expect(res.body.total).to.equal(2)
+      const body = await commands[0].getFollowings({ start: 0, count: 5, sort: 'createdAt' })
+      expect(body.total).to.equal(2)
     }
 
     {
-      const res = await getFollowersListPaginationAndSort({ url: servers[1].url, start: 0, count: 5, sort: 'createdAt' })
-      expect(res.body.total).to.equal(1)
+      const body = await commands[1].getFollowers({ start: 0, count: 5, sort: 'createdAt' })
+      expect(body.total).to.equal(1)
     }
 
     {
-      const res = await getFollowersListPaginationAndSort({ url: servers[2].url, start: 0, count: 5, sort: 'createdAt' })
-      expect(res.body.total).to.equal(1)
+      const body = await commands[2].getFollowers({ start: 0, count: 5, sort: 'createdAt' })
+      expect(body.total).to.equal(1)
     }
 
-    await rejectFollower(servers[2].url, servers[2].accessToken, 'peertube@localhost:' + servers[0].port)
+    await commands[2].rejectFollower({ follower: 'peertube@localhost:' + servers[0].port })
     await waitJobs(servers)
 
     await checkServer1And2HasFollowers(servers)
 
     {
-      const res = await getFollowersListPaginationAndSort({ url: servers[2].url, start: 0, count: 5, sort: 'createdAt' })
-      expect(res.body.total).to.equal(0)
+      const body = await commands[2].getFollowers({ start: 0, count: 5, sort: 'createdAt' })
+      expect(body.total).to.equal(0)
     }
   })
 
index 9e5aa00c75f1323129991f28c65efb13ce0f6225..c8fcca02cd9b9a244146c0c4edde6caa746066a3 100644 (file)
@@ -13,9 +13,7 @@ import {
   deleteVideoComment,
   expectAccountFollows,
   flushAndRunMultipleServers,
-  follow,
-  getFollowersListPaginationAndSort,
-  getFollowingListPaginationAndSort,
+  FollowsCommand,
   getVideoCommentThreads,
   getVideosList,
   getVideoThreadComments,
@@ -24,7 +22,6 @@ import {
   ServerInfo,
   setAccessTokensToServers,
   testCaptionFile,
-  unfollow,
   uploadVideo,
   userLogin,
   waitJobs
@@ -35,11 +32,13 @@ const expect = chai.expect
 
 describe('Test follows', function () {
   let servers: ServerInfo[] = []
+  let followsCommands: FollowsCommand[]
 
   before(async function () {
     this.timeout(30000)
 
     servers = await flushAndRunMultipleServers(3)
+    followsCommands = servers.map(s => s.followsCommand)
 
     // Get the access tokens
     await setAccessTokensToServers(servers)
@@ -47,10 +46,10 @@ describe('Test follows', function () {
 
   it('Should not have followers', async function () {
     for (const server of servers) {
-      const res = await getFollowersListPaginationAndSort({ url: server.url, start: 0, count: 5, sort: 'createdAt' })
-      const follows = res.body.data
+      const body = await server.followsCommand.getFollowers({ start: 0, count: 5, sort: 'createdAt' })
+      expect(body.total).to.equal(0)
 
-      expect(res.body.total).to.equal(0)
+      const follows = body.data
       expect(follows).to.be.an('array')
       expect(follows.length).to.equal(0)
     }
@@ -58,10 +57,10 @@ describe('Test follows', function () {
 
   it('Should not have following', async function () {
     for (const server of servers) {
-      const res = await getFollowingListPaginationAndSort({ url: server.url, start: 0, count: 5, sort: 'createdAt' })
-      const follows = res.body.data
+      const body = await server.followsCommand.getFollowings({ start: 0, count: 5, sort: 'createdAt' })
+      expect(body.total).to.equal(0)
 
-      expect(res.body.total).to.equal(0)
+      const follows = body.data
       expect(follows).to.be.an('array')
       expect(follows.length).to.equal(0)
     }
@@ -70,21 +69,21 @@ describe('Test follows', function () {
   it('Should have server 1 following server 2 and 3', async function () {
     this.timeout(30000)
 
-    await follow(servers[0].url, [ servers[1].url, servers[2].url ], servers[0].accessToken)
+    await followsCommands[0].follow({ targets: [ servers[1].url, servers[2].url ] })
 
     await waitJobs(servers)
   })
 
   it('Should have 2 followings on server 1', async function () {
-    let res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 1, sort: 'createdAt' })
-    let follows = res.body.data
+    const body = await followsCommands[0].getFollowings({ start: 0, count: 1, sort: 'createdAt' })
+    expect(body.total).to.equal(2)
 
-    expect(res.body.total).to.equal(2)
+    let follows = body.data
     expect(follows).to.be.an('array')
     expect(follows.length).to.equal(1)
 
-    res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 1, count: 1, sort: 'createdAt' })
-    follows = follows.concat(res.body.data)
+    const body2 = await followsCommands[0].getFollowings({ start: 1, count: 1, sort: 'createdAt' })
+    follows = follows.concat(body2.data)
 
     const server2Follow = follows.find(f => f.following.host === 'localhost:' + servers[1].port)
     const server3Follow = follows.find(f => f.following.host === 'localhost:' + servers[2].port)
@@ -99,35 +98,33 @@ describe('Test follows', function () {
     const sort = 'createdAt'
     const start = 0
     const count = 1
-    const url = servers[0].url
 
     {
       const search = ':' + servers[1].port
 
       {
-        const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search })
-        const follows = res.body.data
+        const body = await followsCommands[0].getFollowings({ start, count, sort, search })
+        expect(body.total).to.equal(1)
 
-        expect(res.body.total).to.equal(1)
+        const follows = body.data
         expect(follows.length).to.equal(1)
         expect(follows[0].following.host).to.equal('localhost:' + servers[1].port)
       }
 
       {
-        const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search, state: 'accepted' })
-        expect(res.body.total).to.equal(1)
-        expect(res.body.data).to.have.lengthOf(1)
+        const body = await followsCommands[0].getFollowings({ start, count, sort, search, state: 'accepted' })
+        expect(body.total).to.equal(1)
+        expect(body.data).to.have.lengthOf(1)
       }
 
       {
-        const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search, state: 'accepted', actorType: 'Person' })
-        expect(res.body.total).to.equal(0)
-        expect(res.body.data).to.have.lengthOf(0)
+        const body = await followsCommands[0].getFollowings({ start, count, sort, search, state: 'accepted', actorType: 'Person' })
+        expect(body.total).to.equal(0)
+        expect(body.data).to.have.lengthOf(0)
       }
 
       {
-        const res = await getFollowingListPaginationAndSort({
-          url,
+        const body = await followsCommands[0].getFollowings({
           start,
           count,
           sort,
@@ -135,32 +132,31 @@ describe('Test follows', function () {
           state: 'accepted',
           actorType: 'Application'
         })
-        expect(res.body.total).to.equal(1)
-        expect(res.body.data).to.have.lengthOf(1)
+        expect(body.total).to.equal(1)
+        expect(body.data).to.have.lengthOf(1)
       }
 
       {
-        const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search, state: 'pending' })
-        expect(res.body.total).to.equal(0)
-        expect(res.body.data).to.have.lengthOf(0)
+        const body = await followsCommands[0].getFollowings({ start, count, sort, search, state: 'pending' })
+        expect(body.total).to.equal(0)
+        expect(body.data).to.have.lengthOf(0)
       }
     }
 
     {
-      const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search: 'bla' })
-      const follows = res.body.data
+      const body = await followsCommands[0].getFollowings({ start, count, sort, search: 'bla' })
+      expect(body.total).to.equal(0)
 
-      expect(res.body.total).to.equal(0)
-      expect(follows.length).to.equal(0)
+      expect(body.data.length).to.equal(0)
     }
   })
 
   it('Should have 0 followings on server 2 and 3', async function () {
     for (const server of [ servers[1], servers[2] ]) {
-      const res = await getFollowingListPaginationAndSort({ url: server.url, start: 0, count: 5, sort: 'createdAt' })
-      const follows = res.body.data
+      const body = await server.followsCommand.getFollowings({ start: 0, count: 5, sort: 'createdAt' })
+      expect(body.total).to.equal(0)
 
-      expect(res.body.total).to.equal(0)
+      const follows = body.data
       expect(follows).to.be.an('array')
       expect(follows.length).to.equal(0)
     }
@@ -168,10 +164,10 @@ describe('Test follows', function () {
 
   it('Should have 1 followers on server 2 and 3', async function () {
     for (const server of [ servers[1], servers[2] ]) {
-      const res = await getFollowersListPaginationAndSort({ url: server.url, start: 0, count: 1, sort: 'createdAt' })
+      const body = await server.followsCommand.getFollowers({ start: 0, count: 1, sort: 'createdAt' })
+      expect(body.total).to.equal(1)
 
-      const follows = res.body.data
-      expect(res.body.total).to.equal(1)
+      const follows = body.data
       expect(follows).to.be.an('array')
       expect(follows.length).to.equal(1)
       expect(follows[0].follower.host).to.equal('localhost:' + servers[0].port)
@@ -179,7 +175,6 @@ describe('Test follows', function () {
   })
 
   it('Should search/filter followers on server 2', async function () {
-    const url = servers[2].url
     const start = 0
     const count = 5
     const sort = 'createdAt'
@@ -188,29 +183,28 @@ describe('Test follows', function () {
       const search = servers[0].port + ''
 
       {
-        const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search })
-        const follows = res.body.data
+        const body = await followsCommands[2].getFollowers({ start, count, sort, search })
+        expect(body.total).to.equal(1)
 
-        expect(res.body.total).to.equal(1)
+        const follows = body.data
         expect(follows.length).to.equal(1)
         expect(follows[0].following.host).to.equal('localhost:' + servers[2].port)
       }
 
       {
-        const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search, state: 'accepted' })
-        expect(res.body.total).to.equal(1)
-        expect(res.body.data).to.have.lengthOf(1)
+        const body = await followsCommands[2].getFollowers({ start, count, sort, search, state: 'accepted' })
+        expect(body.total).to.equal(1)
+        expect(body.data).to.have.lengthOf(1)
       }
 
       {
-        const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search, state: 'accepted', actorType: 'Person' })
-        expect(res.body.total).to.equal(0)
-        expect(res.body.data).to.have.lengthOf(0)
+        const body = await followsCommands[2].getFollowers({ start, count, sort, search, state: 'accepted', actorType: 'Person' })
+        expect(body.total).to.equal(0)
+        expect(body.data).to.have.lengthOf(0)
       }
 
       {
-        const res = await getFollowersListPaginationAndSort({
-          url,
+        const body = await followsCommands[2].getFollowers({
           start,
           count,
           sort,
@@ -218,31 +212,31 @@ describe('Test follows', function () {
           state: 'accepted',
           actorType: 'Application'
         })
-        expect(res.body.total).to.equal(1)
-        expect(res.body.data).to.have.lengthOf(1)
+        expect(body.total).to.equal(1)
+        expect(body.data).to.have.lengthOf(1)
       }
 
       {
-        const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search, state: 'pending' })
-        expect(res.body.total).to.equal(0)
-        expect(res.body.data).to.have.lengthOf(0)
+        const body = await followsCommands[2].getFollowers({ start, count, sort, search, state: 'pending' })
+        expect(body.total).to.equal(0)
+        expect(body.data).to.have.lengthOf(0)
       }
     }
 
     {
-      const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search: 'bla' })
-      const follows = res.body.data
+      const body = await followsCommands[2].getFollowers({ start, count, sort, search: 'bla' })
+      expect(body.total).to.equal(0)
 
-      expect(res.body.total).to.equal(0)
+      const follows = body.data
       expect(follows.length).to.equal(0)
     }
   })
 
   it('Should have 0 followers on server 1', async function () {
-    const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' })
-    const follows = res.body.data
+    const body = await followsCommands[0].getFollowers({ start: 0, count: 5, sort: 'createdAt' })
+    expect(body.total).to.equal(0)
 
-    expect(res.body.total).to.equal(0)
+    const follows = body.data
     expect(follows).to.be.an('array')
     expect(follows.length).to.equal(0)
   })
@@ -263,16 +257,16 @@ describe('Test follows', function () {
   it('Should unfollow server 3 on server 1', async function () {
     this.timeout(5000)
 
-    await unfollow(servers[0].url, servers[0].accessToken, servers[2])
+    await followsCommands[0].unfollow({ target: servers[2] })
 
     await waitJobs(servers)
   })
 
   it('Should not follow server 3 on server 1 anymore', async function () {
-    const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' })
-    const follows = res.body.data
+    const body = await followsCommands[0].getFollowings({ start: 0, count: 2, sort: 'createdAt' })
+    expect(body.total).to.equal(1)
 
-    expect(res.body.total).to.equal(1)
+    const follows = body.data
     expect(follows).to.be.an('array')
     expect(follows.length).to.equal(1)
 
@@ -280,10 +274,10 @@ describe('Test follows', function () {
   })
 
   it('Should not have server 1 as follower on server 3 anymore', async function () {
-    const res = await getFollowersListPaginationAndSort({ url: servers[2].url, start: 0, count: 1, sort: 'createdAt' })
+    const body = await followsCommands[2].getFollowers({ start: 0, count: 1, sort: 'createdAt' })
+    expect(body.total).to.equal(0)
 
-    const follows = res.body.data
-    expect(res.body.total).to.equal(0)
+    const follows = body.data
     expect(follows).to.be.an('array')
     expect(follows.length).to.equal(0)
   })
@@ -404,7 +398,7 @@ describe('Test follows', function () {
       await waitJobs(servers)
 
       // Server 1 follows server 3
-      await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken)
+      await followsCommands[0].follow({ targets: [ servers[2].url ] })
 
       await waitJobs(servers)
     })
@@ -563,7 +557,7 @@ describe('Test follows', function () {
     it('Should unfollow server 3 on server 1 and does not list server 3 videos', async function () {
       this.timeout(5000)
 
-      await unfollow(servers[0].url, servers[0].accessToken, servers[2])
+      await followsCommands[0].unfollow({ target: servers[2] })
 
       await waitJobs(servers)
 
index d57d72f5e4763ee50516df698b1ef759f8286f0d..eff4451e5e20d98f882596b82a46763507032d99 100644 (file)
@@ -1,39 +1,33 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import * as chai from 'chai'
 import 'mocha'
-import { JobState, Video } from '../../../../shared/models'
-import { VideoPrivacy } from '../../../../shared/models/videos'
-import { VideoCommentThreadTree } from '../../../../shared/models/videos/comment/video-comment.model'
-
+import * as chai from 'chai'
+import { HttpStatusCode } from '@shared/core-utils'
 import {
+  addVideoCommentReply,
+  addVideoCommentThread,
   cleanupTests,
   closeAllSequelize,
   completeVideoCheck,
   flushAndRunMultipleServers,
+  getJobsListPaginationAndSort,
   getVideo,
+  getVideoCommentThreads,
   getVideosList,
+  getVideoThreadComments,
   immutableAssign,
   killallServers,
   reRunServer,
   ServerInfo,
   setAccessTokensToServers,
   setActorFollowScores,
-  unfollow,
   updateVideo,
   uploadVideo,
   uploadVideoAndGetId,
-  wait
-} from '../../../../shared/extra-utils'
-import { follow, getFollowersListPaginationAndSort } from '../../../../shared/extra-utils/server/follows'
-import { getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs'
-import {
-  addVideoCommentReply,
-  addVideoCommentThread,
-  getVideoCommentThreads,
-  getVideoThreadComments
-} from '../../../../shared/extra-utils/videos/video-comments'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+  wait,
+  waitJobs
+} from '@shared/extra-utils'
+import { JobState, Video, VideoCommentThreadTree, VideoPrivacy } from '@shared/models'
 
 const expect = chai.expect
 
@@ -118,8 +112,8 @@ describe('Test handle downs', function () {
     this.timeout(240000)
 
     // Server 2 and 3 follow server 1
-    await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
-    await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
+    await servers[1].followsCommand.follow({ targets: [ servers[0].url ] })
+    await servers[2].followsCommand.follow({ targets: [ servers[0].url ] })
 
     await waitJobs(servers)
 
@@ -177,10 +171,10 @@ describe('Test handle downs', function () {
     await wait(11000)
 
     // Only server 3 is still a follower of server 1
-    const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' })
-    expect(res.body.data).to.be.an('array')
-    expect(res.body.data).to.have.lengthOf(1)
-    expect(res.body.data[0].follower.host).to.equal('localhost:' + servers[2].port)
+    const body = await servers[0].followsCommand.getFollowers({ start: 0, count: 2, sort: 'createdAt' })
+    expect(body.data).to.be.an('array')
+    expect(body.data).to.have.lengthOf(1)
+    expect(body.data[0].follower.host).to.equal('localhost:' + servers[2].port)
   })
 
   it('Should not have pending/processing jobs anymore', async function () {
@@ -205,16 +199,16 @@ describe('Test handle downs', function () {
     await reRunServer(servers[1])
     await reRunServer(servers[2])
 
-    await unfollow(servers[1].url, servers[1].accessToken, servers[0])
+    await servers[1].followsCommand.unfollow({ target: servers[0] })
     await waitJobs(servers)
 
-    await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
+    await servers[1].followsCommand.follow({ targets: [ servers[0].url ] })
 
     await waitJobs(servers)
 
-    const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' })
-    expect(res.body.data).to.be.an('array')
-    expect(res.body.data).to.have.lengthOf(2)
+    const body = await servers[0].followsCommand.getFollowers({ start: 0, count: 2, sort: 'createdAt' })
+    expect(body.data).to.be.an('array')
+    expect(body.data).to.have.lengthOf(2)
   })
 
   it('Should send an update to server 3, and automatically fetch the video', async function () {
index d0e222997645dad4cfce802fad172fd38144d6a1..6576dd7aff5510810b373d1097213956e34bd2ed 100644 (file)
@@ -1,13 +1,13 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import * as chai from 'chai'
 import 'mocha'
+import * as chai from 'chai'
 import { cleanupTests, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
+import { dateIsValid } from '../../../../shared/extra-utils/miscs/miscs'
 import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
 import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs'
 import { flushAndRunMultipleServers } from '../../../../shared/extra-utils/server/servers'
 import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
-import { dateIsValid } from '../../../../shared/extra-utils/miscs/miscs'
 import { Job } from '../../../../shared/models/server'
 
 const expect = chai.expect
index 304181a6d5e6765efbd641be53a91efc5b77746d..f609ea7254ff0218086c33e8264a37ee9288041e 100644 (file)
@@ -4,27 +4,23 @@ import 'mocha'
 import * as chai from 'chai'
 import {
   addVideoChannel,
+  addVideoCommentThread,
   cleanupTests,
   createUser,
   createVideoPlaylist,
   doubleFollow,
   flushAndRunMultipleServers,
-  follow,
   ServerInfo,
-  unfollow,
+  setAccessTokensToServers,
   updateCustomSubConfig,
   uploadVideo,
   userLogin,
   viewVideo,
-  wait
-} from '../../../../shared/extra-utils'
-import { setAccessTokensToServers } from '../../../../shared/extra-utils/index'
-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
-import { getStats } from '../../../../shared/extra-utils/server/stats'
-import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
-import { ServerStats } from '../../../../shared/models/server/server-stats.model'
-import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
-import { ActivityType } from '@shared/models'
+  wait,
+  waitJobs
+} from '@shared/extra-utils'
+import { getStats } from '@shared/extra-utils/server/stats'
+import { ActivityType, ServerStats, VideoPlaylistPrivacy } from '@shared/models'
 
 const expect = chai.expect
 
@@ -57,7 +53,7 @@ describe('Test stats (excluding redundancy)', function () {
     // Wait the video views repeatable job
     await wait(8000)
 
-    await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
+    await servers[2].followsCommand.follow({ targets: [ servers[0].url ] })
     await waitJobs(servers)
   })
 
@@ -111,7 +107,7 @@ describe('Test stats (excluding redundancy)', function () {
   it('Should have the correct total videos stats after an unfollow', async function () {
     this.timeout(15000)
 
-    await unfollow(servers[2].url, servers[2].accessToken, servers[0])
+    await servers[2].followsCommand.unfollow({ target: servers[0] })
     await waitJobs(servers)
 
     const res = await getStats(servers[2].url)
index 60676a37bbb3c00b3bc732eabacc92b6eb459f9b..7e365d7972b2a149f09247f7179095cf079e0e8f 100644 (file)
@@ -1,30 +1,27 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import * as chai from 'chai'
 import 'mocha'
+import * as chai from 'chai'
 import {
+  addUserSubscription,
+  areSubscriptionsExist,
   cleanupTests,
   createUser,
   doubleFollow,
   flushAndRunMultipleServers,
-  follow,
-  getVideosList,
-  unfollow,
-  updateVideo,
-  userLogin
-} from '../../../../shared/extra-utils'
-import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
-import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
-import { Video, VideoChannel } from '../../../../shared/models/videos'
-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
-import {
-  addUserSubscription,
-  areSubscriptionsExist,
   getUserSubscription,
+  getVideosList,
   listUserSubscriptions,
   listUserSubscriptionVideos,
-  removeUserSubscription
-} from '../../../../shared/extra-utils/users/user-subscriptions'
+  removeUserSubscription,
+  ServerInfo,
+  setAccessTokensToServers,
+  updateVideo,
+  uploadVideo,
+  userLogin,
+  waitJobs
+} from '@shared/extra-utils'
+import { Video, VideoChannel } from '@shared/models'
 
 const expect = chai.expect
 
@@ -250,7 +247,7 @@ describe('Test users subscriptions', function () {
   it('Should have server 1 follow server 3 and display server 3 videos', async function () {
     this.timeout(60000)
 
-    await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken)
+    await servers[0].followsCommand.follow({ targets: [ servers[2].url ] })
 
     await waitJobs(servers)
 
@@ -268,7 +265,7 @@ describe('Test users subscriptions', function () {
   it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () {
     this.timeout(60000)
 
-    await unfollow(servers[0].url, servers[0].accessToken, servers[2])
+    await servers[0].followsCommand.unfollow({ target: servers[2] })
 
     await waitJobs(servers)
 
index 6bfc7cfe53a1792a7380b414a156e405571a1d66..92927ea97f6e167c1f5546374d2d0cf25850778b 100644 (file)
@@ -11,7 +11,6 @@ import {
   createUser,
   deleteMe,
   flushAndRunServer,
-  follow,
   getAccountRatings,
   getBlacklistedVideosList,
   getCustomConfig,
@@ -138,7 +137,12 @@ describe('Test users', function () {
 
     it('Should not be able to follow', async function () {
       accessToken = 'my_super_token'
-      await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401)
+
+      await server.followsCommand.follow({
+        targets: [ 'http://example.com' ],
+        token: accessToken,
+        expectedStatus: HttpStatusCode.UNAUTHORIZED_401
+      })
     })
 
     it('Should not be able to unfollow')
index b8e98e45f1cf64ce1c87717c89558c5cdfe97880..e1c9afe794c0100260fd96ce3be18f556e527d70 100644 (file)
@@ -1,7 +1,7 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import * as chai from 'chai'
 import 'mocha'
+import * as chai from 'chai'
 import {
   cleanupTests,
   flushAndRunMultipleServers,
index da8de054b612dae26e971d3174731ef8e894dba2..28f68dcfe61a3bf59b1871b96366e46745098799 100644 (file)
@@ -2,8 +2,12 @@
 
 import 'mocha'
 import * as chai from 'chai'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { HttpStatusCode } from '@shared/core-utils'
 import {
+  addAccountToAccountBlocklist,
+  addAccountToServerBlocklist,
+  addServerToAccountBlocklist,
+  addServerToServerBlocklist,
   addVideoChannel,
   addVideoInPlaylist,
   addVideoToBlacklist,
@@ -27,6 +31,10 @@ import {
   getVideoPlaylistPrivacies,
   getVideoPlaylistsList,
   getVideoPlaylistWithToken,
+  removeAccountFromAccountBlocklist,
+  removeAccountFromServerBlocklist,
+  removeServerFromAccountBlocklist,
+  removeServerFromServerBlocklist,
   removeUser,
   removeVideoFromBlacklist,
   removeVideoFromPlaylist,
@@ -35,7 +43,6 @@ import {
   setAccessTokensToServers,
   setDefaultVideoChannel,
   testImage,
-  unfollow,
   updateVideo,
   updateVideoPlaylist,
   updateVideoPlaylistElement,
@@ -44,24 +51,18 @@ import {
   userLogin,
   wait,
   waitJobs
-} from '../../../../shared/extra-utils'
+} from '@shared/extra-utils'
 import {
-  addAccountToAccountBlocklist,
-  addAccountToServerBlocklist,
-  addServerToAccountBlocklist,
-  addServerToServerBlocklist,
-  removeAccountFromAccountBlocklist,
-  removeAccountFromServerBlocklist,
-  removeServerFromAccountBlocklist,
-  removeServerFromServerBlocklist
-} from '../../../../shared/extra-utils/users/blocklist'
-import { User } from '../../../../shared/models/users'
-import { VideoPlaylistCreateResult, VideoPrivacy } from '../../../../shared/models/videos'
-import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'
-import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../../shared/models/videos/playlist/video-playlist-element.model'
-import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
-import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
-import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model'
+  User,
+  VideoExistInPlaylist,
+  VideoPlaylist,
+  VideoPlaylistCreateResult,
+  VideoPlaylistElement,
+  VideoPlaylistElementType,
+  VideoPlaylistPrivacy,
+  VideoPlaylistType,
+  VideoPrivacy
+} from '@shared/models'
 
 const expect = chai.expect
 
@@ -1171,7 +1172,7 @@ describe('Test video playlists', function () {
         expect(finder(res.body.data)).to.not.be.undefined
       }
 
-      await unfollow(servers[2].url, servers[2].accessToken, servers[0])
+      await servers[2].followsCommand.unfollow({ target: servers[0] })
 
       {
         const res = await getVideoPlaylistsList(servers[2].url, 0, 5)
index 7b5835e47b834bf1ef3ae1412a00a98efff50ae4..48431ed83aa1720276c1133b6c9a971f83f7de65 100644 (file)
@@ -7,15 +7,14 @@ export * from './miscs'
 export * from './mock-servers'
 export * from './moderation'
 export * from './overviews'
+export * from './search'
+export * from './server'
 
 export * from './requests/check-api-params'
 export * from './requests/requests'
 
-export * from './search'
-
 export * from './server/clients'
 export * from './server/config'
-export * from './server/follows'
 export * from './server/jobs'
 export * from './server/plugins'
 export * from './server/servers'
diff --git a/shared/extra-utils/server/follows-command.ts b/shared/extra-utils/server/follows-command.ts
new file mode 100644 (file)
index 0000000..aba7bce
--- /dev/null
@@ -0,0 +1,124 @@
+import { pick } from 'lodash'
+import { ActivityPubActorType, ActorFollow, FollowState, ResultList } from '@shared/models'
+import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
+import { AbstractCommand, OverrideCommandOptions } from '../shared'
+import { ServerInfo } from './servers'
+
+export class FollowsCommand extends AbstractCommand {
+
+  getFollowers (options: OverrideCommandOptions & {
+    start: number
+    count: number
+    sort: string
+    search?: string
+    actorType?: ActivityPubActorType
+    state?: FollowState
+  }) {
+    const path = '/api/v1/server/followers'
+
+    const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ]
+    const query = pick(options, toPick)
+
+    return this.getRequestBody<ResultList<ActorFollow>>({
+      ...options,
+
+      token: null,
+
+      path,
+      query,
+      defaultExpectedStatus: HttpStatusCode.OK_200
+    })
+  }
+
+  getFollowings (options: OverrideCommandOptions & {
+    start: number
+    count: number
+    sort: string
+    search?: string
+    actorType?: ActivityPubActorType
+    state?: FollowState
+  }) {
+    const path = '/api/v1/server/following'
+
+    const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ]
+    const query = pick(options, toPick)
+
+    return this.getRequestBody<ResultList<ActorFollow>>({
+      ...options,
+
+      token: null,
+
+      path,
+      query,
+      defaultExpectedStatus: HttpStatusCode.OK_200
+    })
+  }
+
+  follow (options: OverrideCommandOptions & {
+    targets: string[]
+  }) {
+    const path = '/api/v1/server/following'
+
+    const hosts = options.targets.map(f => f.replace(/^http:\/\//, ''))
+
+    return this.postBodyRequest({
+      ...options,
+
+      path,
+      fields: { hosts },
+      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+    })
+  }
+
+  async unfollow (options: OverrideCommandOptions & {
+    target: ServerInfo
+  }) {
+    const path = '/api/v1/server/following/' + options.target.host
+
+    return this.deleteRequest({
+      ...options,
+
+      path,
+      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+    })
+  }
+
+  acceptFollower (options: OverrideCommandOptions & {
+    follower: string
+  }) {
+    const path = '/api/v1/server/followers/' + options.follower + '/accept'
+
+    return this.postBodyRequest({
+      ...options,
+
+      path,
+      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+    })
+  }
+
+  rejectFollower (options: OverrideCommandOptions & {
+    follower: string
+  }) {
+    const path = '/api/v1/server/followers/' + options.follower + '/reject'
+
+    return this.postBodyRequest({
+      ...options,
+
+      path,
+      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+    })
+  }
+
+  removeFollower (options: OverrideCommandOptions & {
+    follower: ServerInfo
+  }) {
+    const path = '/api/v1/server/followers/peertube@' + options.follower.host
+
+    return this.deleteRequest({
+      ...options,
+
+      path,
+      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+    })
+  }
+}
index 6aae4a31dfe4462b92d06d8a4d9ef9c265a8d4ae..c23cebd81a697322ad9a02c39f86dbd23f02be10 100644 (file)
-import * as request from 'supertest'
-import { ServerInfo } from './servers'
 import { waitJobs } from './jobs'
-import { makePostBodyRequest } from '../requests/requests'
-import { ActivityPubActorType, FollowState } from '@shared/models'
-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
-
-function getFollowersListPaginationAndSort (options: {
-  url: string
-  start: number
-  count: number
-  sort: string
-  search?: string
-  actorType?: ActivityPubActorType
-  state?: FollowState
-}) {
-  const { url, start, count, sort, search, state, actorType } = options
-  const path = '/api/v1/server/followers'
-
-  const query = {
-    start,
-    count,
-    sort,
-    search,
-    state,
-    actorType
-  }
-
-  return request(url)
-    .get(path)
-    .query(query)
-    .set('Accept', 'application/json')
-    .expect(HttpStatusCode.OK_200)
-    .expect('Content-Type', /json/)
-}
-
-function acceptFollower (url: string, token: string, follower: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
-  const path = '/api/v1/server/followers/' + follower + '/accept'
-
-  return makePostBodyRequest({
-    url,
-    token,
-    path,
-    statusCodeExpected
-  })
-}
-
-function rejectFollower (url: string, token: string, follower: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
-  const path = '/api/v1/server/followers/' + follower + '/reject'
-
-  return makePostBodyRequest({
-    url,
-    token,
-    path,
-    statusCodeExpected
-  })
-}
-
-function getFollowingListPaginationAndSort (options: {
-  url: string
-  start: number
-  count: number
-  sort: string
-  search?: string
-  actorType?: ActivityPubActorType
-  state?: FollowState
-}) {
-  const { url, start, count, sort, search, state, actorType } = options
-  const path = '/api/v1/server/following'
-
-  const query = {
-    start,
-    count,
-    sort,
-    search,
-    state,
-    actorType
-  }
-
-  return request(url)
-    .get(path)
-    .query(query)
-    .set('Accept', 'application/json')
-    .expect(HttpStatusCode.OK_200)
-    .expect('Content-Type', /json/)
-}
-
-function follow (follower: string, following: string[], accessToken: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
-  const path = '/api/v1/server/following'
-
-  const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
-  return request(follower)
-    .post(path)
-    .set('Accept', 'application/json')
-    .set('Authorization', 'Bearer ' + accessToken)
-    .send({ hosts: followingHosts })
-    .expect(expectedStatus)
-}
-
-async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
-  const path = '/api/v1/server/following/' + target.host
-
-  return request(url)
-    .delete(path)
-    .set('Accept', 'application/json')
-    .set('Authorization', 'Bearer ' + accessToken)
-    .expect(expectedStatus)
-}
-
-function removeFollower (url: string, accessToken: string, follower: ServerInfo, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
-  const path = '/api/v1/server/followers/peertube@' + follower.host
-
-  return request(url)
-    .delete(path)
-    .set('Accept', 'application/json')
-    .set('Authorization', 'Bearer ' + accessToken)
-    .expect(expectedStatus)
-}
+import { ServerInfo } from './servers'
 
 async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
   await Promise.all([
-    follow(server1.url, [ server2.url ], server1.accessToken),
-    follow(server2.url, [ server1.url ], server2.accessToken)
+    server1.followsCommand.follow({ targets: [ server2.url ] }),
+    server2.followsCommand.follow({ targets: [ server1.url ] })
   ])
 
   // Wait request propagation
@@ -132,12 +16,5 @@ async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
 // ---------------------------------------------------------------------------
 
 export {
-  getFollowersListPaginationAndSort,
-  getFollowingListPaginationAndSort,
-  unfollow,
-  removeFollower,
-  follow,
-  doubleFollow,
-  acceptFollower,
-  rejectFollower
+  doubleFollow
 }
index f0071ba72d5c93f3afbdece5e8794d871e2fdb02..258084623917a994244fe33cc3f1e530a09a2853 100644 (file)
@@ -1,2 +1,4 @@
 export * from './contact-form-command'
 export * from './debug-command'
+export * from './follows-command'
+export * from './follows'
index 30e712ab8d1c8dc01e21c0799dec8409c290a1cd..7ac80cea095ce27a3aa842ea0ffc1c6d9a833a6a 100644 (file)
@@ -18,6 +18,7 @@ import { makeGetRequest } from '../requests/requests'
 import { SearchCommand } from '../search'
 import { ContactFormCommand } from './contact-form-command'
 import { DebugCommand } from './debug-command'
+import { FollowsCommand } from './follows-command'
 
 interface ServerInfo {
   app: ChildProcess
@@ -81,6 +82,7 @@ interface ServerInfo {
   searchCommand?: SearchCommand
   contactFormCommand?: ContactFormCommand
   debugCommand?: DebugCommand
+  followsCommand?: FollowsCommand
 }
 
 function parallelTests () {
@@ -296,6 +298,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
       server.searchCommand = new SearchCommand(server)
       server.contactFormCommand = new ContactFormCommand(server)
       server.debugCommand = new DebugCommand(server)
+      server.followsCommand = new FollowsCommand(server)
 
       res(server)
     })