1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
6 flushAndRunMultipleServers,
9 setAccessTokensToServers,
11 } from '../../../../shared/utils/index'
14 getFollowersListPaginationAndSort,
15 getFollowingListPaginationAndSort,
17 } from '../../../../shared/utils/server/follows'
18 import { waitJobs } from '../../../../shared/utils/server/jobs'
19 import { ActorFollow } from '../../../../shared/models/actors'
21 const expect = chai.expect
23 async function checkHasFollowers (servers: ServerInfo[]) {
25 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
26 expect(res.body.total).to.equal(1)
28 const follow = res.body.data[0] as ActorFollow
29 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
30 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
34 const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt')
35 expect(res.body.total).to.equal(1)
37 const follow = res.body.data[0] as ActorFollow
38 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
39 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
43 async function checkNoFollowers (servers: ServerInfo[]) {
45 const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 5, 'createdAt')
46 expect(res.body.total).to.equal(0)
50 const res = await getFollowersListPaginationAndSort(servers[ 1 ].url, 0, 5, 'createdAt')
51 expect(res.body.total).to.equal(0)
55 describe('Test follows moderation', function () {
56 let servers: ServerInfo[] = []
58 before(async function () {
61 servers = await flushAndRunMultipleServers(2)
63 // Get the access tokens
64 await setAccessTokensToServers(servers)
67 it('Should have server 1 following server 2', async function () {
70 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
72 await waitJobs(servers)
75 it('Should have correct follows', async function () {
76 await checkHasFollowers(servers)
79 it('Should remove follower on server 2', async function () {
80 await removeFollower(servers[1].url, servers[1].accessToken, servers[0])
82 await waitJobs(servers)
85 it('Should not not have follows anymore', async function () {
86 await checkNoFollowers(servers)
89 it('Should disable followers on server 2', async function () {
98 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
100 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
101 await waitJobs(servers)
103 await checkNoFollowers(servers)
106 it('Should re enable followers on server 2', async function () {
115 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
117 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
118 await waitJobs(servers)
120 await checkHasFollowers(servers)
123 after(async function () {
124 killallServers(servers)