]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/follows-moderation.ts
a360706f205df4f9bf28772bf5a8a97fd7acfe94
[github/Chocobozzz/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 {
6 flushAndRunMultipleServers,
7 killallServers,
8 ServerInfo,
9 setAccessTokensToServers,
10 updateCustomSubConfig
11 } from '../../../../shared/utils/index'
12 import {
13 follow,
14 getFollowersListPaginationAndSort,
15 getFollowingListPaginationAndSort,
16 removeFollower
17 } from '../../../../shared/utils/server/follows'
18 import { waitJobs } from '../../../../shared/utils/server/jobs'
19 import { ActorFollow } from '../../../../shared/models/actors'
20
21 const expect = chai.expect
22
23 async function checkHasFollowers (servers: ServerInfo[]) {
24 {
25 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
26 expect(res.body.total).to.equal(1)
27
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')
31 }
32
33 {
34 const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt')
35 expect(res.body.total).to.equal(1)
36
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')
40 }
41 }
42
43 async function checkNoFollowers (servers: ServerInfo[]) {
44 {
45 const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 5, 'createdAt')
46 expect(res.body.total).to.equal(0)
47 }
48
49 {
50 const res = await getFollowersListPaginationAndSort(servers[ 1 ].url, 0, 5, 'createdAt')
51 expect(res.body.total).to.equal(0)
52 }
53 }
54
55 describe('Test follows moderation', function () {
56 let servers: ServerInfo[] = []
57
58 before(async function () {
59 this.timeout(30000)
60
61 servers = await flushAndRunMultipleServers(2)
62
63 // Get the access tokens
64 await setAccessTokensToServers(servers)
65 })
66
67 it('Should have server 1 following server 2', async function () {
68 this.timeout(30000)
69
70 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
71
72 await waitJobs(servers)
73 })
74
75 it('Should have correct follows', async function () {
76 await checkHasFollowers(servers)
77 })
78
79 it('Should remove follower on server 2', async function () {
80 await removeFollower(servers[1].url, servers[1].accessToken, servers[0])
81
82 await waitJobs(servers)
83 })
84
85 it('Should not not have follows anymore', async function () {
86 await checkNoFollowers(servers)
87 })
88
89 it('Should disable followers on server 2', async function () {
90 const subConfig = {
91 followers: {
92 instance: {
93 enabled: false
94 }
95 }
96 }
97
98 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
99
100 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
101 await waitJobs(servers)
102
103 await checkNoFollowers(servers)
104 })
105
106 it('Should re enable followers on server 2', async function () {
107 const subConfig = {
108 followers: {
109 instance: {
110 enabled: true
111 }
112 }
113 }
114
115 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
116
117 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
118 await waitJobs(servers)
119
120 await checkHasFollowers(servers)
121 })
122
123 after(async function () {
124 killallServers(servers)
125 })
126 })