]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/utils/follows.ts
Fix video full description
[github/Chocobozzz/PeerTube.git] / server / tests / utils / follows.ts
CommitLineData
4610bc5b 1import * as request from 'supertest'
4610bc5b 2import { wait } from './miscs'
afffe988 3import { ServerInfo } from './servers'
4610bc5b
C
4
5function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: 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 })
13 .set('Accept', 'application/json')
14 .expect(200)
15 .expect('Content-Type', /json/)
16}
17
18function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string) {
afffe988 19 const path = '/api/v1/server/following'
4610bc5b
C
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
31async function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
afffe988 32 const path = '/api/v1/server/follow'
4610bc5b 33
afffe988 34 const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
4610bc5b
C
35 const res = await request(follower)
36 .post(path)
37 .set('Accept', 'application/json')
38 .set('Authorization', 'Bearer ' + accessToken)
afffe988 39 .send({ 'hosts': followingHosts })
4610bc5b
C
40 .expect(expectedStatus)
41
42 // Wait request propagation
afffe988 43 await wait(20000)
4610bc5b
C
44
45 return res
46}
47
afffe988
C
48async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
49 await Promise.all([
50 follow(server1.url, [ server2.url ], server1.accessToken),
51 follow(server2.url, [ server1.url ], server2.accessToken)
52 ])
53
54 return true
55}
56
4610bc5b
C
57// ---------------------------------------------------------------------------
58
59export {
60 getFollowersListPaginationAndSort,
61 getFollowingListPaginationAndSort,
afffe988
C
62 follow,
63 doubleFollow
4610bc5b 64}