Add ability to remove an instance follower in API
[oweals/peertube.git] / server / tests / api / server / follows-moderation.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import { flushAndRunMultipleServers, killallServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/utils/index'
6 import {
7   follow,
8   getFollowersListPaginationAndSort,
9   getFollowingListPaginationAndSort,
10   removeFollower
11 } from '../../../../shared/utils/server/follows'
12 import { waitJobs } from '../../../../shared/utils/server/jobs'
13 import { ActorFollow } from '../../../../shared/models/actors'
14
15 const expect = chai.expect
16
17 describe('Test follows moderation', function () {
18   let servers: ServerInfo[] = []
19
20   before(async function () {
21     this.timeout(30000)
22
23     servers = await flushAndRunMultipleServers(2)
24
25     // Get the access tokens
26     await setAccessTokensToServers(servers)
27   })
28
29   it('Should have server 1 following server 2', async function () {
30     this.timeout(30000)
31
32     await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
33
34     await waitJobs(servers)
35   })
36
37   it('Should have correct follows', async function () {
38     {
39       const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
40       expect(res.body.total).to.equal(1)
41
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')
45     }
46
47     {
48       const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt')
49       expect(res.body.total).to.equal(1)
50
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')
54     }
55   })
56
57   it('Should remove follower on server 2', async function () {
58     await removeFollower(servers[1].url, servers[1].accessToken, servers[0])
59
60     await waitJobs(servers)
61   })
62
63   it('Should not not have follows anymore', async function () {
64     {
65       const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt')
66       expect(res.body.total).to.equal(0)
67     }
68
69     {
70       const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt')
71       expect(res.body.total).to.equal(0)
72     }
73   })
74
75   after(async function () {
76     killallServers(servers)
77   })
78 })