]>
Commit | Line | Data |
---|---|---|
0e9c48c2 C |
1 | /* tslint:disable:no-unused-expression */ |
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 C |
26 | { |
27 | const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt') | |
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 | { | |
37 | const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt') | |
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 | { | |
49 | const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 5, 'createdAt') | |
50 | expect(res.body.total).to.equal(0) | |
51 | } | |
52 | ||
53 | { | |
54 | const res = await getFollowersListPaginationAndSort(servers[ 1 ].url, 0, 5, 'createdAt') | |
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 () { | |
84 | await removeFollower(servers[1].url, servers[1].accessToken, servers[0]) | |
85 | ||
86 | await waitJobs(servers) | |
87 | }) | |
88 | ||
89 | it('Should not not have follows anymore', async function () { | |
5b9c965d C |
90 | await checkNoFollowers(servers) |
91 | }) | |
92 | ||
93 | it('Should disable followers on server 2', async function () { | |
94 | const subConfig = { | |
95 | followers: { | |
96 | instance: { | |
14893eb7 C |
97 | enabled: false, |
98 | manualApproval: false | |
5b9c965d C |
99 | } |
100 | } | |
0e9c48c2 C |
101 | } |
102 | ||
5b9c965d C |
103 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) |
104 | ||
105 | await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) | |
106 | await waitJobs(servers) | |
107 | ||
108 | await checkNoFollowers(servers) | |
109 | }) | |
110 | ||
111 | it('Should re enable followers on server 2', async function () { | |
112 | const subConfig = { | |
113 | followers: { | |
114 | instance: { | |
14893eb7 C |
115 | enabled: true, |
116 | manualApproval: false | |
5b9c965d C |
117 | } |
118 | } | |
0e9c48c2 | 119 | } |
5b9c965d C |
120 | |
121 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) | |
122 | ||
123 | await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) | |
124 | await waitJobs(servers) | |
125 | ||
14893eb7 C |
126 | await checkServer1And2HasFollowers(servers) |
127 | }) | |
128 | ||
129 | it('Should manually approve followers', async function () { | |
130 | this.timeout(20000) | |
131 | ||
132 | await removeFollower(servers[1].url, servers[1].accessToken, servers[0]) | |
133 | await waitJobs(servers) | |
134 | ||
135 | const subConfig = { | |
136 | followers: { | |
137 | instance: { | |
138 | enabled: true, | |
139 | manualApproval: true | |
140 | } | |
141 | } | |
142 | } | |
143 | ||
144 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) | |
145 | await updateCustomSubConfig(servers[2].url, servers[2].accessToken, subConfig) | |
146 | ||
147 | await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) | |
148 | await waitJobs(servers) | |
149 | ||
150 | await checkServer1And2HasFollowers(servers, 'pending') | |
151 | }) | |
152 | ||
153 | it('Should accept a follower', async function () { | |
7243f84d | 154 | await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@localhost:' + servers[0].port) |
14893eb7 C |
155 | await waitJobs(servers) |
156 | ||
157 | await checkServer1And2HasFollowers(servers) | |
158 | }) | |
159 | ||
160 | it('Should reject another follower', async function () { | |
161 | this.timeout(20000) | |
162 | ||
163 | await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken) | |
164 | await waitJobs(servers) | |
165 | ||
166 | { | |
167 | const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt') | |
168 | expect(res.body.total).to.equal(2) | |
169 | } | |
170 | ||
171 | { | |
172 | const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt') | |
173 | expect(res.body.total).to.equal(1) | |
174 | } | |
175 | ||
176 | { | |
177 | const res = await getFollowersListPaginationAndSort(servers[2].url, 0, 5, 'createdAt') | |
178 | expect(res.body.total).to.equal(1) | |
179 | } | |
180 | ||
7243f84d | 181 | await rejectFollower(servers[2].url, servers[2].accessToken, 'peertube@localhost:' + servers[0].port) |
14893eb7 C |
182 | await waitJobs(servers) |
183 | ||
184 | await checkServer1And2HasFollowers(servers) | |
185 | ||
186 | { | |
187 | const res = await getFollowersListPaginationAndSort(servers[ 2 ].url, 0, 5, 'createdAt') | |
188 | expect(res.body.total).to.equal(0) | |
189 | } | |
0e9c48c2 C |
190 | }) |
191 | ||
7c3b7976 C |
192 | after(async function () { |
193 | await cleanupTests(servers) | |
0e9c48c2 C |
194 | }) |
195 | }) |