1 import * as request from 'supertest'
2 import { ServerInfo } from './servers'
3 import { waitJobs } from './jobs'
4 import { makePostBodyRequest } from '../requests/requests'
5 import { ActivityPubActorType, FollowState } from '@shared/models'
7 function getFollowersListPaginationAndSort (options: {
13 actorType?: ActivityPubActorType,
16 const { url, start, count, sort, search, state, actorType } = options
17 const path = '/api/v1/server/followers'
31 .set('Accept', 'application/json')
33 .expect('Content-Type', /json/)
36 function acceptFollower (url: string, token: string, follower: string, statusCodeExpected = 204) {
37 const path = '/api/v1/server/followers/' + follower + '/accept'
39 return makePostBodyRequest({
47 function rejectFollower (url: string, token: string, follower: string, statusCodeExpected = 204) {
48 const path = '/api/v1/server/followers/' + follower + '/reject'
50 return makePostBodyRequest({
58 function getFollowingListPaginationAndSort (options: {
64 actorType?: ActivityPubActorType,
67 const { url, start, count, sort, search, state, actorType } = options
68 const path = '/api/v1/server/following'
82 .set('Accept', 'application/json')
84 .expect('Content-Type', /json/)
87 function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
88 const path = '/api/v1/server/following'
90 const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
91 return request(follower)
93 .set('Accept', 'application/json')
94 .set('Authorization', 'Bearer ' + accessToken)
95 .send({ 'hosts': followingHosts })
96 .expect(expectedStatus)
99 async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = 204) {
100 const path = '/api/v1/server/following/' + target.host
104 .set('Accept', 'application/json')
105 .set('Authorization', 'Bearer ' + accessToken)
106 .expect(expectedStatus)
109 function removeFollower (url: string, accessToken: string, follower: ServerInfo, expectedStatus = 204) {
110 const path = '/api/v1/server/followers/peertube@' + follower.host
114 .set('Accept', 'application/json')
115 .set('Authorization', 'Bearer ' + accessToken)
116 .expect(expectedStatus)
119 async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
121 follow(server1.url, [ server2.url ], server1.accessToken),
122 follow(server2.url, [ server1.url ], server2.accessToken)
125 // Wait request propagation
126 await waitJobs([ server1, server2 ])
131 // ---------------------------------------------------------------------------
134 getFollowersListPaginationAndSort,
135 getFollowingListPaginationAndSort,