diff options
Diffstat (limited to 'server/tests/utils/follows.ts')
-rw-r--r-- | server/tests/utils/follows.ts | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/server/tests/utils/follows.ts b/server/tests/utils/follows.ts new file mode 100644 index 000000000..9ad1ca7f4 --- /dev/null +++ b/server/tests/utils/follows.ts | |||
@@ -0,0 +1,53 @@ | |||
1 | import * as request from 'supertest' | ||
2 | |||
3 | import { wait } from './miscs' | ||
4 | |||
5 | function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) { | ||
6 | const path = '/api/v1/servers/followers' | ||
7 | |||
8 | return request(url) | ||
9 | .get(path) | ||
10 | .query({ start }) | ||
11 | .query({ count }) | ||
12 | .query({ sort }) | ||
13 | .set('Accept', 'application/json') | ||
14 | .expect(200) | ||
15 | .expect('Content-Type', /json/) | ||
16 | } | ||
17 | |||
18 | function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string) { | ||
19 | const path = '/api/v1/servers/following' | ||
20 | |||
21 | return request(url) | ||
22 | .get(path) | ||
23 | .query({ start }) | ||
24 | .query({ count }) | ||
25 | .query({ sort }) | ||
26 | .set('Accept', 'application/json') | ||
27 | .expect(200) | ||
28 | .expect('Content-Type', /json/) | ||
29 | } | ||
30 | |||
31 | async function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) { | ||
32 | const path = '/api/v1/servers/follow' | ||
33 | |||
34 | const res = await request(follower) | ||
35 | .post(path) | ||
36 | .set('Accept', 'application/json') | ||
37 | .set('Authorization', 'Bearer ' + accessToken) | ||
38 | .send({ 'hosts': following }) | ||
39 | .expect(expectedStatus) | ||
40 | |||
41 | // Wait request propagation | ||
42 | await wait(1000) | ||
43 | |||
44 | return res | ||
45 | } | ||
46 | |||
47 | // --------------------------------------------------------------------------- | ||
48 | |||
49 | export { | ||
50 | getFollowersListPaginationAndSort, | ||
51 | getFollowingListPaginationAndSort, | ||
52 | follow | ||
53 | } | ||