2017-11-16 10:16:42 -06:00
|
|
|
import * as request from 'supertest'
|
|
|
|
import { wait } from './miscs'
|
2017-11-17 04:35:10 -06:00
|
|
|
import { ServerInfo } from './servers'
|
2017-11-16 10:16:42 -06:00
|
|
|
|
|
|
|
function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) {
|
2017-11-17 04:35:10 -06:00
|
|
|
const path = '/api/v1/server/followers'
|
2017-11-16 10:16:42 -06:00
|
|
|
|
|
|
|
return request(url)
|
|
|
|
.get(path)
|
|
|
|
.query({ start })
|
|
|
|
.query({ count })
|
|
|
|
.query({ sort })
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect(200)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string) {
|
2017-11-17 04:35:10 -06:00
|
|
|
const path = '/api/v1/server/following'
|
2017-11-16 10:16:42 -06:00
|
|
|
|
|
|
|
return request(url)
|
|
|
|
.get(path)
|
|
|
|
.query({ start })
|
|
|
|
.query({ count })
|
|
|
|
.query({ sort })
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect(200)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
|
2017-11-17 08:20:42 -06:00
|
|
|
const path = '/api/v1/server/following'
|
2017-11-16 10:16:42 -06:00
|
|
|
|
2017-11-17 04:35:10 -06:00
|
|
|
const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
|
2017-11-16 10:16:42 -06:00
|
|
|
const res = await request(follower)
|
|
|
|
.post(path)
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.set('Authorization', 'Bearer ' + accessToken)
|
2017-11-17 04:35:10 -06:00
|
|
|
.send({ 'hosts': followingHosts })
|
2017-11-16 10:16:42 -06:00
|
|
|
.expect(expectedStatus)
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2017-11-21 06:43:29 -06:00
|
|
|
async function unfollow (url: string, accessToken: string, id: number, expectedStatus = 204) {
|
|
|
|
const path = '/api/v1/server/following/' + id
|
|
|
|
|
|
|
|
const res = await request(url)
|
|
|
|
.delete(path)
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.set('Authorization', 'Bearer ' + accessToken)
|
|
|
|
.expect(expectedStatus)
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2017-11-17 04:35:10 -06:00
|
|
|
async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
|
|
|
|
await Promise.all([
|
|
|
|
follow(server1.url, [ server2.url ], server1.accessToken),
|
|
|
|
follow(server2.url, [ server1.url ], server2.accessToken)
|
|
|
|
])
|
|
|
|
|
2017-11-17 08:42:12 -06:00
|
|
|
// Wait request propagation
|
|
|
|
await wait(20000)
|
|
|
|
|
2017-11-17 04:35:10 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-11-16 10:16:42 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
getFollowersListPaginationAndSort,
|
|
|
|
getFollowingListPaginationAndSort,
|
2017-11-21 06:43:29 -06:00
|
|
|
unfollow,
|
2017-11-17 04:35:10 -06:00
|
|
|
follow,
|
|
|
|
doubleFollow
|
2017-11-16 10:16:42 -06:00
|
|
|
}
|