1
0
Fork 0

Introduce follows command

This commit is contained in:
Chocobozzz 2021-07-07 09:16:40 +02:00
parent 883a901908
commit c3d29f694b
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
20 changed files with 367 additions and 410 deletions

View File

@ -15,7 +15,6 @@ import {
doubleFollow,
findCommentId,
flushAndRunMultipleServers,
follow,
getAccountBlocklistByAccount,
getAccountBlocklistByServer,
getServerBlocklistByAccount,
@ -31,7 +30,6 @@ import {
removeServerFromServerBlocklist,
ServerInfo,
setAccessTokensToServers,
unfollow,
uploadVideo,
userLogin,
waitJobs
@ -742,9 +740,9 @@ describe('Test blocklist', function () {
{
const now = new Date()
await unfollow(servers[1].url, servers[1].accessToken, servers[0])
await servers[1].followsCommand.unfollow({ target: servers[0] })
await waitJobs(servers)
await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken)
await servers[1].followsCommand.follow({ targets: [ servers[0].host ] })
await waitJobs(servers)
@ -807,9 +805,9 @@ describe('Test blocklist', function () {
{
const now = new Date()
await unfollow(servers[1].url, servers[1].accessToken, servers[0])
await servers[1].followsCommand.unfollow({ target: servers[0] })
await waitJobs(servers)
await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken)
await servers[1].followsCommand.follow({ targets: [ servers[0].host ] })
await waitJobs(servers)

View File

@ -21,7 +21,6 @@ import {
checkVideoIsPublished,
cleanupTests,
createUser,
follow,
generateUserAccessToken,
getAccount,
getCustomConfig,
@ -35,7 +34,6 @@ import {
removeUserSubscription,
removeVideoFromBlacklist,
ServerInfo,
unfollow,
updateCustomConfig,
updateCustomSubConfig,
uploadVideo,
@ -386,7 +384,7 @@ describe('Test moderation notifications', function () {
it('Should send a notification only to admin when there is a new instance follower', async function () {
this.timeout(20000)
await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
await servers[2].followsCommand.follow({ targets: [ servers[0].url ] })
await waitJobs(servers)
@ -399,7 +397,7 @@ describe('Test moderation notifications', function () {
it('Should send a notification on auto follow back', async function () {
this.timeout(40000)
await unfollow(servers[2].url, servers[2].accessToken, servers[0])
await servers[2].followsCommand.unfollow({ target: servers[0] })
await waitJobs(servers)
const config = {
@ -411,7 +409,7 @@ describe('Test moderation notifications', function () {
}
await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
await servers[2].followsCommand.follow({ targets: [ servers[0].url ] })
await waitJobs(servers)
@ -424,13 +422,13 @@ describe('Test moderation notifications', function () {
config.followings.instance.autoFollowBack.enabled = false
await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
await unfollow(servers[0].url, servers[0].accessToken, servers[2])
await unfollow(servers[2].url, servers[2].accessToken, servers[0])
await servers[0].followsCommand.unfollow({ target: servers[2] })
await servers[2].followsCommand.unfollow({ target: servers[0] })
})
it('Should send a notification on auto instances index follow', async function () {
this.timeout(30000)
await unfollow(servers[0].url, servers[0].accessToken, servers[1])
await servers[0].followsCommand.unfollow({ target: servers[1] })
await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
@ -443,7 +441,7 @@ describe('Test moderation notifications', function () {
config.followings.instance.autoFollowIndex.enabled = false
await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
await unfollow(servers[0].url, servers[0].accessToken, servers[1])
await servers[0].followsCommand.unfollow({ target: servers[1] })
})
})

View File

@ -7,7 +7,6 @@ import { VideoPrivacy } from '@shared/models'
import {
cleanupTests,
flushAndRunServer,
follow,
killallServers,
reRunServer,
ServerInfo,
@ -98,7 +97,7 @@ describe('Test redundancy constraints', function () {
await waitJobs(servers)
// Server 1 and server 2 follow each other
await follow(remoteServer.url, [ localServer.url ], remoteServer.accessToken)
await remoteServer.followsCommand.follow({ targets: [ localServer.url ] })
await waitJobs(servers)
await updateRedundancy(remoteServer.url, remoteServer.accessToken, localServer.host, true)
@ -184,7 +183,7 @@ describe('Test redundancy constraints', function () {
it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () {
this.timeout(120000)
await follow(localServer.url, [ remoteServer.url ], localServer.accessToken)
await localServer.followsCommand.follow({ targets: [ remoteServer.url ] })
await waitJobs(servers)
await uploadWrapper('video 4 server 2')

View File

@ -12,7 +12,6 @@ import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
getFollowingListPaginationAndSort,
getVideo,
getVideoWithToken,
immutableAssign,
@ -23,7 +22,6 @@ import {
root,
ServerInfo,
setAccessTokensToServers,
unfollow,
updateVideo,
uploadVideo,
viewVideo,
@ -38,7 +36,6 @@ import {
updateRedundancy
} from '../../../../shared/extra-utils/server/redundancy'
import { getStats } from '../../../../shared/extra-utils/server/stats'
import { ActorFollow } from '../../../../shared/models/actors'
import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy'
import { ServerStats } from '../../../../shared/models/server/server-stats.model'
import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
@ -272,13 +269,19 @@ async function checkStatsWithoutRedundancy (strategy: VideoRedundancyStrategyWit
expect(stat.totalVideos).to.equal(0)
}
async function findServerFollows () {
const body = await servers[0].followsCommand.getFollowings({ start: 0, count: 5, sort: '-createdAt' })
const follows = body.data
const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`)
const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`)
return { server2, server3 }
}
async function enableRedundancyOnServer1 () {
await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true)
const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: '-createdAt' })
const follows: ActorFollow[] = res.body.data
const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`)
const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`)
const { server2, server3 } = await findServerFollows()
expect(server3).to.not.be.undefined
expect(server3.following.hostRedundancyAllowed).to.be.false
@ -290,10 +293,7 @@ async function enableRedundancyOnServer1 () {
async function disableRedundancyOnServer1 () {
await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, false)
const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: '-createdAt' })
const follows: ActorFollow[] = res.body.data
const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`)
const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`)
const { server2, server3 } = await findServerFollows()
expect(server3).to.not.be.undefined
expect(server3.following.hostRedundancyAllowed).to.be.false
@ -388,7 +388,7 @@ describe('Test videos redundancy', function () {
it('Should unfollow on server 1 and remove duplicated videos', async function () {
this.timeout(80000)
await unfollow(servers[0].url, servers[0].accessToken, servers[1])
await servers[0].followsCommand.unfollow({ target: servers[1] })
await waitJobs(servers)
await wait(5000)

View File

@ -3,64 +3,46 @@
import 'mocha'
import * as chai from 'chai'
import {
acceptFollower,
cleanupTests,
flushAndRunMultipleServers,
MockInstancesIndex,
ServerInfo,
setAccessTokensToServers,
unfollow,
updateCustomSubConfig,
wait
} from '../../../../shared/extra-utils/index'
import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort } from '../../../../shared/extra-utils/server/follows'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { ActorFollow } from '../../../../shared/models/actors'
wait,
waitJobs
} from '@shared/extra-utils'
const expect = chai.expect
async function checkFollow (follower: ServerInfo, following: ServerInfo, exists: boolean) {
{
const res = await getFollowersListPaginationAndSort({ url: following.url, start: 0, count: 5, sort: '-createdAt' })
const follows = res.body.data as ActorFollow[]
const body = await following.followsCommand.getFollowers({ start: 0, count: 5, sort: '-createdAt' })
const follow = body.data.find(f => f.follower.host === follower.host && f.state === 'accepted')
const follow = follows.find(f => {
return f.follower.host === follower.host && f.state === 'accepted'
})
if (exists === true) {
expect(follow).to.exist
} else {
expect(follow).to.be.undefined
}
if (exists === true) expect(follow).to.exist
else expect(follow).to.be.undefined
}
{
const res = await getFollowingListPaginationAndSort({ url: follower.url, start: 0, count: 5, sort: '-createdAt' })
const follows = res.body.data as ActorFollow[]
const body = await follower.followsCommand.getFollowings({ start: 0, count: 5, sort: '-createdAt' })
const follow = body.data.find(f => f.following.host === following.host && f.state === 'accepted')
const follow = follows.find(f => {
return f.following.host === following.host && f.state === 'accepted'
})
if (exists === true) {
expect(follow).to.exist
} else {
expect(follow).to.be.undefined
}
if (exists === true) expect(follow).to.exist
else expect(follow).to.be.undefined
}
}
async function server1Follows2 (servers: ServerInfo[]) {
await follow(servers[0].url, [ servers[1].host ], servers[0].accessToken)
await servers[0].followsCommand.follow({ targets: [ servers[1].host ] })
await waitJobs(servers)
}
async function resetFollows (servers: ServerInfo[]) {
try {
await unfollow(servers[0].url, servers[0].accessToken, servers[1])
await unfollow(servers[1].url, servers[1].accessToken, servers[0])
await servers[0].followsCommand.unfollow({ target: servers[1] })
await servers[1].followsCommand.unfollow({ target: servers[0] })
} catch { /* empty */
}
@ -137,7 +119,7 @@ describe('Test auto follows', function () {
await checkFollow(servers[0], servers[1], false)
await checkFollow(servers[1], servers[0], false)
await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@' + servers[0].host)
await servers[1].followsCommand.acceptFollower({ follower: 'peertube@' + servers[0].host })
await waitJobs(servers)
await checkFollow(servers[0], servers[1], true)

View File

@ -1,9 +1,12 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import * as chai from 'chai'
import 'mocha'
import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
import {
cleanupTests,
createUser,
doubleFollow,
flushAndRunMultipleServers,
getAccountVideos,
@ -12,13 +15,9 @@ import {
getVideoWithToken,
ServerInfo,
setAccessTokensToServers,
uploadVideo
uploadVideo,
userLogin
} from '../../../../shared/extra-utils'
import { unfollow } from '../../../../shared/extra-utils/server/follows'
import { userLogin } from '../../../../shared/extra-utils/users/login'
import { createUser } from '../../../../shared/extra-utils/users/users'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
const expect = chai.expect
@ -144,7 +143,7 @@ describe('Test follow constraints', function () {
before(async function () {
this.timeout(30000)
await unfollow(servers[0].url, servers[0].accessToken, servers[1])
await servers[0].followsCommand.unfollow({ target: servers[1] })
})
describe('With an unlogged user', function () {

View File

@ -1,43 +1,30 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import * as chai from 'chai'
import 'mocha'
import * as chai from 'chai'
import {
acceptFollower,
cleanupTests,
flushAndRunMultipleServers,
FollowsCommand,
ServerInfo,
setAccessTokensToServers,
updateCustomSubConfig
} from '../../../../shared/extra-utils/index'
import {
follow,
getFollowersListPaginationAndSort,
getFollowingListPaginationAndSort,
rejectFollower,
removeFollower
} from '../../../../shared/extra-utils/server/follows'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { ActorFollow } from '../../../../shared/models/actors'
updateCustomSubConfig,
waitJobs
} from '@shared/extra-utils'
const expect = chai.expect
async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'accepted') {
{
const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' })
expect(res.body.total).to.equal(1)
const fns = [
servers[0].followsCommand.getFollowings.bind(servers[0].followsCommand),
servers[1].followsCommand.getFollowers.bind(servers[1].followsCommand)
]
const follow = res.body.data[0] as ActorFollow
expect(follow.state).to.equal(state)
expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + '/accounts/peertube')
expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube')
}
for (const fn of fns) {
const body = await fn({ start: 0, count: 5, sort: 'createdAt' })
expect(body.total).to.equal(1)
{
const res = await getFollowersListPaginationAndSort({ url: servers[1].url, start: 0, count: 5, sort: 'createdAt' })
expect(res.body.total).to.equal(1)
const follow = res.body.data[0] as ActorFollow
const follow = body.data[0]
expect(follow.state).to.equal(state)
expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + '/accounts/peertube')
expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube')
@ -45,19 +32,20 @@ async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'acc
}
async function checkNoFollowers (servers: ServerInfo[]) {
{
const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' })
expect(res.body.total).to.equal(0)
}
const fns = [
servers[0].followsCommand.getFollowings.bind(servers[0].followsCommand),
servers[1].followsCommand.getFollowers.bind(servers[1].followsCommand)
]
{
const res = await getFollowersListPaginationAndSort({ url: servers[1].url, start: 0, count: 5, sort: 'createdAt' })
expect(res.body.total).to.equal(0)
for (const fn of fns) {
const body = await fn({ start: 0, count: 5, sort: 'createdAt' })
expect(body.total).to.equal(0)
}
}
describe('Test follows moderation', function () {
let servers: ServerInfo[] = []
let commands: FollowsCommand[]
before(async function () {
this.timeout(30000)
@ -66,12 +54,14 @@ describe('Test follows moderation', function () {
// Get the access tokens
await setAccessTokensToServers(servers)
commands = servers.map(s => s.followsCommand)
})
it('Should have server 1 following server 2', async function () {
this.timeout(30000)
await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
await commands[0].follow({ targets: [ servers[1].url ] })
await waitJobs(servers)
})
@ -83,7 +73,7 @@ describe('Test follows moderation', function () {
it('Should remove follower on server 2', async function () {
this.timeout(10000)
await removeFollower(servers[1].url, servers[1].accessToken, servers[0])
await commands[1].removeFollower({ follower: servers[0] })
await waitJobs(servers)
})
@ -106,7 +96,7 @@ describe('Test follows moderation', function () {
await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
await commands[0].follow({ targets: [ servers[1].url ] })
await waitJobs(servers)
await checkNoFollowers(servers)
@ -126,7 +116,7 @@ describe('Test follows moderation', function () {
await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
await commands[0].follow({ targets: [ servers[1].url ] })
await waitJobs(servers)
await checkServer1And2HasFollowers(servers)
@ -135,7 +125,7 @@ describe('Test follows moderation', function () {
it('Should manually approve followers', async function () {
this.timeout(20000)
await removeFollower(servers[1].url, servers[1].accessToken, servers[0])
await commands[1].removeFollower({ follower: servers[0] })
await waitJobs(servers)
const subConfig = {
@ -150,7 +140,7 @@ describe('Test follows moderation', function () {
await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
await updateCustomSubConfig(servers[2].url, servers[2].accessToken, subConfig)
await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
await commands[0].follow({ targets: [ servers[1].url ] })
await waitJobs(servers)
await checkServer1And2HasFollowers(servers, 'pending')
@ -159,7 +149,7 @@ describe('Test follows moderation', function () {
it('Should accept a follower', async function () {
this.timeout(10000)
await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@localhost:' + servers[0].port)
await commands[1].acceptFollower({ follower: 'peertube@localhost:' + servers[0].port })
await waitJobs(servers)
await checkServer1And2HasFollowers(servers)
@ -168,32 +158,32 @@ describe('Test follows moderation', function () {
it('Should reject another follower', async function () {
this.timeout(20000)
await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken)
await commands[0].follow({ targets: [ servers[2].url ] })
await waitJobs(servers)
{
const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' })
expect(res.body.total).to.equal(2)
const body = await commands[0].getFollowings({ start: 0, count: 5, sort: 'createdAt' })
expect(body.total).to.equal(2)
}
{
const res = await getFollowersListPaginationAndSort({ url: servers[1].url, start: 0, count: 5, sort: 'createdAt' })
expect(res.body.total).to.equal(1)
const body = await commands[1].getFollowers({ start: 0, count: 5, sort: 'createdAt' })
expect(body.total).to.equal(1)
}
{
const res = await getFollowersListPaginationAndSort({ url: servers[2].url, start: 0, count: 5, sort: 'createdAt' })
expect(res.body.total).to.equal(1)
const body = await commands[2].getFollowers({ start: 0, count: 5, sort: 'createdAt' })
expect(body.total).to.equal(1)
}
await rejectFollower(servers[2].url, servers[2].accessToken, 'peertube@localhost:' + servers[0].port)
await commands[2].rejectFollower({ follower: 'peertube@localhost:' + servers[0].port })
await waitJobs(servers)
await checkServer1And2HasFollowers(servers)
{
const res = await getFollowersListPaginationAndSort({ url: servers[2].url, start: 0, count: 5, sort: 'createdAt' })
expect(res.body.total).to.equal(0)
const body = await commands[2].getFollowers({ start: 0, count: 5, sort: 'createdAt' })
expect(body.total).to.equal(0)
}
})

View File

@ -13,9 +13,7 @@ import {
deleteVideoComment,
expectAccountFollows,
flushAndRunMultipleServers,
follow,
getFollowersListPaginationAndSort,
getFollowingListPaginationAndSort,
FollowsCommand,
getVideoCommentThreads,
getVideosList,
getVideoThreadComments,
@ -24,7 +22,6 @@ import {
ServerInfo,
setAccessTokensToServers,
testCaptionFile,
unfollow,
uploadVideo,
userLogin,
waitJobs
@ -35,11 +32,13 @@ const expect = chai.expect
describe('Test follows', function () {
let servers: ServerInfo[] = []
let followsCommands: FollowsCommand[]
before(async function () {
this.timeout(30000)
servers = await flushAndRunMultipleServers(3)
followsCommands = servers.map(s => s.followsCommand)
// Get the access tokens
await setAccessTokensToServers(servers)
@ -47,10 +46,10 @@ describe('Test follows', function () {
it('Should not have followers', async function () {
for (const server of servers) {
const res = await getFollowersListPaginationAndSort({ url: server.url, start: 0, count: 5, sort: 'createdAt' })
const follows = res.body.data
const body = await server.followsCommand.getFollowers({ start: 0, count: 5, sort: 'createdAt' })
expect(body.total).to.equal(0)
expect(res.body.total).to.equal(0)
const follows = body.data
expect(follows).to.be.an('array')
expect(follows.length).to.equal(0)
}
@ -58,10 +57,10 @@ describe('Test follows', function () {
it('Should not have following', async function () {
for (const server of servers) {
const res = await getFollowingListPaginationAndSort({ url: server.url, start: 0, count: 5, sort: 'createdAt' })
const follows = res.body.data
const body = await server.followsCommand.getFollowings({ start: 0, count: 5, sort: 'createdAt' })
expect(body.total).to.equal(0)
expect(res.body.total).to.equal(0)
const follows = body.data
expect(follows).to.be.an('array')
expect(follows.length).to.equal(0)
}
@ -70,21 +69,21 @@ describe('Test follows', function () {
it('Should have server 1 following server 2 and 3', async function () {
this.timeout(30000)
await follow(servers[0].url, [ servers[1].url, servers[2].url ], servers[0].accessToken)
await followsCommands[0].follow({ targets: [ servers[1].url, servers[2].url ] })
await waitJobs(servers)
})
it('Should have 2 followings on server 1', async function () {
let res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 1, sort: 'createdAt' })
let follows = res.body.data
const body = await followsCommands[0].getFollowings({ start: 0, count: 1, sort: 'createdAt' })
expect(body.total).to.equal(2)
expect(res.body.total).to.equal(2)
let follows = body.data
expect(follows).to.be.an('array')
expect(follows.length).to.equal(1)
res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 1, count: 1, sort: 'createdAt' })
follows = follows.concat(res.body.data)
const body2 = await followsCommands[0].getFollowings({ start: 1, count: 1, sort: 'createdAt' })
follows = follows.concat(body2.data)
const server2Follow = follows.find(f => f.following.host === 'localhost:' + servers[1].port)
const server3Follow = follows.find(f => f.following.host === 'localhost:' + servers[2].port)
@ -99,35 +98,33 @@ describe('Test follows', function () {
const sort = 'createdAt'
const start = 0
const count = 1
const url = servers[0].url
{
const search = ':' + servers[1].port
{
const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search })
const follows = res.body.data
const body = await followsCommands[0].getFollowings({ start, count, sort, search })
expect(body.total).to.equal(1)
expect(res.body.total).to.equal(1)
const follows = body.data
expect(follows.length).to.equal(1)
expect(follows[0].following.host).to.equal('localhost:' + servers[1].port)
}
{
const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search, state: 'accepted' })
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
const body = await followsCommands[0].getFollowings({ start, count, sort, search, state: 'accepted' })
expect(body.total).to.equal(1)
expect(body.data).to.have.lengthOf(1)
}
{
const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search, state: 'accepted', actorType: 'Person' })
expect(res.body.total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0)
const body = await followsCommands[0].getFollowings({ start, count, sort, search, state: 'accepted', actorType: 'Person' })
expect(body.total).to.equal(0)
expect(body.data).to.have.lengthOf(0)
}
{
const res = await getFollowingListPaginationAndSort({
url,
const body = await followsCommands[0].getFollowings({
start,
count,
sort,
@ -135,32 +132,31 @@ describe('Test follows', function () {
state: 'accepted',
actorType: 'Application'
})
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
expect(body.total).to.equal(1)
expect(body.data).to.have.lengthOf(1)
}
{
const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search, state: 'pending' })
expect(res.body.total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0)
const body = await followsCommands[0].getFollowings({ start, count, sort, search, state: 'pending' })
expect(body.total).to.equal(0)
expect(body.data).to.have.lengthOf(0)
}
}
{
const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search: 'bla' })
const follows = res.body.data
const body = await followsCommands[0].getFollowings({ start, count, sort, search: 'bla' })
expect(body.total).to.equal(0)
expect(res.body.total).to.equal(0)
expect(follows.length).to.equal(0)
expect(body.data.length).to.equal(0)
}
})
it('Should have 0 followings on server 2 and 3', async function () {
for (const server of [ servers[1], servers[2] ]) {
const res = await getFollowingListPaginationAndSort({ url: server.url, start: 0, count: 5, sort: 'createdAt' })
const follows = res.body.data
const body = await server.followsCommand.getFollowings({ start: 0, count: 5, sort: 'createdAt' })
expect(body.total).to.equal(0)
expect(res.body.total).to.equal(0)
const follows = body.data
expect(follows).to.be.an('array')
expect(follows.length).to.equal(0)
}
@ -168,10 +164,10 @@ describe('Test follows', function () {
it('Should have 1 followers on server 2 and 3', async function () {
for (const server of [ servers[1], servers[2] ]) {
const res = await getFollowersListPaginationAndSort({ url: server.url, start: 0, count: 1, sort: 'createdAt' })
const body = await server.followsCommand.getFollowers({ start: 0, count: 1, sort: 'createdAt' })
expect(body.total).to.equal(1)
const follows = res.body.data
expect(res.body.total).to.equal(1)
const follows = body.data
expect(follows).to.be.an('array')
expect(follows.length).to.equal(1)
expect(follows[0].follower.host).to.equal('localhost:' + servers[0].port)
@ -179,7 +175,6 @@ describe('Test follows', function () {
})
it('Should search/filter followers on server 2', async function () {
const url = servers[2].url
const start = 0
const count = 5
const sort = 'createdAt'
@ -188,29 +183,28 @@ describe('Test follows', function () {
const search = servers[0].port + ''
{
const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search })
const follows = res.body.data
const body = await followsCommands[2].getFollowers({ start, count, sort, search })
expect(body.total).to.equal(1)
expect(res.body.total).to.equal(1)
const follows = body.data
expect(follows.length).to.equal(1)
expect(follows[0].following.host).to.equal('localhost:' + servers[2].port)
}
{
const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search, state: 'accepted' })
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
const body = await followsCommands[2].getFollowers({ start, count, sort, search, state: 'accepted' })
expect(body.total).to.equal(1)
expect(body.data).to.have.lengthOf(1)
}
{
const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search, state: 'accepted', actorType: 'Person' })
expect(res.body.total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0)
const body = await followsCommands[2].getFollowers({ start, count, sort, search, state: 'accepted', actorType: 'Person' })
expect(body.total).to.equal(0)
expect(body.data).to.have.lengthOf(0)
}
{
const res = await getFollowersListPaginationAndSort({
url,
const body = await followsCommands[2].getFollowers({
start,
count,
sort,
@ -218,31 +212,31 @@ describe('Test follows', function () {
state: 'accepted',
actorType: 'Application'
})
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
expect(body.total).to.equal(1)
expect(body.data).to.have.lengthOf(1)
}
{
const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search, state: 'pending' })
expect(res.body.total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0)
const body = await followsCommands[2].getFollowers({ start, count, sort, search, state: 'pending' })
expect(body.total).to.equal(0)
expect(body.data).to.have.lengthOf(0)
}
}
{
const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search: 'bla' })
const follows = res.body.data
const body = await followsCommands[2].getFollowers({ start, count, sort, search: 'bla' })
expect(body.total).to.equal(0)
expect(res.body.total).to.equal(0)
const follows = body.data
expect(follows.length).to.equal(0)
}
})
it('Should have 0 followers on server 1', async function () {
const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' })
const follows = res.body.data
const body = await followsCommands[0].getFollowers({ start: 0, count: 5, sort: 'createdAt' })
expect(body.total).to.equal(0)
expect(res.body.total).to.equal(0)
const follows = body.data
expect(follows).to.be.an('array')
expect(follows.length).to.equal(0)
})
@ -263,16 +257,16 @@ describe('Test follows', function () {
it('Should unfollow server 3 on server 1', async function () {
this.timeout(5000)
await unfollow(servers[0].url, servers[0].accessToken, servers[2])
await followsCommands[0].unfollow({ target: servers[2] })
await waitJobs(servers)
})
it('Should not follow server 3 on server 1 anymore', async function () {
const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' })
const follows = res.body.data
const body = await followsCommands[0].getFollowings({ start: 0, count: 2, sort: 'createdAt' })
expect(body.total).to.equal(1)
expect(res.body.total).to.equal(1)
const follows = body.data
expect(follows).to.be.an('array')
expect(follows.length).to.equal(1)
@ -280,10 +274,10 @@ describe('Test follows', function () {
})
it('Should not have server 1 as follower on server 3 anymore', async function () {
const res = await getFollowersListPaginationAndSort({ url: servers[2].url, start: 0, count: 1, sort: 'createdAt' })
const body = await followsCommands[2].getFollowers({ start: 0, count: 1, sort: 'createdAt' })
expect(body.total).to.equal(0)
const follows = res.body.data
expect(res.body.total).to.equal(0)
const follows = body.data
expect(follows).to.be.an('array')
expect(follows.length).to.equal(0)
})
@ -404,7 +398,7 @@ describe('Test follows', function () {
await waitJobs(servers)
// Server 1 follows server 3
await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken)
await followsCommands[0].follow({ targets: [ servers[2].url ] })
await waitJobs(servers)
})
@ -563,7 +557,7 @@ describe('Test follows', function () {
it('Should unfollow server 3 on server 1 and does not list server 3 videos', async function () {
this.timeout(5000)
await unfollow(servers[0].url, servers[0].accessToken, servers[2])
await followsCommands[0].unfollow({ target: servers[2] })
await waitJobs(servers)

View File

@ -1,39 +1,33 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import * as chai from 'chai'
import 'mocha'
import { JobState, Video } from '../../../../shared/models'
import { VideoPrivacy } from '../../../../shared/models/videos'
import { VideoCommentThreadTree } from '../../../../shared/models/videos/comment/video-comment.model'
import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
import {
addVideoCommentReply,
addVideoCommentThread,
cleanupTests,
closeAllSequelize,
completeVideoCheck,
flushAndRunMultipleServers,
getJobsListPaginationAndSort,
getVideo,
getVideoCommentThreads,
getVideosList,
getVideoThreadComments,
immutableAssign,
killallServers,
reRunServer,
ServerInfo,
setAccessTokensToServers,
setActorFollowScores,
unfollow,
updateVideo,
uploadVideo,
uploadVideoAndGetId,
wait
} from '../../../../shared/extra-utils'
import { follow, getFollowersListPaginationAndSort } from '../../../../shared/extra-utils/server/follows'
import { getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs'
import {
addVideoCommentReply,
addVideoCommentThread,
getVideoCommentThreads,
getVideoThreadComments
} from '../../../../shared/extra-utils/videos/video-comments'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
wait,
waitJobs
} from '@shared/extra-utils'
import { JobState, Video, VideoCommentThreadTree, VideoPrivacy } from '@shared/models'
const expect = chai.expect
@ -118,8 +112,8 @@ describe('Test handle downs', function () {
this.timeout(240000)
// Server 2 and 3 follow server 1
await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
await servers[1].followsCommand.follow({ targets: [ servers[0].url ] })
await servers[2].followsCommand.follow({ targets: [ servers[0].url ] })
await waitJobs(servers)
@ -177,10 +171,10 @@ describe('Test handle downs', function () {
await wait(11000)
// Only server 3 is still a follower of server 1
const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' })
expect(res.body.data).to.be.an('array')
expect(res.body.data).to.have.lengthOf(1)
expect(res.body.data[0].follower.host).to.equal('localhost:' + servers[2].port)
const body = await servers[0].followsCommand.getFollowers({ start: 0, count: 2, sort: 'createdAt' })
expect(body.data).to.be.an('array')
expect(body.data).to.have.lengthOf(1)
expect(body.data[0].follower.host).to.equal('localhost:' + servers[2].port)
})
it('Should not have pending/processing jobs anymore', async function () {
@ -205,16 +199,16 @@ describe('Test handle downs', function () {
await reRunServer(servers[1])
await reRunServer(servers[2])
await unfollow(servers[1].url, servers[1].accessToken, servers[0])
await servers[1].followsCommand.unfollow({ target: servers[0] })
await waitJobs(servers)
await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
await servers[1].followsCommand.follow({ targets: [ servers[0].url ] })
await waitJobs(servers)
const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' })
expect(res.body.data).to.be.an('array')
expect(res.body.data).to.have.lengthOf(2)
const body = await servers[0].followsCommand.getFollowers({ start: 0, count: 2, sort: 'createdAt' })
expect(body.data).to.be.an('array')
expect(body.data).to.have.lengthOf(2)
})
it('Should send an update to server 3, and automatically fetch the video', async function () {

View File

@ -1,13 +1,13 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import * as chai from 'chai'
import 'mocha'
import * as chai from 'chai'
import { cleanupTests, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
import { dateIsValid } from '../../../../shared/extra-utils/miscs/miscs'
import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { flushAndRunMultipleServers } from '../../../../shared/extra-utils/server/servers'
import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
import { dateIsValid } from '../../../../shared/extra-utils/miscs/miscs'
import { Job } from '../../../../shared/models/server'
const expect = chai.expect

View File

@ -4,27 +4,23 @@ import 'mocha'
import * as chai from 'chai'
import {
addVideoChannel,
addVideoCommentThread,
cleanupTests,
createUser,
createVideoPlaylist,
doubleFollow,
flushAndRunMultipleServers,
follow,
ServerInfo,
unfollow,
setAccessTokensToServers,
updateCustomSubConfig,
uploadVideo,
userLogin,
viewVideo,
wait
} from '../../../../shared/extra-utils'
import { setAccessTokensToServers } from '../../../../shared/extra-utils/index'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { getStats } from '../../../../shared/extra-utils/server/stats'
import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
import { ServerStats } from '../../../../shared/models/server/server-stats.model'
import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
import { ActivityType } from '@shared/models'
wait,
waitJobs
} from '@shared/extra-utils'
import { getStats } from '@shared/extra-utils/server/stats'
import { ActivityType, ServerStats, VideoPlaylistPrivacy } from '@shared/models'
const expect = chai.expect
@ -57,7 +53,7 @@ describe('Test stats (excluding redundancy)', function () {
// Wait the video views repeatable job
await wait(8000)
await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
await servers[2].followsCommand.follow({ targets: [ servers[0].url ] })
await waitJobs(servers)
})
@ -111,7 +107,7 @@ describe('Test stats (excluding redundancy)', function () {
it('Should have the correct total videos stats after an unfollow', async function () {
this.timeout(15000)
await unfollow(servers[2].url, servers[2].accessToken, servers[0])
await servers[2].followsCommand.unfollow({ target: servers[0] })
await waitJobs(servers)
const res = await getStats(servers[2].url)

View File

@ -1,30 +1,27 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import * as chai from 'chai'
import 'mocha'
import * as chai from 'chai'
import {
addUserSubscription,
areSubscriptionsExist,
cleanupTests,
createUser,
doubleFollow,
flushAndRunMultipleServers,
follow,
getVideosList,
unfollow,
updateVideo,
userLogin
} from '../../../../shared/extra-utils'
import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
import { Video, VideoChannel } from '../../../../shared/models/videos'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import {
addUserSubscription,
areSubscriptionsExist,
getUserSubscription,
getVideosList,
listUserSubscriptions,
listUserSubscriptionVideos,
removeUserSubscription
} from '../../../../shared/extra-utils/users/user-subscriptions'
removeUserSubscription,
ServerInfo,
setAccessTokensToServers,
updateVideo,
uploadVideo,
userLogin,
waitJobs
} from '@shared/extra-utils'
import { Video, VideoChannel } from '@shared/models'
const expect = chai.expect
@ -250,7 +247,7 @@ describe('Test users subscriptions', function () {
it('Should have server 1 follow server 3 and display server 3 videos', async function () {
this.timeout(60000)
await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken)
await servers[0].followsCommand.follow({ targets: [ servers[2].url ] })
await waitJobs(servers)
@ -268,7 +265,7 @@ describe('Test users subscriptions', function () {
it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () {
this.timeout(60000)
await unfollow(servers[0].url, servers[0].accessToken, servers[2])
await servers[0].followsCommand.unfollow({ target: servers[2] })
await waitJobs(servers)

View File

@ -11,7 +11,6 @@ import {
createUser,
deleteMe,
flushAndRunServer,
follow,
getAccountRatings,
getBlacklistedVideosList,
getCustomConfig,
@ -138,7 +137,12 @@ describe('Test users', function () {
it('Should not be able to follow', async function () {
accessToken = 'my_super_token'
await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401)
await server.followsCommand.follow({
targets: [ 'http://example.com' ],
token: accessToken,
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
})
})
it('Should not be able to unfollow')

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import * as chai from 'chai'
import 'mocha'
import * as chai from 'chai'
import {
cleanupTests,
flushAndRunMultipleServers,

View File

@ -2,8 +2,12 @@
import 'mocha'
import * as chai from 'chai'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { HttpStatusCode } from '@shared/core-utils'
import {
addAccountToAccountBlocklist,
addAccountToServerBlocklist,
addServerToAccountBlocklist,
addServerToServerBlocklist,
addVideoChannel,
addVideoInPlaylist,
addVideoToBlacklist,
@ -27,6 +31,10 @@ import {
getVideoPlaylistPrivacies,
getVideoPlaylistsList,
getVideoPlaylistWithToken,
removeAccountFromAccountBlocklist,
removeAccountFromServerBlocklist,
removeServerFromAccountBlocklist,
removeServerFromServerBlocklist,
removeUser,
removeVideoFromBlacklist,
removeVideoFromPlaylist,
@ -35,7 +43,6 @@ import {
setAccessTokensToServers,
setDefaultVideoChannel,
testImage,
unfollow,
updateVideo,
updateVideoPlaylist,
updateVideoPlaylistElement,
@ -44,24 +51,18 @@ import {
userLogin,
wait,
waitJobs
} from '../../../../shared/extra-utils'
} from '@shared/extra-utils'
import {
addAccountToAccountBlocklist,
addAccountToServerBlocklist,
addServerToAccountBlocklist,
addServerToServerBlocklist,
removeAccountFromAccountBlocklist,
removeAccountFromServerBlocklist,
removeServerFromAccountBlocklist,
removeServerFromServerBlocklist
} from '../../../../shared/extra-utils/users/blocklist'
import { User } from '../../../../shared/models/users'
import { VideoPlaylistCreateResult, VideoPrivacy } from '../../../../shared/models/videos'
import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'
import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../../shared/models/videos/playlist/video-playlist-element.model'
import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model'
User,
VideoExistInPlaylist,
VideoPlaylist,
VideoPlaylistCreateResult,
VideoPlaylistElement,
VideoPlaylistElementType,
VideoPlaylistPrivacy,
VideoPlaylistType,
VideoPrivacy
} from '@shared/models'
const expect = chai.expect
@ -1171,7 +1172,7 @@ describe('Test video playlists', function () {
expect(finder(res.body.data)).to.not.be.undefined
}
await unfollow(servers[2].url, servers[2].accessToken, servers[0])
await servers[2].followsCommand.unfollow({ target: servers[0] })
{
const res = await getVideoPlaylistsList(servers[2].url, 0, 5)

View File

@ -7,15 +7,14 @@ export * from './miscs'
export * from './mock-servers'
export * from './moderation'
export * from './overviews'
export * from './search'
export * from './server'
export * from './requests/check-api-params'
export * from './requests/requests'
export * from './search'
export * from './server/clients'
export * from './server/config'
export * from './server/follows'
export * from './server/jobs'
export * from './server/plugins'
export * from './server/servers'

View File

@ -0,0 +1,124 @@
import { pick } from 'lodash'
import { ActivityPubActorType, ActorFollow, FollowState, ResultList } from '@shared/models'
import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
import { AbstractCommand, OverrideCommandOptions } from '../shared'
import { ServerInfo } from './servers'
export class FollowsCommand extends AbstractCommand {
getFollowers (options: OverrideCommandOptions & {
start: number
count: number
sort: string
search?: string
actorType?: ActivityPubActorType
state?: FollowState
}) {
const path = '/api/v1/server/followers'
const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ]
const query = pick(options, toPick)
return this.getRequestBody<ResultList<ActorFollow>>({
...options,
token: null,
path,
query,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
getFollowings (options: OverrideCommandOptions & {
start: number
count: number
sort: string
search?: string
actorType?: ActivityPubActorType
state?: FollowState
}) {
const path = '/api/v1/server/following'
const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ]
const query = pick(options, toPick)
return this.getRequestBody<ResultList<ActorFollow>>({
...options,
token: null,
path,
query,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
follow (options: OverrideCommandOptions & {
targets: string[]
}) {
const path = '/api/v1/server/following'
const hosts = options.targets.map(f => f.replace(/^http:\/\//, ''))
return this.postBodyRequest({
...options,
path,
fields: { hosts },
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
async unfollow (options: OverrideCommandOptions & {
target: ServerInfo
}) {
const path = '/api/v1/server/following/' + options.target.host
return this.deleteRequest({
...options,
path,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
acceptFollower (options: OverrideCommandOptions & {
follower: string
}) {
const path = '/api/v1/server/followers/' + options.follower + '/accept'
return this.postBodyRequest({
...options,
path,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
rejectFollower (options: OverrideCommandOptions & {
follower: string
}) {
const path = '/api/v1/server/followers/' + options.follower + '/reject'
return this.postBodyRequest({
...options,
path,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
removeFollower (options: OverrideCommandOptions & {
follower: ServerInfo
}) {
const path = '/api/v1/server/followers/peertube@' + options.follower.host
return this.deleteRequest({
...options,
path,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
}

View File

@ -1,126 +1,10 @@
import * as request from 'supertest'
import { ServerInfo } from './servers'
import { waitJobs } from './jobs'
import { makePostBodyRequest } from '../requests/requests'
import { ActivityPubActorType, FollowState } from '@shared/models'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
function getFollowersListPaginationAndSort (options: {
url: string
start: number
count: number
sort: string
search?: string
actorType?: ActivityPubActorType
state?: FollowState
}) {
const { url, start, count, sort, search, state, actorType } = options
const path = '/api/v1/server/followers'
const query = {
start,
count,
sort,
search,
state,
actorType
}
return request(url)
.get(path)
.query(query)
.set('Accept', 'application/json')
.expect(HttpStatusCode.OK_200)
.expect('Content-Type', /json/)
}
function acceptFollower (url: string, token: string, follower: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
const path = '/api/v1/server/followers/' + follower + '/accept'
return makePostBodyRequest({
url,
token,
path,
statusCodeExpected
})
}
function rejectFollower (url: string, token: string, follower: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
const path = '/api/v1/server/followers/' + follower + '/reject'
return makePostBodyRequest({
url,
token,
path,
statusCodeExpected
})
}
function getFollowingListPaginationAndSort (options: {
url: string
start: number
count: number
sort: string
search?: string
actorType?: ActivityPubActorType
state?: FollowState
}) {
const { url, start, count, sort, search, state, actorType } = options
const path = '/api/v1/server/following'
const query = {
start,
count,
sort,
search,
state,
actorType
}
return request(url)
.get(path)
.query(query)
.set('Accept', 'application/json')
.expect(HttpStatusCode.OK_200)
.expect('Content-Type', /json/)
}
function follow (follower: string, following: string[], accessToken: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
const path = '/api/v1/server/following'
const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
return request(follower)
.post(path)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.send({ hosts: followingHosts })
.expect(expectedStatus)
}
async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
const path = '/api/v1/server/following/' + target.host
return request(url)
.delete(path)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.expect(expectedStatus)
}
function removeFollower (url: string, accessToken: string, follower: ServerInfo, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
const path = '/api/v1/server/followers/peertube@' + follower.host
return request(url)
.delete(path)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.expect(expectedStatus)
}
import { ServerInfo } from './servers'
async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
await Promise.all([
follow(server1.url, [ server2.url ], server1.accessToken),
follow(server2.url, [ server1.url ], server2.accessToken)
server1.followsCommand.follow({ targets: [ server2.url ] }),
server2.followsCommand.follow({ targets: [ server1.url ] })
])
// Wait request propagation
@ -132,12 +16,5 @@ async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
// ---------------------------------------------------------------------------
export {
getFollowersListPaginationAndSort,
getFollowingListPaginationAndSort,
unfollow,
removeFollower,
follow,
doubleFollow,
acceptFollower,
rejectFollower
doubleFollow
}

View File

@ -1,2 +1,4 @@
export * from './contact-form-command'
export * from './debug-command'
export * from './follows-command'
export * from './follows'

View File

@ -18,6 +18,7 @@ import { makeGetRequest } from '../requests/requests'
import { SearchCommand } from '../search'
import { ContactFormCommand } from './contact-form-command'
import { DebugCommand } from './debug-command'
import { FollowsCommand } from './follows-command'
interface ServerInfo {
app: ChildProcess
@ -81,6 +82,7 @@ interface ServerInfo {
searchCommand?: SearchCommand
contactFormCommand?: ContactFormCommand
debugCommand?: DebugCommand
followsCommand?: FollowsCommand
}
function parallelTests () {
@ -296,6 +298,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
server.searchCommand = new SearchCommand(server)
server.contactFormCommand = new ContactFormCommand(server)
server.debugCommand = new DebugCommand(server)
server.followsCommand = new FollowsCommand(server)
res(server)
})