]>
Commit | Line | Data |
---|---|---|
4610bc5b | 1 | import * as request from 'supertest' |
c5d31dba | 2 | import { wait } from '../miscs/miscs' |
afffe988 | 3 | import { ServerInfo } from './servers' |
3cd0734f | 4 | import { waitJobs } from './jobs' |
4610bc5b C |
5 | |
6 | function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) { | |
afffe988 | 7 | const path = '/api/v1/server/followers' |
4610bc5b C |
8 | |
9 | return request(url) | |
10 | .get(path) | |
11 | .query({ start }) | |
12 | .query({ count }) | |
13 | .query({ sort }) | |
14 | .set('Accept', 'application/json') | |
15 | .expect(200) | |
16 | .expect('Content-Type', /json/) | |
17 | } | |
18 | ||
19 | function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string) { | |
afffe988 | 20 | const path = '/api/v1/server/following' |
4610bc5b C |
21 | |
22 | return request(url) | |
23 | .get(path) | |
24 | .query({ start }) | |
25 | .query({ count }) | |
26 | .query({ sort }) | |
27 | .set('Accept', 'application/json') | |
28 | .expect(200) | |
29 | .expect('Content-Type', /json/) | |
30 | } | |
31 | ||
32 | async function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) { | |
9a27cdc2 | 33 | const path = '/api/v1/server/following' |
4610bc5b | 34 | |
afffe988 | 35 | const followingHosts = following.map(f => f.replace(/^http:\/\//, '')) |
4610bc5b C |
36 | const res = await request(follower) |
37 | .post(path) | |
38 | .set('Accept', 'application/json') | |
39 | .set('Authorization', 'Bearer ' + accessToken) | |
afffe988 | 40 | .send({ 'hosts': followingHosts }) |
4610bc5b C |
41 | .expect(expectedStatus) |
42 | ||
4610bc5b C |
43 | return res |
44 | } | |
45 | ||
50d6de9c C |
46 | async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = 204) { |
47 | const path = '/api/v1/server/following/' + target.host | |
0f91ae62 C |
48 | |
49 | const res = await request(url) | |
50 | .delete(path) | |
51 | .set('Accept', 'application/json') | |
52 | .set('Authorization', 'Bearer ' + accessToken) | |
53 | .expect(expectedStatus) | |
54 | ||
55 | return res | |
56 | } | |
57 | ||
afffe988 C |
58 | async function doubleFollow (server1: ServerInfo, server2: ServerInfo) { |
59 | await Promise.all([ | |
60 | follow(server1.url, [ server2.url ], server1.accessToken), | |
61 | follow(server2.url, [ server1.url ], server2.accessToken) | |
62 | ]) | |
63 | ||
572f8d3d | 64 | // Wait request propagation |
3cd0734f | 65 | await waitJobs([ server1, server2 ]) |
572f8d3d | 66 | |
afffe988 C |
67 | return true |
68 | } | |
69 | ||
4610bc5b C |
70 | // --------------------------------------------------------------------------- |
71 | ||
72 | export { | |
73 | getFollowersListPaginationAndSort, | |
74 | getFollowingListPaginationAndSort, | |
0f91ae62 | 75 | unfollow, |
afffe988 C |
76 | follow, |
77 | doubleFollow | |
4610bc5b | 78 | } |