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