]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/follows-moderation.ts
Try to fix tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / follows-moderation.ts
index a360706f205df4f9bf28772bf5a8a97fd7acfe94..a82acdb34a4c8417e7e1e770337873f27259379a 100644 (file)
@@ -3,31 +3,34 @@
 import * as chai from 'chai'
 import 'mocha'
 import {
+  acceptFollower,
+  cleanupTests,
   flushAndRunMultipleServers,
-  killallServers,
   ServerInfo,
   setAccessTokensToServers,
   updateCustomSubConfig
-} from '../../../../shared/utils/index'
+} from '../../../../shared/extra-utils/index'
 import {
   follow,
   getFollowersListPaginationAndSort,
   getFollowingListPaginationAndSort,
+  rejectFollower,
   removeFollower
-} from '../../../../shared/utils/server/follows'
-import { waitJobs } from '../../../../shared/utils/server/jobs'
+} from '../../../../shared/extra-utils/server/follows'
+import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
 import { ActorFollow } from '../../../../shared/models/actors'
 
 const expect = chai.expect
 
-async function checkHasFollowers (servers: ServerInfo[]) {
+async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'accepted') {
   {
     const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
     expect(res.body.total).to.equal(1)
 
     const follow = res.body.data[0] as ActorFollow
-    expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
-    expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
+    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')
   }
 
   {
@@ -35,8 +38,9 @@ async function checkHasFollowers (servers: ServerInfo[]) {
     expect(res.body.total).to.equal(1)
 
     const follow = res.body.data[0] as ActorFollow
-    expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
-    expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
+    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')
   }
 }
 
@@ -58,7 +62,7 @@ describe('Test follows moderation', function () {
   before(async function () {
     this.timeout(30000)
 
-    servers = await flushAndRunMultipleServers(2)
+    servers = await flushAndRunMultipleServers(3)
 
     // Get the access tokens
     await setAccessTokensToServers(servers)
@@ -73,7 +77,7 @@ describe('Test follows moderation', function () {
   })
 
   it('Should have correct follows', async function () {
-    await checkHasFollowers(servers)
+    await checkServer1And2HasFollowers(servers)
   })
 
   it('Should remove follower on server 2', async function () {
@@ -90,7 +94,8 @@ describe('Test follows moderation', function () {
     const subConfig = {
       followers: {
         instance: {
-          enabled: false
+          enabled: false,
+          manualApproval: false
         }
       }
     }
@@ -107,7 +112,8 @@ describe('Test follows moderation', function () {
     const subConfig = {
       followers: {
         instance: {
-          enabled: true
+          enabled: true,
+          manualApproval: false
         }
       }
     }
@@ -117,10 +123,73 @@ describe('Test follows moderation', function () {
     await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
     await waitJobs(servers)
 
-    await checkHasFollowers(servers)
+    await checkServer1And2HasFollowers(servers)
+  })
+
+  it('Should manually approve followers', async function () {
+    this.timeout(20000)
+
+    await removeFollower(servers[1].url, servers[1].accessToken, servers[0])
+    await waitJobs(servers)
+
+    const subConfig = {
+      followers: {
+        instance: {
+          enabled: true,
+          manualApproval: true
+        }
+      }
+    }
+
+    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 waitJobs(servers)
+
+    await checkServer1And2HasFollowers(servers, 'pending')
+  })
+
+  it('Should accept a follower', async function () {
+    await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@localhost:' + servers[0].port)
+    await waitJobs(servers)
+
+    await checkServer1And2HasFollowers(servers)
+  })
+
+  it('Should reject another follower', async function () {
+    this.timeout(20000)
+
+    await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken)
+    await waitJobs(servers)
+
+    {
+      const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
+      expect(res.body.total).to.equal(2)
+    }
+
+    {
+      const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt')
+      expect(res.body.total).to.equal(1)
+    }
+
+    {
+      const res = await getFollowersListPaginationAndSort(servers[2].url, 0, 5, 'createdAt')
+      expect(res.body.total).to.equal(1)
+    }
+
+    await rejectFollower(servers[2].url, servers[2].accessToken, 'peertube@localhost:' + servers[0].port)
+    await waitJobs(servers)
+
+    await checkServer1And2HasFollowers(servers)
+
+    {
+      const res = await getFollowersListPaginationAndSort(servers[ 2 ].url, 0, 5, 'createdAt')
+      expect(res.body.total).to.equal(0)
+    }
   })
 
   after(async function () {
-    killallServers(servers)
+    await cleanupTests(servers)
   })
 })