1 import * as request from 'supertest'
2 import { ServerInfo } from './servers'
3 import { waitJobs } from './jobs'
4 import { makePostBodyRequest } from '../requests/requests'
5 import { FollowState } from '@shared/models'
7 function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string, search?: string, state?: FollowState) {
8 const path = '/api/v1/server/followers'
21 .set('Accept', 'application/json')
23 .expect('Content-Type', /json/)
26 function acceptFollower (url: string, token: string, follower: string, statusCodeExpected = 204) {
27 const path = '/api/v1/server/followers/' + follower + '/accept'
29 return makePostBodyRequest({
37 function rejectFollower (url: string, token: string, follower: string, statusCodeExpected = 204) {
38 const path = '/api/v1/server/followers/' + follower + '/reject'
40 return makePostBodyRequest({
48 function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string, search?: string, state?: FollowState) {
49 const path = '/api/v1/server/following'
62 .set('Accept', 'application/json')
64 .expect('Content-Type', /json/)
67 function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
68 const path = '/api/v1/server/following'
70 const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
71 return request(follower)
73 .set('Accept', 'application/json')
74 .set('Authorization', 'Bearer ' + accessToken)
75 .send({ 'hosts': followingHosts })
76 .expect(expectedStatus)
79 async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = 204) {
80 const path = '/api/v1/server/following/' + target.host
84 .set('Accept', 'application/json')
85 .set('Authorization', 'Bearer ' + accessToken)
86 .expect(expectedStatus)
89 function removeFollower (url: string, accessToken: string, follower: ServerInfo, expectedStatus = 204) {
90 const path = '/api/v1/server/followers/peertube@' + follower.host
94 .set('Accept', 'application/json')
95 .set('Authorization', 'Bearer ' + accessToken)
96 .expect(expectedStatus)
99 async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
101 follow(server1.url, [ server2.url ], server1.accessToken),
102 follow(server2.url, [ server1.url ], server2.accessToken)
105 // Wait request propagation
106 await waitJobs([ server1, server2 ])
111 // ---------------------------------------------------------------------------
114 getFollowersListPaginationAndSort,
115 getFollowingListPaginationAndSort,