diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-27 11:05:32 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-07-27 13:52:13 +0200 |
commit | 073deef8862f462de5f159a57877ef415ebe4c69 (patch) | |
tree | 256d5ff4483ef68b07754f767626a72ac793bd5f /server/tests/api | |
parent | 3267d381f4fdd128b2f948670b2e2ba765145276 (diff) | |
download | PeerTube-073deef8862f462de5f159a57877ef415ebe4c69.tar.gz PeerTube-073deef8862f462de5f159a57877ef415ebe4c69.tar.zst PeerTube-073deef8862f462de5f159a57877ef415ebe4c69.zip |
Handle rejected follows in client
Also add quick filters so it's easier to find pending follows
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/server/follows-moderation.ts | 111 |
1 files changed, 55 insertions, 56 deletions
diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index a0e94c10e..a34eb9bf0 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts | |||
@@ -33,42 +33,39 @@ async function checkServer1And2HasFollowers (servers: PeerTubeServer[], state = | |||
33 | } | 33 | } |
34 | 34 | ||
35 | async function checkFollows (options: { | 35 | async function checkFollows (options: { |
36 | follower: { | 36 | follower: PeerTubeServer |
37 | server: PeerTubeServer | 37 | followerState: FollowState | 'deleted' |
38 | state?: FollowState // if not provided, it means it does not exist | 38 | |
39 | } | 39 | following: PeerTubeServer |
40 | following: { | 40 | followingState: FollowState | 'deleted' |
41 | server: PeerTubeServer | ||
42 | state?: FollowState // if not provided, it means it does not exist | ||
43 | } | ||
44 | }) { | 41 | }) { |
45 | const { follower, following } = options | 42 | const { follower, followerState, followingState, following } = options |
46 | 43 | ||
47 | const followerUrl = follower.server.url + '/accounts/peertube' | 44 | const followerUrl = follower.url + '/accounts/peertube' |
48 | const followingUrl = following.server.url + '/accounts/peertube' | 45 | const followingUrl = following.url + '/accounts/peertube' |
49 | const finder = (d: ActorFollow) => d.follower.url === followerUrl && d.following.url === followingUrl | 46 | const finder = (d: ActorFollow) => d.follower.url === followerUrl && d.following.url === followingUrl |
50 | 47 | ||
51 | { | 48 | { |
52 | const { data } = await follower.server.follows.getFollowings() | 49 | const { data } = await follower.follows.getFollowings() |
53 | const follow = data.find(finder) | 50 | const follow = data.find(finder) |
54 | 51 | ||
55 | if (!follower.state) { | 52 | if (followerState === 'deleted') { |
56 | expect(follow).to.not.exist | 53 | expect(follow).to.not.exist |
57 | } else { | 54 | } else { |
58 | expect(follow.state).to.equal(follower.state) | 55 | expect(follow.state).to.equal(followerState) |
59 | expect(follow.follower.url).to.equal(followerUrl) | 56 | expect(follow.follower.url).to.equal(followerUrl) |
60 | expect(follow.following.url).to.equal(followingUrl) | 57 | expect(follow.following.url).to.equal(followingUrl) |
61 | } | 58 | } |
62 | } | 59 | } |
63 | 60 | ||
64 | { | 61 | { |
65 | const { data } = await following.server.follows.getFollowers() | 62 | const { data } = await following.follows.getFollowers() |
66 | const follow = data.find(finder) | 63 | const follow = data.find(finder) |
67 | 64 | ||
68 | if (!following.state) { | 65 | if (followingState === 'deleted') { |
69 | expect(follow).to.not.exist | 66 | expect(follow).to.not.exist |
70 | } else { | 67 | } else { |
71 | expect(follow.state).to.equal(following.state) | 68 | expect(follow.state).to.equal(followingState) |
72 | expect(follow.follower.url).to.equal(followerUrl) | 69 | expect(follow.follower.url).to.equal(followerUrl) |
73 | expect(follow.following.url).to.equal(followingUrl) | 70 | expect(follow.following.url).to.equal(followingUrl) |
74 | } | 71 | } |
@@ -256,14 +253,10 @@ describe('Test follows moderation', function () { | |||
256 | await waitJobs(servers) | 253 | await waitJobs(servers) |
257 | 254 | ||
258 | await checkFollows({ | 255 | await checkFollows({ |
259 | follower: { | 256 | follower: servers[0], |
260 | server: servers[0], | 257 | followerState: 'rejected', |
261 | state: 'rejected' | 258 | following: servers[2], |
262 | }, | 259 | followingState: 'rejected' |
263 | following: { | ||
264 | server: servers[2], | ||
265 | state: 'rejected' | ||
266 | } | ||
267 | }) | 260 | }) |
268 | } | 261 | } |
269 | 262 | ||
@@ -279,13 +272,10 @@ describe('Test follows moderation', function () { | |||
279 | await waitJobs(servers) | 272 | await waitJobs(servers) |
280 | 273 | ||
281 | await checkFollows({ | 274 | await checkFollows({ |
282 | follower: { | 275 | follower: servers[0], |
283 | server: servers[0] | 276 | followerState: 'deleted', |
284 | }, | 277 | following: servers[2], |
285 | following: { | 278 | followingState: 'rejected' |
286 | server: servers[2], | ||
287 | state: 'rejected' | ||
288 | } | ||
289 | }) | 279 | }) |
290 | }) | 280 | }) |
291 | 281 | ||
@@ -297,14 +287,10 @@ describe('Test follows moderation', function () { | |||
297 | await waitJobs(servers) | 287 | await waitJobs(servers) |
298 | 288 | ||
299 | await checkFollows({ | 289 | await checkFollows({ |
300 | follower: { | 290 | follower: servers[0], |
301 | server: servers[0], | 291 | followerState: 'pending', |
302 | state: 'pending' | 292 | following: servers[2], |
303 | }, | 293 | followingState: 'pending' |
304 | following: { | ||
305 | server: servers[2], | ||
306 | state: 'pending' | ||
307 | } | ||
308 | }) | 294 | }) |
309 | }) | 295 | }) |
310 | 296 | ||
@@ -313,14 +299,10 @@ describe('Test follows moderation', function () { | |||
313 | await waitJobs(servers) | 299 | await waitJobs(servers) |
314 | 300 | ||
315 | await checkFollows({ | 301 | await checkFollows({ |
316 | follower: { | 302 | follower: servers[0], |
317 | server: servers[0], | 303 | followerState: 'rejected', |
318 | state: 'rejected' | 304 | following: servers[1], |
319 | }, | 305 | followingState: 'rejected' |
320 | following: { | ||
321 | server: servers[1], | ||
322 | state: 'rejected' | ||
323 | } | ||
324 | }) | 306 | }) |
325 | }) | 307 | }) |
326 | 308 | ||
@@ -329,19 +311,36 @@ describe('Test follows moderation', function () { | |||
329 | await waitJobs(servers) | 311 | await waitJobs(servers) |
330 | 312 | ||
331 | await checkFollows({ | 313 | await checkFollows({ |
332 | follower: { | 314 | follower: servers[0], |
333 | server: servers[0], | 315 | followerState: 'accepted', |
334 | state: 'accepted' | 316 | following: servers[1], |
335 | }, | 317 | followingState: 'accepted' |
336 | following: { | ||
337 | server: servers[1], | ||
338 | state: 'accepted' | ||
339 | } | ||
340 | }) | 318 | }) |
341 | }) | 319 | }) |
342 | 320 | ||
343 | it('Should ignore follow requests of muted servers', async function () { | 321 | it('Should ignore follow requests of muted servers', async function () { |
322 | await servers[1].blocklist.addToServerBlocklist({ server: servers[0].host }) | ||
323 | |||
324 | await commands[0].unfollow({ target: servers[1] }) | ||
344 | 325 | ||
326 | await waitJobs(servers) | ||
327 | |||
328 | await checkFollows({ | ||
329 | follower: servers[0], | ||
330 | followerState: 'deleted', | ||
331 | following: servers[1], | ||
332 | followingState: 'deleted' | ||
333 | }) | ||
334 | |||
335 | await commands[0].follow({ hosts: [ servers[1].host ] }) | ||
336 | await waitJobs(servers) | ||
337 | |||
338 | await checkFollows({ | ||
339 | follower: servers[0], | ||
340 | followerState: 'rejected', | ||
341 | following: servers[1], | ||
342 | followingState: 'deleted' | ||
343 | }) | ||
345 | }) | 344 | }) |
346 | 345 | ||
347 | after(async function () { | 346 | after(async function () { |