X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fserver%2Ffollows-moderation.ts;h=921f510435cf3131e6bd138b4481c79f24660ce9;hb=4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef;hp=a82acdb34a4c8417e7e1e770337873f27259379a;hpb=a41b9da1a9ce49df82ea10c82de4c2fbc6d1b189;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index a82acdb34..921f51043 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts @@ -1,77 +1,66 @@ -/* tslint:disable:no-unused-expression */ +/* 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, - ServerInfo, + createMultipleServers, + FollowsCommand, + PeerTubeServer, 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' + waitJobs +} from '@shared/extra-utils' const expect = chai.expect -async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'accepted') { - { - const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt') - expect(res.body.total).to.equal(1) - - 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') - } +async function checkServer1And2HasFollowers (servers: PeerTubeServer[], state = 'accepted') { + const fns = [ + servers[0].follows.getFollowings.bind(servers[0].follows), + servers[1].follows.getFollowers.bind(servers[1].follows) + ] - { - const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt') - expect(res.body.total).to.equal(1) + for (const fn of fns) { + const body = await fn({ start: 0, count: 5, sort: 'createdAt' }) + expect(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') } } -async function checkNoFollowers (servers: ServerInfo[]) { - { - const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 5, 'createdAt') - expect(res.body.total).to.equal(0) - } +async function checkNoFollowers (servers: PeerTubeServer[]) { + const fns = [ + servers[0].follows.getFollowings.bind(servers[0].follows), + servers[1].follows.getFollowers.bind(servers[1].follows) + ] - { - const res = await getFollowersListPaginationAndSort(servers[ 1 ].url, 0, 5, '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 servers: PeerTubeServer[] = [] + let commands: FollowsCommand[] before(async function () { this.timeout(30000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) // Get the access tokens await setAccessTokensToServers(servers) + + commands = servers.map(s => s.follows) }) 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({ hosts: [ servers[1].url ] }) await waitJobs(servers) }) @@ -81,7 +70,9 @@ describe('Test follows moderation', function () { }) it('Should remove follower on server 2', async function () { - await removeFollower(servers[1].url, servers[1].accessToken, servers[0]) + this.timeout(10000) + + await commands[1].removeFollower({ follower: servers[0] }) await waitJobs(servers) }) @@ -91,6 +82,8 @@ describe('Test follows moderation', function () { }) it('Should disable followers on server 2', async function () { + this.timeout(10000) + const subConfig = { followers: { instance: { @@ -100,15 +93,17 @@ describe('Test follows moderation', function () { } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) + await servers[1].config.updateCustomSubConfig({ newConfig: subConfig }) - await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) + await commands[0].follow({ hosts: [ servers[1].url ] }) await waitJobs(servers) await checkNoFollowers(servers) }) it('Should re enable followers on server 2', async function () { + this.timeout(10000) + const subConfig = { followers: { instance: { @@ -118,9 +113,9 @@ describe('Test follows moderation', function () { } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) + await servers[1].config.updateCustomSubConfig({ newConfig: subConfig }) - await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) + await commands[0].follow({ hosts: [ servers[1].url ] }) await waitJobs(servers) await checkServer1And2HasFollowers(servers) @@ -129,7 +124,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 = { @@ -141,17 +136,19 @@ describe('Test follows moderation', function () { } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) - await updateCustomSubConfig(servers[2].url, servers[2].accessToken, subConfig) + await servers[1].config.updateCustomSubConfig({ newConfig: subConfig }) + await servers[2].config.updateCustomSubConfig({ newConfig: subConfig }) - await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) + await commands[0].follow({ hosts: [ servers[1].url ] }) await waitJobs(servers) await checkServer1And2HasFollowers(servers, 'pending') }) it('Should accept a follower', async function () { - await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@localhost:' + servers[0].port) + this.timeout(10000) + + await commands[1].acceptFollower({ follower: 'peertube@localhost:' + servers[0].port }) await waitJobs(servers) await checkServer1And2HasFollowers(servers) @@ -160,32 +157,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({ hosts: [ servers[2].url ] }) await waitJobs(servers) { - const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, '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(servers[1].url, 0, 5, '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(servers[2].url, 0, 5, '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(servers[ 2 ].url, 0, 5, '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) } })