]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { | |
6 | cleanupTests, | |
7 | flushAndRunMultipleServers, | |
8 | FollowsCommand, | |
9 | ServerInfo, | |
10 | setAccessTokensToServers, | |
11 | updateCustomSubConfig, | |
12 | waitJobs | |
13 | } from '@shared/extra-utils' | |
14 | ||
15 | const expect = chai.expect | |
16 | ||
17 | async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'accepted') { | |
18 | const fns = [ | |
19 | servers[0].followsCommand.getFollowings.bind(servers[0].followsCommand), | |
20 | servers[1].followsCommand.getFollowers.bind(servers[1].followsCommand) | |
21 | ] | |
22 | ||
23 | for (const fn of fns) { | |
24 | const body = await fn({ start: 0, count: 5, sort: 'createdAt' }) | |
25 | expect(body.total).to.equal(1) | |
26 | ||
27 | const follow = body.data[0] | |
28 | expect(follow.state).to.equal(state) | |
29 | expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + '/accounts/peertube') | |
30 | expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube') | |
31 | } | |
32 | } | |
33 | ||
34 | async function checkNoFollowers (servers: ServerInfo[]) { | |
35 | const fns = [ | |
36 | servers[0].followsCommand.getFollowings.bind(servers[0].followsCommand), | |
37 | servers[1].followsCommand.getFollowers.bind(servers[1].followsCommand) | |
38 | ] | |
39 | ||
40 | for (const fn of fns) { | |
41 | const body = await fn({ start: 0, count: 5, sort: 'createdAt' }) | |
42 | expect(body.total).to.equal(0) | |
43 | } | |
44 | } | |
45 | ||
46 | describe('Test follows moderation', function () { | |
47 | let servers: ServerInfo[] = [] | |
48 | let commands: FollowsCommand[] | |
49 | ||
50 | before(async function () { | |
51 | this.timeout(30000) | |
52 | ||
53 | servers = await flushAndRunMultipleServers(3) | |
54 | ||
55 | // Get the access tokens | |
56 | await setAccessTokensToServers(servers) | |
57 | ||
58 | commands = servers.map(s => s.followsCommand) | |
59 | }) | |
60 | ||
61 | it('Should have server 1 following server 2', async function () { | |
62 | this.timeout(30000) | |
63 | ||
64 | await commands[0].follow({ targets: [ servers[1].url ] }) | |
65 | ||
66 | await waitJobs(servers) | |
67 | }) | |
68 | ||
69 | it('Should have correct follows', async function () { | |
70 | await checkServer1And2HasFollowers(servers) | |
71 | }) | |
72 | ||
73 | it('Should remove follower on server 2', async function () { | |
74 | this.timeout(10000) | |
75 | ||
76 | await commands[1].removeFollower({ follower: servers[0] }) | |
77 | ||
78 | await waitJobs(servers) | |
79 | }) | |
80 | ||
81 | it('Should not not have follows anymore', async function () { | |
82 | await checkNoFollowers(servers) | |
83 | }) | |
84 | ||
85 | it('Should disable followers on server 2', async function () { | |
86 | this.timeout(10000) | |
87 | ||
88 | const subConfig = { | |
89 | followers: { | |
90 | instance: { | |
91 | enabled: false, | |
92 | manualApproval: false | |
93 | } | |
94 | } | |
95 | } | |
96 | ||
97 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) | |
98 | ||
99 | await commands[0].follow({ targets: [ servers[1].url ] }) | |
100 | await waitJobs(servers) | |
101 | ||
102 | await checkNoFollowers(servers) | |
103 | }) | |
104 | ||
105 | it('Should re enable followers on server 2', async function () { | |
106 | this.timeout(10000) | |
107 | ||
108 | const subConfig = { | |
109 | followers: { | |
110 | instance: { | |
111 | enabled: true, | |
112 | manualApproval: false | |
113 | } | |
114 | } | |
115 | } | |
116 | ||
117 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) | |
118 | ||
119 | await commands[0].follow({ targets: [ servers[1].url ] }) | |
120 | await waitJobs(servers) | |
121 | ||
122 | await checkServer1And2HasFollowers(servers) | |
123 | }) | |
124 | ||
125 | it('Should manually approve followers', async function () { | |
126 | this.timeout(20000) | |
127 | ||
128 | await commands[1].removeFollower({ follower: servers[0] }) | |
129 | await waitJobs(servers) | |
130 | ||
131 | const subConfig = { | |
132 | followers: { | |
133 | instance: { | |
134 | enabled: true, | |
135 | manualApproval: true | |
136 | } | |
137 | } | |
138 | } | |
139 | ||
140 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) | |
141 | await updateCustomSubConfig(servers[2].url, servers[2].accessToken, subConfig) | |
142 | ||
143 | await commands[0].follow({ targets: [ servers[1].url ] }) | |
144 | await waitJobs(servers) | |
145 | ||
146 | await checkServer1And2HasFollowers(servers, 'pending') | |
147 | }) | |
148 | ||
149 | it('Should accept a follower', async function () { | |
150 | this.timeout(10000) | |
151 | ||
152 | await commands[1].acceptFollower({ follower: 'peertube@localhost:' + servers[0].port }) | |
153 | await waitJobs(servers) | |
154 | ||
155 | await checkServer1And2HasFollowers(servers) | |
156 | }) | |
157 | ||
158 | it('Should reject another follower', async function () { | |
159 | this.timeout(20000) | |
160 | ||
161 | await commands[0].follow({ targets: [ servers[2].url ] }) | |
162 | await waitJobs(servers) | |
163 | ||
164 | { | |
165 | const body = await commands[0].getFollowings({ start: 0, count: 5, sort: 'createdAt' }) | |
166 | expect(body.total).to.equal(2) | |
167 | } | |
168 | ||
169 | { | |
170 | const body = await commands[1].getFollowers({ start: 0, count: 5, sort: 'createdAt' }) | |
171 | expect(body.total).to.equal(1) | |
172 | } | |
173 | ||
174 | { | |
175 | const body = await commands[2].getFollowers({ start: 0, count: 5, sort: 'createdAt' }) | |
176 | expect(body.total).to.equal(1) | |
177 | } | |
178 | ||
179 | await commands[2].rejectFollower({ follower: 'peertube@localhost:' + servers[0].port }) | |
180 | await waitJobs(servers) | |
181 | ||
182 | await checkServer1And2HasFollowers(servers) | |
183 | ||
184 | { | |
185 | const body = await commands[2].getFollowers({ start: 0, count: 5, sort: 'createdAt' }) | |
186 | expect(body.total).to.equal(0) | |
187 | } | |
188 | }) | |
189 | ||
190 | after(async function () { | |
191 | await cleanupTests(servers) | |
192 | }) | |
193 | }) |