1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { flushAndRunMultipleServers, killallServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/utils/index'
8 getFollowersListPaginationAndSort,
9 getFollowingListPaginationAndSort,
11 } from '../../../../shared/utils/server/follows'
12 import { waitJobs } from '../../../../shared/utils/server/jobs'
13 import { ActorFollow } from '../../../../shared/models/actors'
15 const expect = chai.expect
17 describe('Test follows moderation', function () {
18 let servers: ServerInfo[] = []
20 before(async function () {
23 servers = await flushAndRunMultipleServers(2)
25 // Get the access tokens
26 await setAccessTokensToServers(servers)
29 it('Should have server 1 following server 2', async function () {
32 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
34 await waitJobs(servers)
37 it('Should have correct follows', async function () {
39 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
40 expect(res.body.total).to.equal(1)
42 const follow = res.body.data[0] as ActorFollow
43 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
44 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
48 const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt')
49 expect(res.body.total).to.equal(1)
51 const follow = res.body.data[0] as ActorFollow
52 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
53 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
57 it('Should remove follower on server 2', async function () {
58 await removeFollower(servers[1].url, servers[1].accessToken, servers[0])
60 await waitJobs(servers)
63 it('Should not not have follows anymore', async function () {
65 const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt')
66 expect(res.body.total).to.equal(0)
70 const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt')
71 expect(res.body.total).to.equal(0)
75 after(async function () {
76 killallServers(servers)