1 import * as request from 'supertest'
2 import { ServerInfo } from './servers'
3 import { waitJobs } from './jobs'
4 import { makePostBodyRequest } from '../requests/requests'
6 function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string, search?: string) {
7 const path = '/api/v1/server/followers'
19 .set('Accept', 'application/json')
21 .expect('Content-Type', /json/)
24 function acceptFollower (url: string, token: string, follower: string, statusCodeExpected = 204) {
25 const path = '/api/v1/server/followers/' + follower + '/accept'
27 return makePostBodyRequest({
35 function rejectFollower (url: string, token: string, follower: string, statusCodeExpected = 204) {
36 const path = '/api/v1/server/followers/' + follower + '/reject'
38 return makePostBodyRequest({
46 function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string, search?: string) {
47 const path = '/api/v1/server/following'
59 .set('Accept', 'application/json')
61 .expect('Content-Type', /json/)
64 function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
65 const path = '/api/v1/server/following'
67 const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
68 return request(follower)
70 .set('Accept', 'application/json')
71 .set('Authorization', 'Bearer ' + accessToken)
72 .send({ 'hosts': followingHosts })
73 .expect(expectedStatus)
76 async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = 204) {
77 const path = '/api/v1/server/following/' + target.host
81 .set('Accept', 'application/json')
82 .set('Authorization', 'Bearer ' + accessToken)
83 .expect(expectedStatus)
86 function removeFollower (url: string, accessToken: string, follower: ServerInfo, expectedStatus = 204) {
87 const path = '/api/v1/server/followers/peertube@' + follower.host
91 .set('Accept', 'application/json')
92 .set('Authorization', 'Bearer ' + accessToken)
93 .expect(expectedStatus)
96 async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
98 follow(server1.url, [ server2.url ], server1.accessToken),
99 follow(server2.url, [ server1.url ], server2.accessToken)
102 // Wait request propagation
103 await waitJobs([ server1, server2 ])
108 // ---------------------------------------------------------------------------
111 getFollowersListPaginationAndSort,
112 getFollowingListPaginationAndSort,