1 import * as request from 'supertest'
2 import { wait } from '../miscs/miscs'
3 import { ServerInfo } from './servers'
4 import { waitJobs } from './jobs'
6 function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) {
7 const path = '/api/v1/server/followers'
14 .set('Accept', 'application/json')
16 .expect('Content-Type', /json/)
19 function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string) {
20 const path = '/api/v1/server/following'
27 .set('Accept', 'application/json')
29 .expect('Content-Type', /json/)
32 async function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
33 const path = '/api/v1/server/following'
35 const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
36 const res = await request(follower)
38 .set('Accept', 'application/json')
39 .set('Authorization', 'Bearer ' + accessToken)
40 .send({ 'hosts': followingHosts })
41 .expect(expectedStatus)
46 async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = 204) {
47 const path = '/api/v1/server/following/' + target.host
49 const res = await request(url)
51 .set('Accept', 'application/json')
52 .set('Authorization', 'Bearer ' + accessToken)
53 .expect(expectedStatus)
58 async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
60 follow(server1.url, [ server2.url ], server1.accessToken),
61 follow(server2.url, [ server1.url ], server2.accessToken)
64 // Wait request propagation
65 await waitJobs([ server1, server2 ])
70 // ---------------------------------------------------------------------------
73 getFollowersListPaginationAndSort,
74 getFollowingListPaginationAndSort,