]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/utils/server/follows.ts
Underline links in feed popover when hovering
[github/Chocobozzz/PeerTube.git] / server / tests / utils / server / follows.ts
1 import * as request from 'supertest'
2 import { wait } from '../miscs/miscs'
3 import { ServerInfo } from './servers'
4 import { waitJobs } from './jobs'
5
6 function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) {
7 const path = '/api/v1/server/followers'
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) {
20 const path = '/api/v1/server/following'
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) {
33 const path = '/api/v1/server/following'
34
35 const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
36 const res = await request(follower)
37 .post(path)
38 .set('Accept', 'application/json')
39 .set('Authorization', 'Bearer ' + accessToken)
40 .send({ 'hosts': followingHosts })
41 .expect(expectedStatus)
42
43 return res
44 }
45
46 async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = 204) {
47 const path = '/api/v1/server/following/' + target.host
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
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
64 // Wait request propagation
65 await waitJobs([ server1, server2 ])
66
67 return true
68 }
69
70 // ---------------------------------------------------------------------------
71
72 export {
73 getFollowersListPaginationAndSort,
74 getFollowingListPaginationAndSort,
75 unfollow,
76 follow,
77 doubleFollow
78 }