1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
8 flushAndRunMultipleServers,
10 setAccessTokensToServers,
12 } from '../../../../shared/extra-utils/index'
15 getFollowersListPaginationAndSort,
16 getFollowingListPaginationAndSort,
19 } from '../../../../shared/extra-utils/server/follows'
20 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
21 import { ActorFollow } from '../../../../shared/models/actors'
23 const expect = chai.expect
25 async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'accepted') {
27 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
28 expect(res.body.total).to.equal(1)
30 const follow = res.body.data[0] as ActorFollow
31 expect(follow.state).to.equal(state)
32 expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + '/accounts/peertube')
33 expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube')
37 const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt')
38 expect(res.body.total).to.equal(1)
40 const follow = res.body.data[0] as ActorFollow
41 expect(follow.state).to.equal(state)
42 expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + '/accounts/peertube')
43 expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube')
47 async function checkNoFollowers (servers: ServerInfo[]) {
49 const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 5, 'createdAt')
50 expect(res.body.total).to.equal(0)
54 const res = await getFollowersListPaginationAndSort(servers[ 1 ].url, 0, 5, 'createdAt')
55 expect(res.body.total).to.equal(0)
59 describe('Test follows moderation', function () {
60 let servers: ServerInfo[] = []
62 before(async function () {
65 servers = await flushAndRunMultipleServers(3)
67 // Get the access tokens
68 await setAccessTokensToServers(servers)
71 it('Should have server 1 following server 2', async function () {
74 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
76 await waitJobs(servers)
79 it('Should have correct follows', async function () {
80 await checkServer1And2HasFollowers(servers)
83 it('Should remove follower on server 2', async function () {
84 await removeFollower(servers[1].url, servers[1].accessToken, servers[0])
86 await waitJobs(servers)
89 it('Should not not have follows anymore', async function () {
90 await checkNoFollowers(servers)
93 it('Should disable followers on server 2', async function () {
103 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
105 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
106 await waitJobs(servers)
108 await checkNoFollowers(servers)
111 it('Should re enable followers on server 2', async function () {
116 manualApproval: false
121 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
123 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
124 await waitJobs(servers)
126 await checkServer1And2HasFollowers(servers)
129 it('Should manually approve followers', async function () {
132 await removeFollower(servers[1].url, servers[1].accessToken, servers[0])
133 await waitJobs(servers)
144 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
145 await updateCustomSubConfig(servers[2].url, servers[2].accessToken, subConfig)
147 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
148 await waitJobs(servers)
150 await checkServer1And2HasFollowers(servers, 'pending')
153 it('Should accept a follower', async function () {
154 await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@localhost:' + servers[0].port)
155 await waitJobs(servers)
157 await checkServer1And2HasFollowers(servers)
160 it('Should reject another follower', async function () {
163 await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken)
164 await waitJobs(servers)
167 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
168 expect(res.body.total).to.equal(2)
172 const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt')
173 expect(res.body.total).to.equal(1)
177 const res = await getFollowersListPaginationAndSort(servers[2].url, 0, 5, 'createdAt')
178 expect(res.body.total).to.equal(1)
181 await rejectFollower(servers[2].url, servers[2].accessToken, 'peertube@localhost:' + servers[0].port)
182 await waitJobs(servers)
184 await checkServer1And2HasFollowers(servers)
187 const res = await getFollowersListPaginationAndSort(servers[ 2 ].url, 0, 5, 'createdAt')
188 expect(res.body.total).to.equal(0)
192 after(async function () {
193 await cleanupTests(servers)