From c3d29f694bf8c910f917be655626d0f80871124f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 09:16:40 +0200 Subject: Introduce follows command --- server/tests/api/moderation/blocklist.ts | 10 +- .../api/notifications/moderation-notifications.ts | 16 +-- .../tests/api/redundancy/redundancy-constraints.ts | 5 +- server/tests/api/redundancy/redundancy.ts | 24 ++-- server/tests/api/server/auto-follows.ts | 48 +++---- server/tests/api/server/follow-constraints.ts | 15 +-- server/tests/api/server/follows-moderation.ts | 92 ++++++------- server/tests/api/server/follows.ts | 144 ++++++++++----------- server/tests/api/server/handle-down.ts | 50 ++++--- server/tests/api/server/jobs.ts | 4 +- server/tests/api/server/stats.ts | 22 ++-- server/tests/api/users/user-subscriptions.ts | 33 +++-- server/tests/api/users/users.ts | 8 +- server/tests/api/videos/video-description.ts | 2 +- server/tests/api/videos/video-playlists.ts | 41 +++--- 15 files changed, 233 insertions(+), 281 deletions(-) (limited to 'server') diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 793abbcb4..9ca6324c2 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -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) diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index c4f63200a..9a93ce401 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -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] }) }) }) diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index 1cb1603bc..602f4bc1b 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts @@ -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') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 0e0a73b9d..dfe8099ed 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -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) diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts index 1519b263f..02389b1e9 100644 --- a/server/tests/api/server/auto-follows.ts +++ b/server/tests/api/server/auto-follows.ts @@ -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 follow = follows.find(f => { - return f.following.host === following.host && f.state === 'accepted' - }) + 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') - 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) diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts index 3f2f71f46..0f1c6264d 100644 --- a/server/tests/api/server/follow-constraints.ts +++ b/server/tests/api/server/follow-constraints.ts @@ -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 () { diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index 73c212a32..4853b647d 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts @@ -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') - } - - { - const res = await getFollowersListPaginationAndSort({ url: servers[1].url, start: 0, count: 5, sort: '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') @@ -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 res = await getFollowersListPaginationAndSort({ url: servers[1].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) + ] + + 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) } }) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index 9e5aa00c7..c8fcca02c 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -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) diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index d57d72f5e..eff4451e5 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -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 () { diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index d0e222997..6576dd7af 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -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 diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index 304181a6d..f609ea725 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -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) diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 60676a37b..7e365d797 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -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) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 6bfc7cfe5..92927ea97 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -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') diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts index b8e98e45f..e1c9afe79 100644 --- a/server/tests/api/videos/video-description.ts +++ b/server/tests/api/videos/video-description.ts @@ -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, diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index da8de054b..28f68dcfe 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -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) -- cgit v1.2.3