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