1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
10 setAccessTokensToServers,
12 } from '@shared/server-commands'
14 const expect = chai.expect
16 async function checkServer1And2HasFollowers (servers: PeerTubeServer[], state = 'accepted') {
18 servers[0].follows.getFollowings.bind(servers[0].follows),
19 servers[1].follows.getFollowers.bind(servers[1].follows)
22 for (const fn of fns) {
23 const body = await fn({ start: 0, count: 5, sort: 'createdAt' })
24 expect(body.total).to.equal(1)
26 const follow = body.data[0]
27 expect(follow.state).to.equal(state)
28 expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + '/accounts/peertube')
29 expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube')
33 async function checkNoFollowers (servers: PeerTubeServer[]) {
35 servers[0].follows.getFollowings.bind(servers[0].follows),
36 servers[1].follows.getFollowers.bind(servers[1].follows)
39 for (const fn of fns) {
40 const body = await fn({ start: 0, count: 5, sort: 'createdAt' })
41 expect(body.total).to.equal(0)
45 describe('Test follows moderation', function () {
46 let servers: PeerTubeServer[] = []
47 let commands: FollowsCommand[]
49 before(async function () {
52 servers = await createMultipleServers(3)
54 // Get the access tokens
55 await setAccessTokensToServers(servers)
57 commands = servers.map(s => s.follows)
60 it('Should have server 1 following server 2', async function () {
63 await commands[0].follow({ hosts: [ servers[1].url ] })
65 await waitJobs(servers)
68 it('Should have correct follows', async function () {
69 await checkServer1And2HasFollowers(servers)
72 it('Should remove follower on server 2', async function () {
75 await commands[1].removeFollower({ follower: servers[0] })
77 await waitJobs(servers)
80 it('Should not not have follows anymore', async function () {
81 await checkNoFollowers(servers)
84 it('Should disable followers on server 2', async function () {
96 await servers[1].config.updateCustomSubConfig({ newConfig: subConfig })
98 await commands[0].follow({ hosts: [ servers[1].url ] })
99 await waitJobs(servers)
101 await checkNoFollowers(servers)
104 it('Should re enable followers on server 2', async function () {
111 manualApproval: false
116 await servers[1].config.updateCustomSubConfig({ newConfig: subConfig })
118 await commands[0].follow({ hosts: [ servers[1].url ] })
119 await waitJobs(servers)
121 await checkServer1And2HasFollowers(servers)
124 it('Should manually approve followers', async function () {
127 await commands[1].removeFollower({ follower: servers[0] })
128 await waitJobs(servers)
139 await servers[1].config.updateCustomSubConfig({ newConfig: subConfig })
140 await servers[2].config.updateCustomSubConfig({ newConfig: subConfig })
142 await commands[0].follow({ hosts: [ servers[1].url ] })
143 await waitJobs(servers)
145 await checkServer1And2HasFollowers(servers, 'pending')
148 it('Should accept a follower', async function () {
151 await commands[1].acceptFollower({ follower: 'peertube@localhost:' + servers[0].port })
152 await waitJobs(servers)
154 await checkServer1And2HasFollowers(servers)
157 it('Should reject another follower', async function () {
160 await commands[0].follow({ hosts: [ servers[2].url ] })
161 await waitJobs(servers)
164 const body = await commands[0].getFollowings({ start: 0, count: 5, sort: 'createdAt' })
165 expect(body.total).to.equal(2)
169 const body = await commands[1].getFollowers({ start: 0, count: 5, sort: 'createdAt' })
170 expect(body.total).to.equal(1)
174 const body = await commands[2].getFollowers({ start: 0, count: 5, sort: 'createdAt' })
175 expect(body.total).to.equal(1)
178 await commands[2].rejectFollower({ follower: 'peertube@localhost:' + servers[0].port })
179 await waitJobs(servers)
181 await checkServer1And2HasFollowers(servers)
184 const body = await commands[2].getFollowers({ start: 0, count: 5, sort: 'createdAt' })
185 expect(body.total).to.equal(0)
189 after(async function () {
190 await cleanupTests(servers)