diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-28 13:59:22 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-28 13:59:22 +0100 |
commit | c5d31dba56d669c0df0209761c43c5a6ac7cec4a (patch) | |
tree | fe72b56a1c0e7beb6e092c393a00ddfe93a5d71f /server/tests/utils/follows.ts | |
parent | db799da3d2b2ea465165df78ff71effa653b6309 (diff) | |
download | PeerTube-c5d31dba56d669c0df0209761c43c5a6ac7cec4a.tar.gz PeerTube-c5d31dba56d669c0df0209761c43c5a6ac7cec4a.tar.zst PeerTube-c5d31dba56d669c0df0209761c43c5a6ac7cec4a.zip |
Tests directories refractor
Diffstat (limited to 'server/tests/utils/follows.ts')
-rw-r--r-- | server/tests/utils/follows.ts | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/server/tests/utils/follows.ts b/server/tests/utils/follows.ts deleted file mode 100644 index a9f798bcb..000000000 --- a/server/tests/utils/follows.ts +++ /dev/null | |||
@@ -1,77 +0,0 @@ | |||
1 | import * as request from 'supertest' | ||
2 | import { wait } from './miscs' | ||
3 | import { ServerInfo } from './servers' | ||
4 | |||
5 | function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) { | ||
6 | const path = '/api/v1/server/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/server/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/server/following' | ||
33 | |||
34 | const followingHosts = following.map(f => f.replace(/^http:\/\//, '')) | ||
35 | const res = await request(follower) | ||
36 | .post(path) | ||
37 | .set('Accept', 'application/json') | ||
38 | .set('Authorization', 'Bearer ' + accessToken) | ||
39 | .send({ 'hosts': followingHosts }) | ||
40 | .expect(expectedStatus) | ||
41 | |||
42 | return res | ||
43 | } | ||
44 | |||
45 | async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = 204) { | ||
46 | const path = '/api/v1/server/following/' + target.host | ||
47 | |||
48 | const res = await request(url) | ||
49 | .delete(path) | ||
50 | .set('Accept', 'application/json') | ||
51 | .set('Authorization', 'Bearer ' + accessToken) | ||
52 | .expect(expectedStatus) | ||
53 | |||
54 | return res | ||
55 | } | ||
56 | |||
57 | async function doubleFollow (server1: ServerInfo, server2: ServerInfo) { | ||
58 | await Promise.all([ | ||
59 | follow(server1.url, [ server2.url ], server1.accessToken), | ||
60 | follow(server2.url, [ server1.url ], server2.accessToken) | ||
61 | ]) | ||
62 | |||
63 | // Wait request propagation | ||
64 | await wait(10000) | ||
65 | |||
66 | return true | ||
67 | } | ||
68 | |||
69 | // --------------------------------------------------------------------------- | ||
70 | |||
71 | export { | ||
72 | getFollowersListPaginationAndSort, | ||
73 | getFollowingListPaginationAndSort, | ||
74 | unfollow, | ||
75 | follow, | ||
76 | doubleFollow | ||
77 | } | ||