1 import * as request from 'supertest'
2 import { wait } from '../miscs/miscs'
3 import { ServerInfo } from './servers'
5 function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) {
6 const path = '/api/v1/server/followers'
13 .set('Accept', 'application/json')
15 .expect('Content-Type', /json/)
18 function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string) {
19 const path = '/api/v1/server/following'
26 .set('Accept', 'application/json')
28 .expect('Content-Type', /json/)
31 async function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
32 const path = '/api/v1/server/following'
34 const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
35 const res = await request(follower)
37 .set('Accept', 'application/json')
38 .set('Authorization', 'Bearer ' + accessToken)
39 .send({ 'hosts': followingHosts })
40 .expect(expectedStatus)
45 async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = 204) {
46 const path = '/api/v1/server/following/' + target.host
48 const res = await request(url)
50 .set('Accept', 'application/json')
51 .set('Authorization', 'Bearer ' + accessToken)
52 .expect(expectedStatus)
57 async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
59 follow(server1.url, [ server2.url ], server1.accessToken),
60 follow(server2.url, [ server1.url ], server2.accessToken)
63 // Wait request propagation
69 // ---------------------------------------------------------------------------
72 getFollowersListPaginationAndSort,
73 getFollowingListPaginationAndSort,