From 0c1a77e9ccf915184c431145a8b326d4ce271b46 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 12:01:59 +0200 Subject: Introduce abuse command --- server/tests/api/moderation/abuses.ts | 631 ++++++++++++++++------------------ 1 file changed, 294 insertions(+), 337 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index fb765e7e3..a9f5332ce 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -3,51 +3,32 @@ import 'mocha' import * as chai from 'chai' import { - AbuseFilter, - AbuseMessage, - AbusePredefinedReasonsString, - AbuseState, - Account, - AdminAbuse, - UserAbuse, - VideoComment -} from '@shared/models' -import { - addAbuseMessage, + AbusesCommand, + addAccountToServerBlocklist, + addServerToServerBlocklist, addVideoCommentThread, cleanupTests, createUser, - deleteAbuse, - deleteAbuseMessage, deleteVideoComment, + doubleFollow, flushAndRunMultipleServers, generateUserAccessToken, getAccount, - getAdminAbusesList, - getUserAbusesList, getVideoCommentThreads, getVideoIdFromUUID, getVideosList, - immutableAssign, - listAbuseMessages, + removeAccountFromServerBlocklist, + removeServerFromServerBlocklist, removeUser, removeVideo, - reportAbuse, ServerInfo, setAccessTokensToServers, - updateAbuse, uploadVideo, uploadVideoAndGetId, - userLogin -} from '../../../../shared/extra-utils/index' -import { doubleFollow } from '../../../../shared/extra-utils/server/follows' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - addAccountToServerBlocklist, - addServerToServerBlocklist, - removeAccountFromServerBlocklist, - removeServerFromServerBlocklist -} from '../../../../shared/extra-utils/users/blocklist' + userLogin, + waitJobs +} from '@shared/extra-utils' +import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, Account, AdminAbuse, UserAbuse, VideoComment } from '@shared/models' const expect = chai.expect @@ -55,6 +36,7 @@ describe('Test abuses', function () { let servers: ServerInfo[] = [] let abuseServer1: AdminAbuse let abuseServer2: AdminAbuse + let commands: AbusesCommand[] before(async function () { this.timeout(50000) @@ -67,6 +49,8 @@ describe('Test abuses', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) + + commands = servers.map(s => s.abusesCommand) }) describe('Video abuses', function () { @@ -100,54 +84,58 @@ describe('Test abuses', function () { }) it('Should not have abuses', async function () { - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + const body = await commands[0].getAdminList() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) }) it('Should report abuse on a local video', async function () { this.timeout(15000) const reason = 'my super bad reason' - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: servers[0].video.id, reason }) + await commands[0].report({ videoId: servers[0].video.id, reason }) // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 await waitJobs(servers) }) it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { - const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + { + const body = await commands[0].getAdminList() - expect(res1.body.total).to.equal(1) - expect(res1.body.data).to.be.an('array') - expect(res1.body.data.length).to.equal(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(1) - const abuse: AdminAbuse = res1.body.data[0] - expect(abuse.reason).to.equal('my super bad reason') + const abuse = body.data[0] + expect(abuse.reason).to.equal('my super bad reason') - expect(abuse.reporterAccount.name).to.equal('root') - expect(abuse.reporterAccount.host).to.equal(servers[0].host) + expect(abuse.reporterAccount.name).to.equal('root') + expect(abuse.reporterAccount.host).to.equal(servers[0].host) - expect(abuse.video.id).to.equal(servers[0].video.id) - expect(abuse.video.channel).to.exist + expect(abuse.video.id).to.equal(servers[0].video.id) + expect(abuse.video.channel).to.exist - expect(abuse.comment).to.be.null + expect(abuse.comment).to.be.null - expect(abuse.flaggedAccount.name).to.equal('root') - expect(abuse.flaggedAccount.host).to.equal(servers[0].host) + expect(abuse.flaggedAccount.name).to.equal('root') + expect(abuse.flaggedAccount.host).to.equal(servers[0].host) - expect(abuse.video.countReports).to.equal(1) - expect(abuse.video.nthReport).to.equal(1) + expect(abuse.video.countReports).to.equal(1) + expect(abuse.video.nthReport).to.equal(1) - expect(abuse.countReportsForReporter).to.equal(1) - expect(abuse.countReportsForReportee).to.equal(1) + expect(abuse.countReportsForReporter).to.equal(1) + expect(abuse.countReportsForReportee).to.equal(1) + } - const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) - expect(res2.body.total).to.equal(0) - expect(res2.body.data).to.be.an('array') - expect(res2.body.data.length).to.equal(0) + { + const body = await commands[1].getAdminList() + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } }) it('Should report abuse on a remote video', async function () { @@ -155,68 +143,72 @@ describe('Test abuses', function () { const reason = 'my super bad reason 2' const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId, reason }) + await commands[0].report({ videoId, reason }) // We wait requests propagation await waitJobs(servers) }) it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { - const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + { + const body = await commands[0].getAdminList() - expect(res1.body.total).to.equal(2) - expect(res1.body.data.length).to.equal(2) + expect(body.total).to.equal(2) + expect(body.data.length).to.equal(2) - const abuse1: AdminAbuse = res1.body.data[0] - expect(abuse1.reason).to.equal('my super bad reason') - expect(abuse1.reporterAccount.name).to.equal('root') - expect(abuse1.reporterAccount.host).to.equal(servers[0].host) + const abuse1 = body.data[0] + expect(abuse1.reason).to.equal('my super bad reason') + expect(abuse1.reporterAccount.name).to.equal('root') + expect(abuse1.reporterAccount.host).to.equal(servers[0].host) - expect(abuse1.video.id).to.equal(servers[0].video.id) - expect(abuse1.video.countReports).to.equal(1) - expect(abuse1.video.nthReport).to.equal(1) + expect(abuse1.video.id).to.equal(servers[0].video.id) + expect(abuse1.video.countReports).to.equal(1) + expect(abuse1.video.nthReport).to.equal(1) - expect(abuse1.comment).to.be.null + expect(abuse1.comment).to.be.null - expect(abuse1.flaggedAccount.name).to.equal('root') - expect(abuse1.flaggedAccount.host).to.equal(servers[0].host) + expect(abuse1.flaggedAccount.name).to.equal('root') + expect(abuse1.flaggedAccount.host).to.equal(servers[0].host) - expect(abuse1.state.id).to.equal(AbuseState.PENDING) - expect(abuse1.state.label).to.equal('Pending') - expect(abuse1.moderationComment).to.be.null + expect(abuse1.state.id).to.equal(AbuseState.PENDING) + expect(abuse1.state.label).to.equal('Pending') + expect(abuse1.moderationComment).to.be.null - const abuse2: AdminAbuse = res1.body.data[1] - expect(abuse2.reason).to.equal('my super bad reason 2') + const abuse2 = body.data[1] + expect(abuse2.reason).to.equal('my super bad reason 2') - expect(abuse2.reporterAccount.name).to.equal('root') - expect(abuse2.reporterAccount.host).to.equal(servers[0].host) + expect(abuse2.reporterAccount.name).to.equal('root') + expect(abuse2.reporterAccount.host).to.equal(servers[0].host) - expect(abuse2.video.id).to.equal(servers[1].video.id) + expect(abuse2.video.id).to.equal(servers[1].video.id) - expect(abuse2.comment).to.be.null + expect(abuse2.comment).to.be.null - expect(abuse2.flaggedAccount.name).to.equal('root') - expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) + expect(abuse2.flaggedAccount.name).to.equal('root') + expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) - expect(abuse2.state.id).to.equal(AbuseState.PENDING) - expect(abuse2.state.label).to.equal('Pending') - expect(abuse2.moderationComment).to.be.null + expect(abuse2.state.id).to.equal(AbuseState.PENDING) + expect(abuse2.state.label).to.equal('Pending') + expect(abuse2.moderationComment).to.be.null + } - const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) - expect(res2.body.total).to.equal(1) - expect(res2.body.data.length).to.equal(1) + { + const body = await commands[1].getAdminList() + expect(body.total).to.equal(1) + expect(body.data.length).to.equal(1) - abuseServer2 = res2.body.data[0] - expect(abuseServer2.reason).to.equal('my super bad reason 2') - expect(abuseServer2.reporterAccount.name).to.equal('root') - expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) + abuseServer2 = body.data[0] + expect(abuseServer2.reason).to.equal('my super bad reason 2') + expect(abuseServer2.reporterAccount.name).to.equal('root') + expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) - expect(abuse2.flaggedAccount.name).to.equal('root') - expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) + expect(abuseServer2.flaggedAccount.name).to.equal('root') + expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host) - expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) - expect(abuseServer2.state.label).to.equal('Pending') - expect(abuseServer2.moderationComment).to.be.null + expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) + expect(abuseServer2.state.label).to.equal('Pending') + expect(abuseServer2.moderationComment).to.be.null + } }) it('Should hide video abuses from blocked accounts', async function () { @@ -224,11 +216,11 @@ describe('Test abuses', function () { { const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid) - await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'will mute this' }) + await commands[1].report({ videoId, reason: 'will mute this' }) await waitJobs(servers) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) - expect(res.body.total).to.equal(3) + const body = await commands[0].getAdminList() + expect(body.total).to.equal(3) } const accountToBlock = 'root@' + servers[1].host @@ -236,18 +228,18 @@ describe('Test abuses', function () { { await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getAdminList() + expect(body.total).to.equal(2) - const abuse = res.body.data.find(a => a.reason === 'will mute this') + const abuse = body.data.find(a => a.reason === 'will mute this') expect(abuse).to.be.undefined } { await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) - expect(res.body.total).to.equal(3) + const body = await commands[0].getAdminList() + expect(body.total).to.equal(3) } }) @@ -257,18 +249,18 @@ describe('Test abuses', function () { { await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getAdminList() + expect(body.total).to.equal(2) - const abuse = res.body.data.find(a => a.reason === 'will mute this') + const abuse = body.data.find(a => a.reason === 'will mute this') expect(abuse).to.be.undefined } { await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) - expect(res.body.total).to.equal(3) + const body = await commands[0].getAdminList() + expect(body.total).to.equal(3) } }) @@ -279,11 +271,11 @@ describe('Test abuses', function () { await waitJobs(servers) - const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) - expect(res.body.total).to.equal(2, "wrong number of videos returned") - expect(res.body.data).to.have.lengthOf(2, "wrong number of videos returned") + const body = await commands[1].getAdminList() + expect(body.total).to.equal(2, "wrong number of videos returned") + expect(body.data).to.have.lengthOf(2, "wrong number of videos returned") - const abuse: AdminAbuse = res.body.data[0] + const abuse = body.data[0] expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video") expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id") expect(abuse.video.channel).to.exist @@ -303,24 +295,21 @@ describe('Test abuses', function () { name: 'my second super name for server 1', description: 'my second super description for server 1' } - await uploadVideo(servers[0].url, userAccessToken, video3Attributes) - - const res1 = await getVideosList(servers[0].url) - const videos = res1.body.data - const video3 = videos.find(video => video.name === 'my second super name for server 1') + const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes) + const video3Id = resUpload.body.video.id // resume with the test const reason3 = 'my super bad reason 3' - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video3.id, reason: reason3 }) + await commands[0].report({ videoId: video3Id, reason: reason3 }) const reason4 = 'my super bad reason 4' - await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: reason4 }) + await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: reason4 }) { - const res2 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) - const abuses = res2.body.data as AdminAbuse[] + const body = await commands[0].getAdminList() + const abuses = body.data - const abuseVideo3 = res2.body.data.find(a => a.video.id === video3.id) + const abuseVideo3 = body.data.find(a => a.video.id === video3Id) expect(abuseVideo3).to.not.be.undefined expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3") expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3") @@ -337,20 +326,18 @@ describe('Test abuses', function () { const reason5 = 'my super bad reason 5' const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ] - const createdAbuse = (await reportAbuse({ - url: servers[0].url, - token: servers[0].accessToken, + const createRes = await commands[0].report({ videoId: servers[0].video.id, reason: reason5, predefinedReasons: predefinedReasons5, startAt: 1, endAt: 5 - })).body.abuse + }) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + const body = await commands[0].getAdminList() { - const abuse = (res.body.data as AdminAbuse[]).find(a => a.id === createdAbuse.id) + const abuse = body.data.find(a => a.id === createRes.abuse.id) expect(abuse.reason).to.equals(reason5) expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported") expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported") @@ -361,37 +348,30 @@ describe('Test abuses', function () { it('Should delete the video abuse', async function () { this.timeout(10000) - await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) + await commands[1].delete({ abuseId: abuseServer2.id }) await waitJobs(servers) { - const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) - expect(res.body.total).to.equal(1) - expect(res.body.data.length).to.equal(1) - expect(res.body.data[0].id).to.not.equal(abuseServer2.id) + const body = await commands[1].getAdminList() + expect(body.total).to.equal(1) + expect(body.data.length).to.equal(1) + expect(body.data[0].id).to.not.equal(abuseServer2.id) } { - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) - expect(res.body.total).to.equal(6) + const body = await commands[0].getAdminList() + expect(body.total).to.equal(6) } }) it('Should list and filter video abuses', async function () { this.timeout(10000) - async function list (query: Omit[0], 'url' | 'token'>) { - const options = { - url: servers[0].url, - token: servers[0].accessToken - } - - Object.assign(options, query) + async function list (query: Parameters[0]) { + const body = await commands[0].getAdminList(query) - const res = await getAdminAbusesList(options) - - return res.body.data as AdminAbuse[] + return body.data } expect(await list({ id: 56 })).to.have.lengthOf(0) @@ -452,7 +432,7 @@ describe('Test abuses', function () { const comment = await getComment(servers[0].url, servers[0].video.id) const reason = 'it is a bad comment' - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason }) + await commands[0].report({ commentId: comment.id, reason }) await waitJobs(servers) }) @@ -460,12 +440,12 @@ describe('Test abuses', function () { it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () { { const comment = await getComment(servers[0].url, servers[0].video.id) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) + const body = await commands[0].getAdminList({ filter: 'comment' }) - 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 abuse: AdminAbuse = res.body.data[0] + const abuse = body.data[0] expect(abuse.reason).to.equal('it is a bad comment') expect(abuse.reporterAccount.name).to.equal('root') @@ -485,9 +465,9 @@ describe('Test abuses', function () { } { - const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) - expect(res.body.total).to.equal(0) - expect(res.body.data.length).to.equal(0) + const body = await commands[1].getAdminList({ filter: 'comment' }) + expect(body.total).to.equal(0) + expect(body.data.length).to.equal(0) } }) @@ -497,7 +477,7 @@ describe('Test abuses', function () { const comment = await getComment(servers[0].url, servers[1].video.uuid) const reason = 'it is a really bad comment' - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason }) + await commands[0].report({ commentId: comment.id, reason }) await waitJobs(servers) }) @@ -505,54 +485,58 @@ describe('Test abuses', function () { it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { const commentServer2 = await getComment(servers[0].url, servers[1].video.id) - const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) - expect(res1.body.total).to.equal(2) - expect(res1.body.data.length).to.equal(2) + { + const body = await commands[0].getAdminList({ filter: 'comment' }) + expect(body.total).to.equal(2) + expect(body.data.length).to.equal(2) - const abuse: AdminAbuse = res1.body.data[0] - expect(abuse.reason).to.equal('it is a bad comment') - expect(abuse.countReportsForReporter).to.equal(6) - expect(abuse.countReportsForReportee).to.equal(5) + const abuse = body.data[0] + expect(abuse.reason).to.equal('it is a bad comment') + expect(abuse.countReportsForReporter).to.equal(6) + expect(abuse.countReportsForReportee).to.equal(5) - const abuse2: AdminAbuse = res1.body.data[1] + const abuse2 = body.data[1] - expect(abuse2.reason).to.equal('it is a really bad comment') + expect(abuse2.reason).to.equal('it is a really bad comment') - expect(abuse2.reporterAccount.name).to.equal('root') - expect(abuse2.reporterAccount.host).to.equal(servers[0].host) + expect(abuse2.reporterAccount.name).to.equal('root') + expect(abuse2.reporterAccount.host).to.equal(servers[0].host) - expect(abuse2.video).to.be.null + expect(abuse2.video).to.be.null - expect(abuse2.comment.deleted).to.be.false - expect(abuse2.comment.id).to.equal(commentServer2.id) - expect(abuse2.comment.text).to.equal(commentServer2.text) - expect(abuse2.comment.video.name).to.equal('server 2') - expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid) + expect(abuse2.comment.deleted).to.be.false + expect(abuse2.comment.id).to.equal(commentServer2.id) + expect(abuse2.comment.text).to.equal(commentServer2.text) + expect(abuse2.comment.video.name).to.equal('server 2') + expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid) - expect(abuse2.state.id).to.equal(AbuseState.PENDING) - expect(abuse2.state.label).to.equal('Pending') + expect(abuse2.state.id).to.equal(AbuseState.PENDING) + expect(abuse2.state.label).to.equal('Pending') - expect(abuse2.moderationComment).to.be.null + expect(abuse2.moderationComment).to.be.null - expect(abuse2.countReportsForReporter).to.equal(6) - expect(abuse2.countReportsForReportee).to.equal(2) + expect(abuse2.countReportsForReporter).to.equal(6) + expect(abuse2.countReportsForReportee).to.equal(2) + } - const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) - expect(res2.body.total).to.equal(1) - expect(res2.body.data.length).to.equal(1) + { + const body = await commands[1].getAdminList({ filter: 'comment' }) + expect(body.total).to.equal(1) + expect(body.data.length).to.equal(1) - abuseServer2 = res2.body.data[0] - expect(abuseServer2.reason).to.equal('it is a really bad comment') - expect(abuseServer2.reporterAccount.name).to.equal('root') - expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) + abuseServer2 = body.data[0] + expect(abuseServer2.reason).to.equal('it is a really bad comment') + expect(abuseServer2.reporterAccount.name).to.equal('root') + expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) - expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) - expect(abuseServer2.state.label).to.equal('Pending') + expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) + expect(abuseServer2.state.label).to.equal('Pending') - expect(abuseServer2.moderationComment).to.be.null + expect(abuseServer2.moderationComment).to.be.null - expect(abuseServer2.countReportsForReporter).to.equal(1) - expect(abuseServer2.countReportsForReportee).to.equal(1) + expect(abuseServer2.countReportsForReporter).to.equal(1) + expect(abuseServer2.countReportsForReportee).to.equal(1) + } }) it('Should keep the comment abuse when deleting the comment', async function () { @@ -564,11 +548,11 @@ describe('Test abuses', function () { await waitJobs(servers) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + const body = await commands[0].getAdminList({ filter: 'comment' }) + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(2) - const abuse = (res.body.data as AdminAbuse[]).find(a => a.comment?.id === commentServer2.id) + const abuse = body.data.find(a => a.comment?.id === commentServer2.id) expect(abuse).to.not.be.undefined expect(abuse.comment.text).to.be.empty @@ -579,53 +563,43 @@ describe('Test abuses', function () { it('Should delete the comment abuse', async function () { this.timeout(10000) - await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) + await commands[1].delete({ abuseId: abuseServer2.id }) await waitJobs(servers) { - const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) - expect(res.body.total).to.equal(0) - expect(res.body.data.length).to.equal(0) + const body = await commands[1].getAdminList({ filter: 'comment' }) + expect(body.total).to.equal(0) + expect(body.data.length).to.equal(0) } { - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getAdminList({ filter: 'comment' }) + expect(body.total).to.equal(2) } }) it('Should list and filter video abuses', async function () { { - const res = await getAdminAbusesList({ - url: servers[0].url, - token: servers[0].accessToken, - filter: 'comment', - searchReportee: 'foo' - }) - expect(res.body.total).to.equal(0) + const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' }) + expect(body.total).to.equal(0) } { - const res = await getAdminAbusesList({ - url: servers[0].url, - token: servers[0].accessToken, - filter: 'comment', - searchReportee: 'ot' - }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' }) + expect(body.total).to.equal(2) } { - const baseParams = { url: servers[0].url, token: servers[0].accessToken, filter: 'comment' as AbuseFilter, start: 1, count: 1 } - - const res1 = await getAdminAbusesList(immutableAssign(baseParams, { sort: 'createdAt' })) - expect(res1.body.data).to.have.lengthOf(1) - expect(res1.body.data[0].comment.text).to.be.empty + const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' }) + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].comment.text).to.be.empty + } - const res2 = await getAdminAbusesList(immutableAssign(baseParams, { sort: '-createdAt' })) - expect(res2.body.data).to.have.lengthOf(1) - expect(res2.body.data[0].comment.text).to.equal('comment server 1') + { + const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' }) + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].comment.text).to.equal('comment server 1') } }) }) @@ -655,19 +629,19 @@ describe('Test abuses', function () { const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0]) const reason = 'it is a bad account' - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason }) + await commands[0].report({ accountId: account.id, reason }) await waitJobs(servers) }) it('Should have 1 account abuse on server 1 and 0 on server 2', async function () { { - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) + const body = await commands[0].getAdminList({ filter: 'account' }) - 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 abuse: AdminAbuse = res.body.data[0] + const abuse = body.data[0] expect(abuse.reason).to.equal('it is a bad account') expect(abuse.reporterAccount.name).to.equal('root') @@ -681,9 +655,9 @@ describe('Test abuses', function () { } { - const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) - expect(res.body.total).to.equal(0) - expect(res.body.data.length).to.equal(0) + const body = await commands[1].getAdminList({ filter: 'comment' }) + expect(body.total).to.equal(0) + expect(body.data.length).to.equal(0) } }) @@ -693,48 +667,52 @@ describe('Test abuses', function () { const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1]) const reason = 'it is a really bad account' - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason }) + await commands[0].report({ accountId: account.id, reason }) await waitJobs(servers) }) it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { - const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) - expect(res1.body.total).to.equal(2) - expect(res1.body.data.length).to.equal(2) + { + const body = await commands[0].getAdminList({ filter: 'account' }) + expect(body.total).to.equal(2) + expect(body.data.length).to.equal(2) - const abuse: AdminAbuse = res1.body.data[0] - expect(abuse.reason).to.equal('it is a bad account') + const abuse: AdminAbuse = body.data[0] + expect(abuse.reason).to.equal('it is a bad account') - const abuse2: AdminAbuse = res1.body.data[1] - expect(abuse2.reason).to.equal('it is a really bad account') + const abuse2: AdminAbuse = body.data[1] + expect(abuse2.reason).to.equal('it is a really bad account') - expect(abuse2.reporterAccount.name).to.equal('root') - expect(abuse2.reporterAccount.host).to.equal(servers[0].host) + expect(abuse2.reporterAccount.name).to.equal('root') + expect(abuse2.reporterAccount.host).to.equal(servers[0].host) - expect(abuse2.video).to.be.null - expect(abuse2.comment).to.be.null + expect(abuse2.video).to.be.null + expect(abuse2.comment).to.be.null - expect(abuse2.state.id).to.equal(AbuseState.PENDING) - expect(abuse2.state.label).to.equal('Pending') + expect(abuse2.state.id).to.equal(AbuseState.PENDING) + expect(abuse2.state.label).to.equal('Pending') - expect(abuse2.moderationComment).to.be.null + expect(abuse2.moderationComment).to.be.null + } - const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) - expect(res2.body.total).to.equal(1) - expect(res2.body.data.length).to.equal(1) + { + const body = await commands[1].getAdminList({ filter: 'account' }) + expect(body.total).to.equal(1) + expect(body.data.length).to.equal(1) - abuseServer2 = res2.body.data[0] + abuseServer2 = body.data[0] - expect(abuseServer2.reason).to.equal('it is a really bad account') + expect(abuseServer2.reason).to.equal('it is a really bad account') - expect(abuseServer2.reporterAccount.name).to.equal('root') - expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) + expect(abuseServer2.reporterAccount.name).to.equal('root') + expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) - expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) - expect(abuseServer2.state.label).to.equal('Pending') + expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) + expect(abuseServer2.state.label).to.equal('Pending') - expect(abuseServer2.moderationComment).to.be.null + expect(abuseServer2.moderationComment).to.be.null + } }) it('Should keep the account abuse when deleting the account', async function () { @@ -745,32 +723,32 @@ describe('Test abuses', function () { await waitJobs(servers) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + const body = await commands[0].getAdminList({ filter: 'account' }) + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(2) - const abuse = (res.body.data as AdminAbuse[]).find(a => a.reason === 'it is a really bad account') + const abuse = body.data.find(a => a.reason === 'it is a really bad account') expect(abuse).to.not.be.undefined }) it('Should delete the account abuse', async function () { this.timeout(10000) - await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) + await commands[1].delete({ abuseId: abuseServer2.id }) await waitJobs(servers) { - const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) - expect(res.body.total).to.equal(0) - expect(res.body.data.length).to.equal(0) + const body = await commands[1].getAdminList({ filter: 'account' }) + expect(body.total).to.equal(0) + expect(body.data.length).to.equal(0) } { - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getAdminList({ filter: 'account' }) + expect(body.total).to.equal(2) - abuseServer1 = res.body.data[0] + abuseServer1 = body.data[0] } }) }) @@ -778,20 +756,18 @@ describe('Test abuses', function () { describe('Common actions on abuses', function () { it('Should update the state of an abuse', async function () { - const body = { state: AbuseState.REJECTED } - await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body) + await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } }) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) - expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED) + const body = await commands[0].getAdminList({ id: abuseServer1.id }) + expect(body.data[0].state.id).to.equal(AbuseState.REJECTED) }) it('Should add a moderation comment', async function () { - const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' } - await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body) + await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } }) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) - expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED) - expect(res.body.data[0].moderationComment).to.equal('It is valid') + const body = await commands[0].getAdminList({ id: abuseServer1.id }) + expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED) + expect(body.data[0].moderationComment).to.equal('Valid') }) }) @@ -802,18 +778,18 @@ describe('Test abuses', function () { before(async function () { userAccessToken = await generateUserAccessToken(servers[0], 'user_42') - await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) + await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) - await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId, reason: 'user reason 2' }) + await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' }) }) it('Should correctly list my abuses', async function () { { - const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 5, sort: 'createdAt' }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' }) + expect(body.total).to.equal(2) - const abuses: UserAbuse[] = res.body.data + const abuses = body.data expect(abuses[0].reason).to.equal('user reason 1') expect(abuses[1].reason).to.equal('user reason 2') @@ -821,95 +797,77 @@ describe('Test abuses', function () { } { - const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: 'createdAt' }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(2) - const abuses: UserAbuse[] = res.body.data + const abuses: UserAbuse[] = body.data expect(abuses[0].reason).to.equal('user reason 2') } { - const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: '-createdAt' }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' }) + expect(body.total).to.equal(2) - const abuses: UserAbuse[] = res.body.data + const abuses: UserAbuse[] = body.data expect(abuses[0].reason).to.equal('user reason 1') } }) it('Should correctly filter my abuses by id', async function () { - const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, id: abuseId1 }) - - expect(res.body.total).to.equal(1) + const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 }) + expect(body.total).to.equal(1) - const abuses: UserAbuse[] = res.body.data + const abuses: UserAbuse[] = body.data expect(abuses[0].reason).to.equal('user reason 1') }) it('Should correctly filter my abuses by search', async function () { - const res = await getUserAbusesList({ - url: servers[0].url, - token: userAccessToken, - search: 'server 2' - }) - - expect(res.body.total).to.equal(1) + const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' }) + expect(body.total).to.equal(1) - const abuses: UserAbuse[] = res.body.data + const abuses: UserAbuse[] = body.data expect(abuses[0].reason).to.equal('user reason 2') }) it('Should correctly filter my abuses by state', async function () { - const body = { state: AbuseState.REJECTED } - await updateAbuse(servers[0].url, servers[0].accessToken, abuseId1, body) - - const res = await getUserAbusesList({ - url: servers[0].url, - token: userAccessToken, - state: AbuseState.REJECTED - }) + await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } }) - expect(res.body.total).to.equal(1) + const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED }) + expect(body.total).to.equal(1) - const abuses: UserAbuse[] = res.body.data + const abuses: UserAbuse[] = body.data expect(abuses[0].reason).to.equal('user reason 1') }) }) describe('Abuse messages', async function () { let abuseId: number - let userAccessToken: string + let userToken: string let abuseMessageUserId: number let abuseMessageModerationId: number before(async function () { - userAccessToken = await generateUserAccessToken(servers[0], 'user_43') - - const res = await reportAbuse({ - url: servers[0].url, - token: userAccessToken, - videoId: servers[0].video.id, - reason: 'user 43 reason 1' - }) + userToken = await generateUserAccessToken(servers[0], 'user_43') - abuseId = res.body.abuse.id + const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' }) + abuseId = body.abuse.id }) it('Should create some messages on the abuse', async function () { - await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 1') - await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 2') - await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 3') - await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 4') + await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' }) + await commands[0].addMessage({ abuseId, message: 'message 2' }) + await commands[0].addMessage({ abuseId, message: 'message 3' }) + await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' }) }) it('Should have the correct messages count when listing abuses', async function () { const results = await Promise.all([ - getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, start: 0, count: 50 }), - getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 50 }) + commands[0].getAdminList({ start: 0, count: 50 }), + commands[0].getUserList({ token: userToken, start: 0, count: 50 }) ]) - for (const res of results) { - const abuses: AdminAbuse[] = res.body.data + for (const body of results) { + const abuses = body.data const abuse = abuses.find(a => a.id === abuseId) expect(abuse.countMessages).to.equal(4) } @@ -917,14 +875,14 @@ describe('Test abuses', function () { it('Should correctly list messages of this abuse', async function () { const results = await Promise.all([ - listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId), - listAbuseMessages(servers[0].url, userAccessToken, abuseId) + commands[0].listMessages({ abuseId }), + commands[0].listMessages({ token: userToken, abuseId }) ]) - for (const res of results) { - expect(res.body.total).to.equal(4) + for (const body of results) { + expect(body.total).to.equal(4) - const abuseMessages: AbuseMessage[] = res.body.data + const abuseMessages: AbuseMessage[] = body.data expect(abuseMessages[0].message).to.equal('message 1') expect(abuseMessages[0].byModerator).to.be.false @@ -948,19 +906,18 @@ describe('Test abuses', function () { }) it('Should delete messages', async function () { - await deleteAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, abuseMessageModerationId) - await deleteAbuseMessage(servers[0].url, userAccessToken, abuseId, abuseMessageUserId) + await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId }) + await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId }) const results = await Promise.all([ - listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId), - listAbuseMessages(servers[0].url, userAccessToken, abuseId) + commands[0].listMessages({ abuseId }), + commands[0].listMessages({ token: userToken, abuseId }) ]) - for (const res of results) { - expect(res.body.total).to.equal(2) - - const abuseMessages: AbuseMessage[] = res.body.data + for (const body of results) { + expect(body.total).to.equal(2) + const abuseMessages: AbuseMessage[] = body.data expect(abuseMessages[0].message).to.equal('message 2') expect(abuseMessages[1].message).to.equal('message 4') } -- cgit v1.2.3 From af971e06c620bd46a5aa64c8833364e7022b5e3d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 15:22:51 +0200 Subject: Introduce search command --- server/tests/api/moderation/video-blacklist.ts | 31 ++++++++++++-------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index 52cac20d9..4a4930c98 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -7,6 +7,7 @@ import { addVideoToBlacklist, cleanupTests, createUser, + doubleFollow, flushAndRunMultipleServers, getBlacklistedVideosList, getMyUserInformation, @@ -15,20 +16,16 @@ import { killallServers, removeVideoFromBlacklist, reRunServer, - searchVideo, ServerInfo, setAccessTokensToServers, updateVideo, updateVideoBlacklist, uploadVideo, - userLogin -} from '../../../../shared/extra-utils/index' -import { doubleFollow } from '../../../../shared/extra-utils/server/follows' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { getGoodVideoUrl, getMagnetURI, importVideo } from '../../../../shared/extra-utils/videos/video-imports' -import { User, UserRole } from '../../../../shared/models/users' -import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' -import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos' + userLogin, + waitJobs +} from '@shared/extra-utils' +import { getGoodVideoUrl, getMagnetURI, importVideo } from '@shared/extra-utils/videos/video-imports' +import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' const expect = chai.expect @@ -80,11 +77,11 @@ describe('Test video blacklist', function () { } { - const res = await searchVideo(servers[0].url, 'name') + const body = await servers[0].searchCommand.searchVideos({ search: 'name' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) } }) @@ -98,11 +95,11 @@ describe('Test video blacklist', function () { } { - const res = await searchVideo(servers[1].url, 'video') + const body = await servers[1].searchCommand.searchVideos({ search: 'name' }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(2) + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(2) } }) }) -- cgit v1.2.3 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 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'server/tests/api/moderation') 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) -- cgit v1.2.3 From 9fff08cf83f34339df7ed4ac770e1dee536adf9d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 13:38:26 +0200 Subject: Introduce accounts command --- server/tests/api/moderation/abuses.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index a9f5332ce..124833cf6 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -13,7 +13,6 @@ import { doubleFollow, flushAndRunMultipleServers, generateUserAccessToken, - getAccount, getVideoCommentThreads, getVideoIdFromUUID, getVideosList, @@ -606,10 +605,8 @@ describe('Test abuses', function () { describe('Account abuses', function () { - async function getAccountFromServer (url: string, name: string, server: ServerInfo) { - const res = await getAccount(url, name + '@' + server.host) - - return res.body as Account + function getAccountFromServer (server: ServerInfo, targetName: string, targetServer: ServerInfo) { + return server.accountsCommand.get({ accountName: targetName + '@' + targetServer.host }) } before(async function () { @@ -626,7 +623,7 @@ describe('Test abuses', function () { it('Should report abuse on an account', async function () { this.timeout(15000) - const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0]) + const account = await getAccountFromServer(servers[0], 'user_1', servers[0]) const reason = 'it is a bad account' await commands[0].report({ accountId: account.id, reason }) @@ -664,7 +661,7 @@ describe('Test abuses', function () { it('Should report abuse on a remote account', async function () { this.timeout(10000) - const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1]) + const account = await getAccountFromServer(servers[0], 'user_2', servers[1]) const reason = 'it is a really bad account' await commands[0].report({ accountId: account.id, reason }) @@ -718,7 +715,7 @@ describe('Test abuses', function () { it('Should keep the account abuse when deleting the account', async function () { this.timeout(10000) - const account = await getAccountFromServer(servers[1].url, 'user_2', servers[1]) + const account = await getAccountFromServer(servers[1], 'user_2', servers[1]) await removeUser(servers[1].url, account.userId, servers[1].accessToken) await waitJobs(servers) -- cgit v1.2.3 From 5f8bd4cbb178290da7d8f81e996f19f0eccc8e4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 16:02:46 +0200 Subject: Introduce blocklist command --- server/tests/api/moderation/abuses.ts | 14 ++- .../tests/api/moderation/blocklist-notification.ts | 41 ++++----- server/tests/api/moderation/blocklist.ts | 100 ++++++++------------- 3 files changed, 59 insertions(+), 96 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index 124833cf6..a2bd07b12 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -4,8 +4,6 @@ import 'mocha' import * as chai from 'chai' import { AbusesCommand, - addAccountToServerBlocklist, - addServerToServerBlocklist, addVideoCommentThread, cleanupTests, createUser, @@ -16,8 +14,6 @@ import { getVideoCommentThreads, getVideoIdFromUUID, getVideosList, - removeAccountFromServerBlocklist, - removeServerFromServerBlocklist, removeUser, removeVideo, ServerInfo, @@ -27,7 +23,7 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, Account, AdminAbuse, UserAbuse, VideoComment } from '@shared/models' +import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse, VideoComment } from '@shared/models' const expect = chai.expect @@ -225,7 +221,7 @@ describe('Test abuses', function () { const accountToBlock = 'root@' + servers[1].host { - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) + await servers[0].blocklistCommand.addToServerBlocklist({ account: accountToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(2) @@ -235,7 +231,7 @@ describe('Test abuses', function () { } { - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) + await servers[0].blocklistCommand.removeFromServerBlocklist({ account: accountToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(3) @@ -246,7 +242,7 @@ describe('Test abuses', function () { const serverToBlock = servers[1].host { - await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) + await servers[0].blocklistCommand.addToServerBlocklist({ server: serverToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(2) @@ -256,7 +252,7 @@ describe('Test abuses', function () { } { - await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) + await servers[0].blocklistCommand.removeFromServerBlocklist({ server: serverToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(3) diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index 4fb3c95f2..99da64a2d 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -2,30 +2,23 @@ import 'mocha' import * as chai from 'chai' -import { getUserNotifications, markAsReadAllNotifications } from '@shared/extra-utils/users/user-notifications' -import { addUserSubscription, removeUserSubscription } from '@shared/extra-utils/users/user-subscriptions' -import { UserNotification, UserNotificationType } from '@shared/models' import { + addUserSubscription, + addVideoCommentThread, cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, + getUserNotifications, + markAsReadAllNotifications, + removeUserSubscription, ServerInfo, + setAccessTokensToServers, uploadVideo, - userLogin -} from '../../../../shared/extra-utils/index' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - addAccountToAccountBlocklist, - addAccountToServerBlocklist, - addServerToAccountBlocklist, - addServerToServerBlocklist, - removeAccountFromAccountBlocklist, - removeAccountFromServerBlocklist, - removeServerFromAccountBlocklist -} from '../../../../shared/extra-utils/users/blocklist' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' -import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' + userLogin, + waitJobs +} from '@shared/extra-utils' +import { UserNotification, UserNotificationType } from '@shared/models' const expect = chai.expect @@ -134,7 +127,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await addAccountToAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host) + await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) await waitJobs(servers) }) @@ -147,7 +140,7 @@ describe('Test blocklist', function () { await checkNotifications(servers[0].url, userToken2, notifs) - await removeAccountFromAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host) + await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) }) }) @@ -167,7 +160,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await addServerToAccountBlocklist(servers[0].url, userToken1, servers[1].host) + await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host }) await waitJobs(servers) }) @@ -180,7 +173,7 @@ describe('Test blocklist', function () { await checkNotifications(servers[0].url, userToken2, notifs) - await removeServerFromAccountBlocklist(servers[0].url, userToken1, servers[1].host) + await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host }) }) }) @@ -207,7 +200,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host) + await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host }) await waitJobs(servers) }) @@ -215,7 +208,7 @@ describe('Test blocklist', function () { await checkNotifications(servers[0].url, userToken1, []) await checkNotifications(servers[0].url, userToken2, []) - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host) + await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host }) }) }) @@ -242,7 +235,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) + await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host }) await waitJobs(servers) }) diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 9ca6324c2..1b8860571 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -3,46 +3,27 @@ import 'mocha' import * as chai from 'chai' import { - addAccountToAccountBlocklist, - addAccountToServerBlocklist, - addServerToAccountBlocklist, - addServerToServerBlocklist, addVideoCommentReply, addVideoCommentThread, + BlocklistCommand, cleanupTests, createUser, deleteVideoComment, doubleFollow, findCommentId, flushAndRunMultipleServers, - getAccountBlocklistByAccount, - getAccountBlocklistByServer, - getServerBlocklistByAccount, - getServerBlocklistByServer, getUserNotifications, getVideoCommentThreads, getVideosList, getVideosListWithToken, getVideoThreadComments, - removeAccountFromAccountBlocklist, - removeAccountFromServerBlocklist, - removeServerFromAccountBlocklist, - removeServerFromServerBlocklist, ServerInfo, setAccessTokensToServers, uploadVideo, userLogin, waitJobs } from '@shared/extra-utils' -import { - AccountBlock, - ServerBlock, - UserNotification, - UserNotificationType, - Video, - VideoComment, - VideoCommentThreadTree -} from '@shared/models' +import { UserNotification, UserNotificationType, Video, VideoComment, VideoCommentThreadTree } from '@shared/models' const expect = chai.expect @@ -108,6 +89,8 @@ describe('Test blocklist', function () { let userModeratorToken: string let userToken2: string + let command: BlocklistCommand + before(async function () { this.timeout(120000) @@ -167,6 +150,8 @@ describe('Test blocklist', function () { } await waitJobs(servers) + + command = servers[0].blocklistCommand }) describe('User blocklist', function () { @@ -181,7 +166,7 @@ describe('Test blocklist', function () { }) it('Should block a remote account', async function () { - await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + await command.addToMyBlocklist({ account: 'user2@localhost:' + servers[1].port }) }) it('Should hide its videos', async function () { @@ -195,7 +180,7 @@ describe('Test blocklist', function () { }) it('Should block a local account', async function () { - await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') + await command.addToMyBlocklist({ account: 'user1' }) }) it('Should hide its videos', async function () { @@ -251,12 +236,10 @@ describe('Test blocklist', function () { it('Should list blocked accounts', async function () { { - const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') - const blocks: AccountBlock[] = res.body.data + const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(2) - expect(res.body.total).to.equal(2) - - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('root') expect(block.byAccount.name).to.equal('root') expect(block.blockedAccount.displayName).to.equal('user2') @@ -265,12 +248,10 @@ describe('Test blocklist', function () { } { - const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt') - const blocks: AccountBlock[] = res.body.data - - expect(res.body.total).to.equal(2) + const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' }) + expect(body.total).to.equal(2) - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('root') expect(block.byAccount.name).to.equal('root') expect(block.blockedAccount.displayName).to.equal('user1') @@ -335,7 +316,7 @@ describe('Test blocklist', function () { }) it('Should unblock the remote account', async function () { - await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + await command.removeFromMyBlocklist({ account: 'user2@localhost:' + servers[1].port }) }) it('Should display its videos', async function () { @@ -374,7 +355,7 @@ describe('Test blocklist', function () { }) it('Should unblock the local account', async function () { - await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') + await command.removeFromMyBlocklist({ account: 'user1' }) }) it('Should display its comments', function () { @@ -402,6 +383,7 @@ describe('Test blocklist', function () { }) describe('When managing server blocklist', function () { + it('Should list all videos', function () { return checkAllVideos(servers[0].url, servers[0].accessToken) }) @@ -411,7 +393,7 @@ describe('Test blocklist', function () { }) it('Should block a remote server', async function () { - await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.addToMyBlocklist({ server: 'localhost:' + servers[1].port }) }) it('Should hide its videos', async function () { @@ -464,19 +446,17 @@ describe('Test blocklist', function () { }) it('Should list blocked servers', async function () { - const res = await getServerBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') - const blocks: ServerBlock[] = res.body.data - - expect(res.body.total).to.equal(1) + const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(1) - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('root') expect(block.byAccount.name).to.equal('root') expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) }) it('Should unblock the remote server', async function () { - await removeServerFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port }) }) it('Should display its videos', function () { @@ -524,7 +504,7 @@ describe('Test blocklist', function () { }) it('Should block a remote account', async function () { - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + await command.addToServerBlocklist({ account: 'user2@localhost:' + servers[1].port }) }) it('Should hide its videos', async function () { @@ -540,7 +520,7 @@ describe('Test blocklist', function () { }) it('Should block a local account', async function () { - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') + await command.addToServerBlocklist({ account: 'user1' }) }) it('Should hide its videos', async function () { @@ -598,12 +578,10 @@ describe('Test blocklist', function () { it('Should list blocked accounts', async function () { { - const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') - const blocks: AccountBlock[] = res.body.data - - expect(res.body.total).to.equal(2) + const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(2) - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('peertube') expect(block.byAccount.name).to.equal('peertube') expect(block.blockedAccount.displayName).to.equal('user2') @@ -612,12 +590,10 @@ describe('Test blocklist', function () { } { - const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt') - const blocks: AccountBlock[] = res.body.data + const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' }) + expect(body.total).to.equal(2) - expect(res.body.total).to.equal(2) - - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('peertube') expect(block.byAccount.name).to.equal('peertube') expect(block.blockedAccount.displayName).to.equal('user1') @@ -627,7 +603,7 @@ describe('Test blocklist', function () { }) it('Should unblock the remote account', async function () { - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port }) }) it('Should display its videos', async function () { @@ -643,7 +619,7 @@ describe('Test blocklist', function () { }) it('Should unblock the local account', async function () { - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') + await command.removeFromServerBlocklist({ account: 'user1' }) }) it('Should display its comments', async function () { @@ -686,7 +662,7 @@ describe('Test blocklist', function () { }) it('Should block a remote server', async function () { - await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port }) }) it('Should hide its videos', async function () { @@ -758,19 +734,17 @@ describe('Test blocklist', function () { }) it('Should list blocked servers', async function () { - const res = await getServerBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') - const blocks: ServerBlock[] = res.body.data - - expect(res.body.total).to.equal(1) + const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(1) - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('peertube') expect(block.byAccount.name).to.equal('peertube') expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) }) it('Should unblock the remote server', async function () { - await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port }) }) it('Should list all videos', async function () { -- cgit v1.2.3 From 2c27e70471120c92e0bc8c8114141fbb31ff98ac Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 16:40:49 +0200 Subject: Introduce subscriptions command --- server/tests/api/moderation/blocklist-notification.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index 99da64a2d..5b9699816 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -3,7 +3,6 @@ import 'mocha' import * as chai from 'chai' import { - addUserSubscription, addVideoCommentThread, cleanupTests, createUser, @@ -11,7 +10,6 @@ import { flushAndRunMultipleServers, getUserNotifications, markAsReadAllNotifications, - removeUserSubscription, ServerInfo, setAccessTokensToServers, uploadVideo, @@ -44,8 +42,8 @@ describe('Test blocklist', function () { async function resetState () { try { - await removeUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host) - await removeUserSubscription(servers[1].url, remoteUserToken, 'user2_channel@' + servers[0].host) + await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host }) + await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host }) } catch {} await waitJobs(servers) @@ -66,8 +64,8 @@ describe('Test blocklist', function () { { - await addUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host) - await addUserSubscription(servers[1].url, remoteUserToken, 'user2_channel@' + servers[0].host) + await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host }) + await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host }) } await waitJobs(servers) -- cgit v1.2.3 From e3d15a6a9aed97a004d9dac1b7a6499d794e080a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 11:17:55 +0200 Subject: Introduce blacklist command --- server/tests/api/moderation/video-blacklist.ts | 144 ++++++++++--------------- 1 file changed, 54 insertions(+), 90 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index 4a4930c98..17a68e4a6 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -4,22 +4,19 @@ import 'mocha' import * as chai from 'chai' import { orderBy } from 'lodash' import { - addVideoToBlacklist, + BlacklistCommand, cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, - getBlacklistedVideosList, getMyUserInformation, getMyVideos, getVideosList, killallServers, - removeVideoFromBlacklist, reRunServer, ServerInfo, setAccessTokensToServers, updateVideo, - updateVideoBlacklist, uploadVideo, userLogin, waitJobs @@ -32,13 +29,14 @@ const expect = chai.expect describe('Test video blacklist', function () { let servers: ServerInfo[] = [] let videoId: number + let command: BlacklistCommand async function blacklistVideosOnServer (server: ServerInfo) { const res = await getVideosList(server.url) const videos = res.body.data for (const video of videos) { - await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason') + await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' }) } } @@ -61,6 +59,8 @@ describe('Test video blacklist', function () { // Wait videos propagation, server 2 has transcoding enabled await waitJobs(servers) + command = servers[0].blacklistCommand + // Blacklist the two videos on server 1 await blacklistVideosOnServer(servers[0]) }) @@ -77,7 +77,7 @@ describe('Test video blacklist', function () { } { - const body = await servers[0].searchCommand.searchVideos({ search: 'name' }) + const body = await servers[0].searchCommand.searchVideos({ search: 'video' }) expect(body.total).to.equal(0) expect(body.data).to.be.an('array') @@ -95,7 +95,7 @@ describe('Test video blacklist', function () { } { - const body = await servers[1].searchCommand.searchVideos({ search: 'name' }) + const body = await servers[1].searchCommand.searchVideos({ search: 'video' }) expect(body.total).to.equal(2) expect(body.data).to.be.an('array') @@ -106,11 +106,10 @@ describe('Test video blacklist', function () { describe('When listing manually blacklisted videos', function () { it('Should display all the blacklisted videos', async function () { - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken }) - - expect(res.body.total).to.equal(2) + const body = await command.list() + expect(body.total).to.equal(2) - const blacklistedVideos = res.body.data + const blacklistedVideos = body.data expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos.length).to.equal(2) @@ -121,79 +120,66 @@ describe('Test video blacklist', function () { }) it('Should display all the blacklisted videos when applying manual type filter', async function () { - const res = await getBlacklistedVideosList({ - url: servers[0].url, - token: servers[0].accessToken, - type: VideoBlacklistType.MANUAL - }) + const body = await command.list({ type: VideoBlacklistType.MANUAL }) + expect(body.total).to.equal(2) - expect(res.body.total).to.equal(2) - - const blacklistedVideos = res.body.data + const blacklistedVideos = body.data expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos.length).to.equal(2) }) it('Should display nothing when applying automatic type filter', async function () { - const res = await getBlacklistedVideosList({ - url: servers[0].url, - token: servers[0].accessToken, - type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED - }) + const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) + expect(body.total).to.equal(0) - expect(res.body.total).to.equal(0) - - const blacklistedVideos = res.body.data + const blacklistedVideos = body.data expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos.length).to.equal(0) }) it('Should get the correct sort when sorting by descending id', async function () { - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-id' }) - expect(res.body.total).to.equal(2) + const body = await command.list({ sort: '-id' }) + expect(body.total).to.equal(2) - const blacklistedVideos = res.body.data + const blacklistedVideos = body.data expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos.length).to.equal(2) - const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ]) - + const result = orderBy(body.data, [ 'id' ], [ 'desc' ]) expect(blacklistedVideos).to.deep.equal(result) }) it('Should get the correct sort when sorting by descending video name', async function () { - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) - expect(res.body.total).to.equal(2) + const body = await command.list({ sort: '-name' }) + expect(body.total).to.equal(2) - const blacklistedVideos = res.body.data + const blacklistedVideos = body.data expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos.length).to.equal(2) - const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ]) - + const result = orderBy(body.data, [ 'name' ], [ 'desc' ]) expect(blacklistedVideos).to.deep.equal(result) }) it('Should get the correct sort when sorting by ascending creation date', async function () { - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' }) - expect(res.body.total).to.equal(2) + const body = await command.list({ sort: 'createdAt' }) + expect(body.total).to.equal(2) - const blacklistedVideos = res.body.data + const blacklistedVideos = body.data expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos.length).to.equal(2) - const result = orderBy(res.body.data, [ 'createdAt' ]) - + const result = orderBy(body.data, [ 'createdAt' ]) expect(blacklistedVideos).to.deep.equal(result) }) }) describe('When updating blacklisted videos', function () { it('Should change the reason', async function () { - await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') + await command.update({ videoId, reason: 'my super reason updated' }) - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) - const video = res.body.data.find(b => b.video.id === videoId) + const body = await command.list({ sort: '-name' }) + const video = body.data.find(b => b.video.id === videoId) expect(video.reason).to.equal('my super reason updated') }) @@ -228,12 +214,12 @@ describe('Test video blacklist', function () { it('Should remove a video from the blacklist on server 1', async function () { // Get one video in the blacklist - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) - videoToRemove = res.body.data[0] - blacklist = res.body.data.slice(1) + const body = await command.list({ sort: '-name' }) + videoToRemove = body.data[0] + blacklist = body.data.slice(1) // Remove it - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id) + await command.remove({ videoId: videoToRemove.video.id }) }) it('Should have the ex-blacklisted video in videos list on server 1', async function () { @@ -249,10 +235,10 @@ describe('Test video blacklist', function () { }) it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) - expect(res.body.total).to.equal(1) + const body = await command.list({ sort: '-name' }) + expect(body.total).to.equal(1) - const videos = res.body.data + const videos = body.data expect(videos).to.be.an('array') expect(videos.length).to.equal(1) expect(videos).to.deep.equal(blacklist) @@ -281,7 +267,7 @@ describe('Test video blacklist', function () { it('Should blacklist video 3 and keep it federated', async function () { this.timeout(10000) - await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video3UUID, 'super reason', false) + await command.add({ videoId: video3UUID, reason: 'super reason', unfederate: false }) await waitJobs(servers) @@ -299,7 +285,7 @@ describe('Test video blacklist', function () { it('Should unfederate the video', async function () { this.timeout(10000) - await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video4UUID, 'super reason', true) + await command.add({ videoId: video4UUID, reason: 'super reason', unfederate: true }) await waitJobs(servers) @@ -323,9 +309,9 @@ describe('Test video blacklist', function () { }) it('Should have the correct video blacklist unfederate attribute', async function () { - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' }) + const body = await command.list({ sort: 'createdAt' }) - const blacklistedVideos: VideoBlacklist[] = res.body.data + const blacklistedVideos = body.data const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID) @@ -336,7 +322,7 @@ describe('Test video blacklist', function () { it('Should remove the video from blacklist and refederate the video', async function () { this.timeout(10000) - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video4UUID) + await command.remove({ videoId: video4UUID }) await waitJobs(servers) @@ -407,14 +393,9 @@ describe('Test video blacklist', function () { it('Should auto blacklist a video on upload', async function () { await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) - const res = await getBlacklistedVideosList({ - url: servers[0].url, - token: servers[0].accessToken, - type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED - }) - - expect(res.body.total).to.equal(1) - expect(res.body.data[0].video.name).to.equal('blacklisted') + const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) + expect(body.total).to.equal(1) + expect(body.data[0].video.name).to.equal('blacklisted') }) it('Should auto blacklist a video on URL import', async function () { @@ -427,15 +408,9 @@ describe('Test video blacklist', function () { } await importVideo(servers[0].url, userWithoutFlag, attributes) - const res = await getBlacklistedVideosList({ - url: servers[0].url, - token: servers[0].accessToken, - sort: 'createdAt', - type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED - }) - - expect(res.body.total).to.equal(2) - expect(res.body.data[1].video.name).to.equal('URL import') + const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) + expect(body.total).to.equal(2) + expect(body.data[1].video.name).to.equal('URL import') }) it('Should auto blacklist a video on torrent import', async function () { @@ -446,27 +421,16 @@ describe('Test video blacklist', function () { } await importVideo(servers[0].url, userWithoutFlag, attributes) - const res = await getBlacklistedVideosList({ - url: servers[0].url, - token: servers[0].accessToken, - sort: 'createdAt', - type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED - }) - - expect(res.body.total).to.equal(3) - expect(res.body.data[2].video.name).to.equal('Torrent import') + const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) + expect(body.total).to.equal(3) + expect(body.data[2].video.name).to.equal('Torrent import') }) it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) - const res = await getBlacklistedVideosList({ - url: servers[0].url, - token: servers[0].accessToken, - type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED - }) - - expect(res.body.total).to.equal(3) + const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) + expect(body.total).to.equal(3) }) }) -- cgit v1.2.3 From 6910f20f114b5bd020258a3a9a3f2117819a60c2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 16:49:51 +0200 Subject: Introduce import command --- server/tests/api/moderation/video-blacklist.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index 17a68e4a6..c72ebc16b 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -12,6 +12,7 @@ import { getMyUserInformation, getMyVideos, getVideosList, + ImportsCommand, killallServers, reRunServer, ServerInfo, @@ -21,7 +22,6 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { getGoodVideoUrl, getMagnetURI, importVideo } from '@shared/extra-utils/videos/video-imports' import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' const expect = chai.expect @@ -402,11 +402,11 @@ describe('Test video blacklist', function () { this.timeout(15000) const attributes = { - targetUrl: getGoodVideoUrl(), + targetUrl: ImportsCommand.getGoodVideoUrl(), name: 'URL import', channelId: channelOfUserWithoutFlag } - await importVideo(servers[0].url, userWithoutFlag, attributes) + await servers[0].importsCommand.importVideo({ token: userWithoutFlag, attributes }) const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(2) @@ -415,11 +415,11 @@ describe('Test video blacklist', function () { it('Should auto blacklist a video on torrent import', async function () { const attributes = { - magnetUri: getMagnetURI(), + magnetUri: ImportsCommand.getMagnetURI(), name: 'Torrent import', channelId: channelOfUserWithoutFlag } - await importVideo(servers[0].url, userWithoutFlag, attributes) + await servers[0].importsCommand.importVideo({ token: userWithoutFlag, attributes }) const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(3) -- cgit v1.2.3 From 12edc1495a36b2199f1bf1ba37f50c7b694be382 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 14:15:11 +0200 Subject: Introduce comments command --- server/tests/api/moderation/abuses.ts | 29 ++- .../tests/api/moderation/blocklist-notification.ts | 7 +- server/tests/api/moderation/blocklist.ts | 196 ++++++++++----------- 3 files changed, 110 insertions(+), 122 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index a2bd07b12..e428cf1a8 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -4,14 +4,11 @@ import 'mocha' import * as chai from 'chai' import { AbusesCommand, - addVideoCommentThread, cleanupTests, createUser, - deleteVideoComment, doubleFollow, flushAndRunMultipleServers, generateUserAccessToken, - getVideoCommentThreads, getVideoIdFromUUID, getVideosList, removeUser, @@ -23,7 +20,7 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse, VideoComment } from '@shared/models' +import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' const expect = chai.expect @@ -399,14 +396,14 @@ describe('Test abuses', function () { describe('Comment abuses', function () { - async function getComment (url: string, videoIdArg: number | string) { + async function getComment (server: ServerInfo, videoIdArg: number | string) { const videoId = typeof videoIdArg === 'string' - ? await getVideoIdFromUUID(url, videoIdArg) + ? await getVideoIdFromUUID(server.url, videoIdArg) : videoIdArg - const res = await getVideoCommentThreads(url, videoId, 0, 5) + const { data } = await server.commentsCommand.listThreads({ videoId }) - return res.body.data[0] as VideoComment + return data[0] } before(async function () { @@ -415,8 +412,8 @@ describe('Test abuses', function () { servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' }) servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' }) - await addVideoCommentThread(servers[0].url, servers[0].accessToken, servers[0].video.id, 'comment server 1') - await addVideoCommentThread(servers[1].url, servers[1].accessToken, servers[1].video.id, 'comment server 2') + await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' }) + await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' }) await waitJobs(servers) }) @@ -424,7 +421,7 @@ describe('Test abuses', function () { it('Should report abuse on a comment', async function () { this.timeout(15000) - const comment = await getComment(servers[0].url, servers[0].video.id) + const comment = await getComment(servers[0], servers[0].video.id) const reason = 'it is a bad comment' await commands[0].report({ commentId: comment.id, reason }) @@ -434,7 +431,7 @@ describe('Test abuses', function () { it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () { { - const comment = await getComment(servers[0].url, servers[0].video.id) + const comment = await getComment(servers[0], servers[0].video.id) const body = await commands[0].getAdminList({ filter: 'comment' }) expect(body.total).to.equal(1) @@ -469,7 +466,7 @@ describe('Test abuses', function () { it('Should report abuse on a remote comment', async function () { this.timeout(10000) - const comment = await getComment(servers[0].url, servers[1].video.uuid) + const comment = await getComment(servers[0], servers[1].video.uuid) const reason = 'it is a really bad comment' await commands[0].report({ commentId: comment.id, reason }) @@ -478,7 +475,7 @@ describe('Test abuses', function () { }) it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { - const commentServer2 = await getComment(servers[0].url, servers[1].video.id) + const commentServer2 = await getComment(servers[0], servers[1].video.id) { const body = await commands[0].getAdminList({ filter: 'comment' }) @@ -537,9 +534,9 @@ describe('Test abuses', function () { it('Should keep the comment abuse when deleting the comment', async function () { this.timeout(10000) - const commentServer2 = await getComment(servers[0].url, servers[1].video.id) + const commentServer2 = await getComment(servers[0], servers[1].video.id) - await deleteVideoComment(servers[0].url, servers[0].accessToken, servers[1].video.uuid, commentServer2.id) + await servers[0].commentsCommand.delete({ videoId: servers[1].video.uuid, commentId: commentServer2.id }) await waitJobs(servers) diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index 5b9699816..a077d8739 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -3,7 +3,6 @@ import 'mocha' import * as chai from 'chai' import { - addVideoCommentThread, cleanupTests, createUser, doubleFollow, @@ -59,7 +58,11 @@ describe('Test blocklist', function () { } { - await addVideoCommentThread(servers[1].url, remoteUserToken, videoUUID, '@user2@' + servers[0].host + ' hello') + await servers[1].commentsCommand.createThread({ + token: remoteUserToken, + videoId: videoUUID, + text: '@user2@' + servers[0].host + ' hello' + }) } { diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 1b8860571..00cb6c65c 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -3,55 +3,47 @@ import 'mocha' import * as chai from 'chai' import { - addVideoCommentReply, - addVideoCommentThread, BlocklistCommand, cleanupTests, + CommentsCommand, createUser, - deleteVideoComment, doubleFollow, - findCommentId, flushAndRunMultipleServers, getUserNotifications, - getVideoCommentThreads, getVideosList, getVideosListWithToken, - getVideoThreadComments, ServerInfo, setAccessTokensToServers, uploadVideo, userLogin, waitJobs } from '@shared/extra-utils' -import { UserNotification, UserNotificationType, Video, VideoComment, VideoCommentThreadTree } from '@shared/models' +import { UserNotification, UserNotificationType, Video } from '@shared/models' const expect = chai.expect -async function checkAllVideos (url: string, token: string) { +async function checkAllVideos (server: ServerInfo, token: string) { { - const res = await getVideosListWithToken(url, token) + const res = await getVideosListWithToken(server.url, token) expect(res.body.data).to.have.lengthOf(5) } { - const res = await getVideosList(url) + const res = await getVideosList(server.url) expect(res.body.data).to.have.lengthOf(5) } } -async function checkAllComments (url: string, token: string, videoUUID: string) { - const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 25, '-createdAt', token) +async function checkAllComments (server: ServerInfo, token: string, videoUUID: string) { + const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token }) - const allThreads: VideoComment[] = resThreads.body.data - const threads = allThreads.filter(t => t.isDeleted === false) + const threads = data.filter(t => t.isDeleted === false) expect(threads).to.have.lengthOf(2) for (const thread of threads) { - const res = await getVideoThreadComments(url, videoUUID, thread.id, token) - - const tree: VideoCommentThreadTree = res.body + const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId: thread.id, token }) expect(tree.children).to.have.lengthOf(1) } } @@ -61,10 +53,9 @@ async function checkCommentNotification ( comment: { server: ServerInfo, token: string, videoUUID: string, text: string }, check: 'presence' | 'absence' ) { - const resComment = await addVideoCommentThread(comment.server.url, comment.token, comment.videoUUID, comment.text) - const created = resComment.body.comment as VideoComment - const threadId = created.id - const createdAt = created.createdAt + const command = comment.server.commentsCommand + + const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text }) await waitJobs([ mainServer, comment.server ]) @@ -75,7 +66,7 @@ async function checkCommentNotification ( if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) else expect(commentNotifications).to.have.lengthOf(0) - await deleteVideoComment(comment.server.url, comment.token, comment.videoUUID, threadId) + await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId }) await waitJobs([ mainServer, comment.server ]) } @@ -90,6 +81,7 @@ describe('Test blocklist', function () { let userToken2: string let command: BlocklistCommand + let commentsCommand: CommentsCommand[] before(async function () { this.timeout(120000) @@ -97,6 +89,9 @@ describe('Test blocklist', function () { servers = await flushAndRunMultipleServers(3) await setAccessTokensToServers(servers) + command = servers[0].blocklistCommand + commentsCommand = servers.map(s => s.commentsCommand) + { const user = { username: 'user1', password: 'password' } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) @@ -139,30 +134,33 @@ describe('Test blocklist', function () { await doubleFollow(servers[0], servers[2]) { - const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID1, 'comment root 1') - const resReply = await addVideoCommentReply(servers[0].url, userToken1, videoUUID1, resComment.body.comment.id, 'comment user 1') - await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resReply.body.comment.id, 'comment root 1') + const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' }) + const reply = await commentsCommand[0].addReply({ + token: userToken1, + videoId: videoUUID1, + toCommentId: created.id, + text: 'comment user 1' + }) + await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' }) } { - const resComment = await addVideoCommentThread(servers[0].url, userToken1, videoUUID1, 'comment user 1') - await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resComment.body.comment.id, 'comment root 1') + const created = await commentsCommand[0].createThread({ token: userToken1, videoId: videoUUID1, text: 'comment user 1' }) + await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: created.id, text: 'comment root 1' }) } await waitJobs(servers) - - command = servers[0].blocklistCommand }) describe('User blocklist', function () { describe('When managing account blocklist', function () { it('Should list all videos', function () { - return checkAllVideos(servers[0].url, servers[0].accessToken) + return checkAllVideos(servers[0], servers[0].accessToken) }) it('Should list the comments', function () { - return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + return checkAllComments(servers[0], servers[0].accessToken, videoUUID1) }) it('Should block a remote account', async function () { @@ -194,19 +192,26 @@ describe('Test blocklist', function () { }) it('Should hide its comments', async function () { - const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 25, '-createdAt', servers[0].accessToken) - - const threads: VideoComment[] = resThreads.body.data - expect(threads).to.have.lengthOf(1) - expect(threads[0].totalReplies).to.equal(1) - - const t = threads.find(t => t.text === 'comment user 1') + const { data } = await commentsCommand[0].listThreads({ + token: servers[0].accessToken, + videoId: videoUUID1, + start: 0, + count: 25, + sort: '-createdAt' + }) + + expect(data).to.have.lengthOf(1) + expect(data[0].totalReplies).to.equal(1) + + const t = data.find(t => t.text === 'comment user 1') expect(t).to.be.undefined - for (const thread of threads) { - const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, servers[0].accessToken) - - const tree: VideoCommentThreadTree = res.body + for (const thread of data) { + const tree = await commentsCommand[0].getThread({ + videoId: videoUUID1, + threadId: thread.id, + token: servers[0].accessToken + }) expect(tree.children).to.have.lengthOf(0) } }) @@ -231,7 +236,7 @@ describe('Test blocklist', function () { }) it('Should list all the videos with another user', async function () { - return checkAllVideos(servers[0].url, userToken1) + return checkAllVideos(servers[0], userToken1) }) it('Should list blocked accounts', async function () { @@ -264,32 +269,29 @@ describe('Test blocklist', function () { this.timeout(60000) { - await addVideoCommentThread(servers[1].url, userToken2, videoUUID3, 'comment user 2') + await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' }) await waitJobs(servers) - await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID3, 'uploader') + await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' }) await waitJobs(servers) - const commentId = await findCommentId(servers[1].url, videoUUID3, 'uploader') + const commentId = await commentsCommand[1].findCommentId({ videoId: videoUUID3, text: 'uploader' }) const message = 'reply by user 2' - const resReply = await addVideoCommentReply(servers[1].url, userToken2, videoUUID3, commentId, message) - await addVideoCommentReply(servers[1].url, servers[1].accessToken, videoUUID3, resReply.body.comment.id, 'another reply') + const reply = await commentsCommand[1].addReply({ token: userToken2, videoId: videoUUID3, toCommentId: commentId, text: message }) + await commentsCommand[1].addReply({ videoId: videoUUID3, toCommentId: reply.id, text: 'another reply' }) await waitJobs(servers) } // Server 2 has all the comments { - const resThreads = await getVideoCommentThreads(servers[1].url, videoUUID3, 0, 25, '-createdAt') - const threads: VideoComment[] = resThreads.body.data - - expect(threads).to.have.lengthOf(2) - expect(threads[0].text).to.equal('uploader') - expect(threads[1].text).to.equal('comment user 2') + const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) - const resReplies = await getVideoThreadComments(servers[1].url, videoUUID3, threads[0].id) + expect(data).to.have.lengthOf(2) + expect(data[0].text).to.equal('uploader') + expect(data[1].text).to.equal('comment user 2') - const tree: VideoCommentThreadTree = resReplies.body + const tree = await commentsCommand[1].getThread({ videoId: videoUUID3, threadId: data[0].id }) expect(tree.children).to.have.lengthOf(1) expect(tree.children[0].comment.text).to.equal('reply by user 2') expect(tree.children[0].children).to.have.lengthOf(1) @@ -298,20 +300,15 @@ describe('Test blocklist', function () { // Server 1 and 3 should only have uploader comments for (const server of [ servers[0], servers[2] ]) { - const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt') - const threads: VideoComment[] = resThreads.body.data + const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) - expect(threads).to.have.lengthOf(1) - expect(threads[0].text).to.equal('uploader') + expect(data).to.have.lengthOf(1) + expect(data[0].text).to.equal('uploader') - const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id) + const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id }) - const tree: VideoCommentThreadTree = resReplies.body - if (server.serverNumber === 1) { - expect(tree.children).to.have.lengthOf(0) - } else { - expect(tree.children).to.have.lengthOf(1) - } + if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0) + else expect(tree.children).to.have.lengthOf(1) } }) @@ -331,22 +328,19 @@ describe('Test blocklist', function () { it('Should display its comments on my video', async function () { for (const server of servers) { - const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt') - const threads: VideoComment[] = resThreads.body.data + const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment if (server.serverNumber === 3) { - expect(threads).to.have.lengthOf(1) + expect(data).to.have.lengthOf(1) continue } - expect(threads).to.have.lengthOf(2) - expect(threads[0].text).to.equal('uploader') - expect(threads[1].text).to.equal('comment user 2') - - const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id) + expect(data).to.have.lengthOf(2) + expect(data[0].text).to.equal('uploader') + expect(data[1].text).to.equal('comment user 2') - const tree: VideoCommentThreadTree = resReplies.body + const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id }) expect(tree.children).to.have.lengthOf(1) expect(tree.children[0].comment.text).to.equal('reply by user 2') expect(tree.children[0].children).to.have.lengthOf(1) @@ -359,7 +353,7 @@ describe('Test blocklist', function () { }) it('Should display its comments', function () { - return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + return checkAllComments(servers[0], servers[0].accessToken, videoUUID1) }) it('Should have a notification from a non blocked account', async function () { @@ -385,11 +379,11 @@ describe('Test blocklist', function () { describe('When managing server blocklist', function () { it('Should list all videos', function () { - return checkAllVideos(servers[0].url, servers[0].accessToken) + return checkAllVideos(servers[0], servers[0].accessToken) }) it('Should list the comments', function () { - return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + return checkAllComments(servers[0], servers[0].accessToken, videoUUID1) }) it('Should block a remote server', async function () { @@ -410,20 +404,19 @@ describe('Test blocklist', function () { }) it('Should list all the videos with another user', async function () { - return checkAllVideos(servers[0].url, userToken1) + return checkAllVideos(servers[0], userToken1) }) it('Should hide its comments', async function () { this.timeout(10000) - const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2') - const threadId = resThreads.body.comment.id + const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' }) await waitJobs(servers) - await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + await checkAllComments(servers[0], servers[0].accessToken, videoUUID1) - await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId) + await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id }) }) it('Should not have notifications from blocked server', async function () { @@ -460,11 +453,11 @@ describe('Test blocklist', function () { }) it('Should display its videos', function () { - return checkAllVideos(servers[0].url, servers[0].accessToken) + return checkAllVideos(servers[0], servers[0].accessToken) }) it('Should display its comments', function () { - return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + return checkAllComments(servers[0], servers[0].accessToken, videoUUID1) }) it('Should have notification from unblocked server', async function () { @@ -493,13 +486,13 @@ describe('Test blocklist', function () { describe('When managing account blocklist', function () { it('Should list all videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllVideos(servers[0].url, token) + await checkAllVideos(servers[0], token) } }) it('Should list the comments', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllComments(servers[0].url, token, videoUUID1) + await checkAllComments(servers[0], token, videoUUID1) } }) @@ -537,10 +530,8 @@ describe('Test blocklist', function () { it('Should hide its comments', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 20, '-createdAt', token) - - let threads: VideoComment[] = resThreads.body.data - threads = threads.filter(t => t.isDeleted === false) + const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token }) + const threads = data.filter(t => t.isDeleted === false) expect(threads).to.have.lengthOf(1) expect(threads[0].totalReplies).to.equal(1) @@ -549,9 +540,7 @@ describe('Test blocklist', function () { expect(t).to.be.undefined for (const thread of threads) { - const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, token) - - const tree: VideoCommentThreadTree = res.body + const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token }) expect(tree.children).to.have.lengthOf(0) } } @@ -624,7 +613,7 @@ describe('Test blocklist', function () { it('Should display its comments', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllComments(servers[0].url, token, videoUUID1) + await checkAllComments(servers[0], token, videoUUID1) } }) @@ -651,13 +640,13 @@ describe('Test blocklist', function () { describe('When managing server blocklist', function () { it('Should list all videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllVideos(servers[0].url, token) + await checkAllVideos(servers[0], token) } }) it('Should list the comments', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllComments(servers[0].url, token, videoUUID1) + await checkAllComments(servers[0], token, videoUUID1) } }) @@ -686,14 +675,13 @@ describe('Test blocklist', function () { it('Should hide its comments', async function () { this.timeout(10000) - const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2') - const threadId = resThreads.body.comment.id + const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' }) await waitJobs(servers) - await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + await checkAllComments(servers[0], servers[0].accessToken, videoUUID1) - await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId) + await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id }) }) it('Should not have notification from blocked instances by instance', async function () { @@ -749,13 +737,13 @@ describe('Test blocklist', function () { it('Should list all videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllVideos(servers[0].url, token) + await checkAllVideos(servers[0], token) } }) it('Should list the comments', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllComments(servers[0].url, token, videoUUID1) + await checkAllComments(servers[0], token, videoUUID1) } }) -- cgit v1.2.3 From 9293139fde7091e9badcafa9b570b83cea9a10ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 15:37:43 +0200 Subject: Introduce sql command --- server/tests/api/moderation/video-blacklist.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index c72ebc16b..8b4723a2b 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -342,7 +342,7 @@ describe('Test video blacklist', function () { before(async function () { this.timeout(20000) - killallServers([ servers[0] ]) + await killallServers([ servers[0] ]) const config = { auto_blacklist: { -- cgit v1.2.3 From dd0ebb715123dfa126a82d4e4fe3a04064ae77b8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 16:23:01 +0200 Subject: Introduce notifications command --- .../tests/api/moderation/blocklist-notification.ts | 47 ++++++++++------------ server/tests/api/moderation/blocklist.ts | 28 +++++-------- 2 files changed, 32 insertions(+), 43 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index a077d8739..b676a4db4 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -7,27 +7,22 @@ import { createUser, doubleFollow, flushAndRunMultipleServers, - getUserNotifications, - markAsReadAllNotifications, ServerInfo, setAccessTokensToServers, uploadVideo, userLogin, waitJobs } from '@shared/extra-utils' -import { UserNotification, UserNotificationType } from '@shared/models' +import { UserNotificationType } from '@shared/models' const expect = chai.expect -async function checkNotifications (url: string, token: string, expected: UserNotificationType[]) { - const res = await getUserNotifications(url, token, 0, 10, true) - - const notifications: UserNotification[] = res.body.data - - expect(notifications).to.have.lengthOf(expected.length) +async function checkNotifications (server: ServerInfo, token: string, expected: UserNotificationType[]) { + const { data } = await server.notificationsCommand.list({ token, start: 0, count: 10, unread: true }) + expect(data).to.have.lengthOf(expected.length) for (const type of expected) { - expect(notifications.find(n => n.type === type)).to.exist + expect(data.find(n => n.type === type)).to.exist } } @@ -47,8 +42,8 @@ describe('Test blocklist', function () { await waitJobs(servers) - await markAsReadAllNotifications(servers[0].url, userToken1) - await markAsReadAllNotifications(servers[0].url, userToken2) + await servers[0].notificationsCommand.markAsReadAll({ token: userToken1 }) + await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 }) { const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' }) @@ -122,7 +117,7 @@ describe('Test blocklist', function () { it('Should have appropriate notifications', async function () { const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken1, notifs) + await checkNotifications(servers[0], userToken1, notifs) }) it('Should block an account', async function () { @@ -133,13 +128,13 @@ describe('Test blocklist', function () { }) it('Should not have notifications from this account', async function () { - await checkNotifications(servers[0].url, userToken1, []) + await checkNotifications(servers[0], userToken1, []) }) it('Should have notifications of this account on user 2', async function () { const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken2, notifs) + await checkNotifications(servers[0], userToken2, notifs) await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) }) @@ -155,7 +150,7 @@ describe('Test blocklist', function () { it('Should have appropriate notifications', async function () { const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken1, notifs) + await checkNotifications(servers[0], userToken1, notifs) }) it('Should block an account', async function () { @@ -166,13 +161,13 @@ describe('Test blocklist', function () { }) it('Should not have notifications from this account', async function () { - await checkNotifications(servers[0].url, userToken1, []) + await checkNotifications(servers[0], userToken1, []) }) it('Should have notifications of this account on user 2', async function () { const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken2, notifs) + await checkNotifications(servers[0], userToken2, notifs) await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host }) }) @@ -189,12 +184,12 @@ describe('Test blocklist', function () { it('Should have appropriate notifications', async function () { { const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken1, notifs) + await checkNotifications(servers[0], userToken1, notifs) } { const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken2, notifs) + await checkNotifications(servers[0], userToken2, notifs) } }) @@ -206,8 +201,8 @@ describe('Test blocklist', function () { }) it('Should not have notifications from this account', async function () { - await checkNotifications(servers[0].url, userToken1, []) - await checkNotifications(servers[0].url, userToken2, []) + await checkNotifications(servers[0], userToken1, []) + await checkNotifications(servers[0], userToken2, []) await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host }) }) @@ -224,12 +219,12 @@ describe('Test blocklist', function () { it('Should have appropriate notifications', async function () { { const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken1, notifs) + await checkNotifications(servers[0], userToken1, notifs) } { const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken2, notifs) + await checkNotifications(servers[0], userToken2, notifs) } }) @@ -241,8 +236,8 @@ describe('Test blocklist', function () { }) it('Should not have notifications from this account', async function () { - await checkNotifications(servers[0].url, userToken1, []) - await checkNotifications(servers[0].url, userToken2, []) + await checkNotifications(servers[0], userToken1, []) + await checkNotifications(servers[0], userToken2, []) }) }) diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 00cb6c65c..44e3de4e4 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -9,7 +9,6 @@ import { createUser, doubleFollow, flushAndRunMultipleServers, - getUserNotifications, getVideosList, getVideosListWithToken, ServerInfo, @@ -18,7 +17,7 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { UserNotification, UserNotificationType, Video } from '@shared/models' +import { UserNotificationType, Video } from '@shared/models' const expect = chai.expect @@ -59,9 +58,8 @@ async function checkCommentNotification ( await waitJobs([ mainServer, comment.server ]) - const res = await getUserNotifications(mainServer.url, mainServer.accessToken, 0, 30) - const commentNotifications = (res.body.data as UserNotification[]) - .filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt) + const { data } = await mainServer.notificationsCommand.list({ start: 0, count: 30 }) + const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt) if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) else expect(commentNotifications).to.have.lengthOf(0) @@ -710,12 +708,10 @@ describe('Test blocklist', function () { await waitJobs(servers) - const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30) - const commentNotifications = (res.body.data as UserNotification[]) - .filter(n => { - return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && - n.createdAt >= now.toISOString() - }) + const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 }) + const commentNotifications = data.filter(n => { + return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString() + }) expect(commentNotifications).to.have.lengthOf(0) } @@ -773,12 +769,10 @@ describe('Test blocklist', function () { await waitJobs(servers) - const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30) - const commentNotifications = (res.body.data as UserNotification[]) - .filter(n => { - return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && - n.createdAt >= now.toISOString() - }) + const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 }) + const commentNotifications = data.filter(n => { + return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString() + }) expect(commentNotifications).to.have.lengthOf(1) } -- cgit v1.2.3 From 41d1d075011174e73dccb74006181a92a618d7b4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 11:05:15 +0200 Subject: Introduce login command --- server/tests/api/moderation/abuses.ts | 3 +-- server/tests/api/moderation/blocklist-notification.ts | 7 +++---- server/tests/api/moderation/blocklist.ts | 7 +++---- server/tests/api/moderation/video-blacklist.ts | 5 ++--- 4 files changed, 9 insertions(+), 13 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index e428cf1a8..d7462f38f 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -17,7 +17,6 @@ import { setAccessTokensToServers, uploadVideo, uploadVideoAndGetId, - userLogin, waitJobs } from '@shared/extra-utils' import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' @@ -280,7 +279,7 @@ describe('Test abuses', function () { // register a second user to have two reporters/reportees const user = { username: 'user2', password: 'password' } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user }) - const userAccessToken = await userLogin(servers[0], user) + const userAccessToken = await servers[0].loginCommand.getAccessToken(user) // upload a third video via this user const video3Attributes = { diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index b676a4db4..4f2be6198 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -10,7 +10,6 @@ import { ServerInfo, setAccessTokensToServers, uploadVideo, - userLogin, waitJobs } from '@shared/extra-utils' import { UserNotificationType } from '@shared/models' @@ -86,7 +85,7 @@ describe('Test blocklist', function () { videoQuotaDaily: -1 }) - userToken1 = await userLogin(servers[0], user) + userToken1 = await servers[0].loginCommand.getAccessToken(user) await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) } @@ -94,14 +93,14 @@ describe('Test blocklist', function () { const user = { username: 'user2', password: 'password' } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) - userToken2 = await userLogin(servers[0], user) + userToken2 = await servers[0].loginCommand.getAccessToken(user) } { const user = { username: 'user3', password: 'password' } await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) - remoteUserToken = await userLogin(servers[1], user) + remoteUserToken = await servers[1].loginCommand.getAccessToken(user) } await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 44e3de4e4..c38a7dad4 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -14,7 +14,6 @@ import { ServerInfo, setAccessTokensToServers, uploadVideo, - userLogin, waitJobs } from '@shared/extra-utils' import { UserNotificationType, Video } from '@shared/models' @@ -94,7 +93,7 @@ describe('Test blocklist', function () { const user = { username: 'user1', password: 'password' } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) - userToken1 = await userLogin(servers[0], user) + userToken1 = await servers[0].loginCommand.getAccessToken(user) await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) } @@ -102,14 +101,14 @@ describe('Test blocklist', function () { const user = { username: 'moderator', password: 'password' } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) - userModeratorToken = await userLogin(servers[0], user) + userModeratorToken = await servers[0].loginCommand.getAccessToken(user) } { const user = { username: 'user2', password: 'password' } await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) - userToken2 = await userLogin(servers[1], user) + userToken2 = await servers[1].loginCommand.getAccessToken(user) await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) } diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index 8b4723a2b..b61effc57 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -19,7 +19,6 @@ import { setAccessTokensToServers, updateVideo, uploadVideo, - userLogin, waitJobs } from '@shared/extra-utils' import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' @@ -366,7 +365,7 @@ describe('Test video blacklist', function () { role: UserRole.USER }) - userWithoutFlag = await userLogin(servers[0], user) + userWithoutFlag = await servers[0].loginCommand.getAccessToken(user) const res = await getMyUserInformation(servers[0].url, userWithoutFlag) const body: User = res.body @@ -384,7 +383,7 @@ describe('Test video blacklist', function () { role: UserRole.USER }) - userWithFlag = await userLogin(servers[0], user) + userWithFlag = await servers[0].loginCommand.getAccessToken(user) } await waitJobs(servers) -- cgit v1.2.3 From 7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 14:23:01 +0200 Subject: Introduce user command --- server/tests/api/moderation/abuses.ts | 15 ++++++--------- server/tests/api/moderation/blocklist-notification.ts | 9 +++------ server/tests/api/moderation/blocklist.ts | 7 +++---- server/tests/api/moderation/video-blacklist.ts | 17 +++++------------ 4 files changed, 17 insertions(+), 31 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index d7462f38f..a7119263c 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -5,13 +5,10 @@ import * as chai from 'chai' import { AbusesCommand, cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, - generateUserAccessToken, getVideoIdFromUUID, getVideosList, - removeUser, removeVideo, ServerInfo, setAccessTokensToServers, @@ -278,7 +275,7 @@ describe('Test abuses', function () { // register a second user to have two reporters/reportees const user = { username: 'user2', password: 'password' } - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user }) + await servers[0].usersCommand.create({ ...user }) const userAccessToken = await servers[0].loginCommand.getAccessToken(user) // upload a third video via this user @@ -604,9 +601,9 @@ describe('Test abuses', function () { before(async function () { this.timeout(50000) - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' }) + await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' }) - const token = await generateUserAccessToken(servers[1], 'user_2') + const token = await servers[1].usersCommand.generateUserAndToken('user_2') await uploadVideo(servers[1].url, token, { name: 'super video' }) await waitJobs(servers) @@ -708,7 +705,7 @@ describe('Test abuses', function () { this.timeout(10000) const account = await getAccountFromServer(servers[1], 'user_2', servers[1]) - await removeUser(servers[1].url, account.userId, servers[1].accessToken) + await servers[1].usersCommand.remove({ userId: account.userId }) await waitJobs(servers) @@ -765,7 +762,7 @@ describe('Test abuses', function () { let userAccessToken: string before(async function () { - userAccessToken = await generateUserAccessToken(servers[0], 'user_42') + userAccessToken = await servers[0].usersCommand.generateUserAndToken('user_42') await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) @@ -836,7 +833,7 @@ describe('Test abuses', function () { let abuseMessageModerationId: number before(async function () { - userToken = await generateUserAccessToken(servers[0], 'user_43') + userToken = await servers[0].usersCommand.generateUserAndToken('user_43') const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' }) abuseId = body.abuse.id diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index 4f2be6198..b44bcb012 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -4,7 +4,6 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, ServerInfo, @@ -76,9 +75,7 @@ describe('Test blocklist', function () { { const user = { username: 'user1', password: 'password' } - await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, + await servers[0].usersCommand.create({ username: user.username, password: user.password, videoQuota: -1, @@ -91,14 +88,14 @@ describe('Test blocklist', function () { { const user = { username: 'user2', password: 'password' } - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) + await servers[0].usersCommand.create({ username: user.username, password: user.password }) userToken2 = await servers[0].loginCommand.getAccessToken(user) } { const user = { username: 'user3', password: 'password' } - await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) + await servers[1].usersCommand.create({ username: user.username, password: user.password }) remoteUserToken = await servers[1].loginCommand.getAccessToken(user) } diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index c38a7dad4..c253b5c11 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -6,7 +6,6 @@ import { BlocklistCommand, cleanupTests, CommentsCommand, - createUser, doubleFollow, flushAndRunMultipleServers, getVideosList, @@ -91,7 +90,7 @@ describe('Test blocklist', function () { { const user = { username: 'user1', password: 'password' } - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) + await servers[0].usersCommand.create({ username: user.username, password: user.password }) userToken1 = await servers[0].loginCommand.getAccessToken(user) await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) @@ -99,14 +98,14 @@ describe('Test blocklist', function () { { const user = { username: 'moderator', password: 'password' } - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) + await servers[0].usersCommand.create({ username: user.username, password: user.password }) userModeratorToken = await servers[0].loginCommand.getAccessToken(user) } { const user = { username: 'user2', password: 'password' } - await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) + await servers[1].usersCommand.create({ username: user.username, password: user.password }) userToken2 = await servers[1].loginCommand.getAccessToken(user) await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index b61effc57..ef25cfb8e 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -6,10 +6,8 @@ import { orderBy } from 'lodash' import { BlacklistCommand, cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, - getMyUserInformation, getMyVideos, getVideosList, ImportsCommand, @@ -21,7 +19,7 @@ import { uploadVideo, waitJobs } from '@shared/extra-utils' -import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' +import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' const expect = chai.expect @@ -356,9 +354,7 @@ describe('Test video blacklist', function () { { const user = { username: 'user_without_flag', password: 'password' } - await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, + await servers[0].usersCommand.create({ username: user.username, adminFlags: UserAdminFlag.NONE, password: user.password, @@ -367,16 +363,13 @@ describe('Test video blacklist', function () { userWithoutFlag = await servers[0].loginCommand.getAccessToken(user) - const res = await getMyUserInformation(servers[0].url, userWithoutFlag) - const body: User = res.body - channelOfUserWithoutFlag = body.videoChannels[0].id + const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: userWithoutFlag }) + channelOfUserWithoutFlag = videoChannels[0].id } { const user = { username: 'user_with_flag', password: 'password' } - await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, + await servers[0].usersCommand.create({ username: user.username, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST, password: user.password, -- cgit v1.2.3 From d23dd9fbfc4d26026352c10f81d2795ceaf2908a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Jul 2021 10:02:54 +0200 Subject: Introduce videos command --- server/tests/api/moderation/abuses.ts | 57 ++++++------ .../tests/api/moderation/blocklist-notification.ts | 16 +--- server/tests/api/moderation/blocklist.ts | 100 +++++++++------------ server/tests/api/moderation/video-blacklist.ts | 92 +++++++++---------- 4 files changed, 118 insertions(+), 147 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index a7119263c..7574b8f4a 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -7,13 +7,8 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideoIdFromUUID, - getVideosList, - removeVideo, ServerInfo, setAccessTokensToServers, - uploadVideo, - uploadVideoAndGetId, waitJobs } from '@shared/extra-utils' import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' @@ -47,28 +42,30 @@ describe('Test abuses', function () { this.timeout(50000) // Upload some videos on each servers - const video1Attributes = { - name: 'my super name for server 1', - description: 'my super description for server 1' + { + const attributes = { + name: 'my super name for server 1', + description: 'my super description for server 1' + } + await servers[0].videosCommand.upload({ attributes }) } - await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes) - const video2Attributes = { - name: 'my super name for server 2', - description: 'my super description for server 2' + { + const attributes = { + name: 'my super name for server 2', + description: 'my super description for server 2' + } + await servers[1].videosCommand.upload({ attributes }) } - await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes) // Wait videos propagation, server 2 has transcoding enabled await waitJobs(servers) - const res = await getVideosList(servers[0].url) - const videos = res.body.data - - expect(videos.length).to.equal(2) + const { data } = await servers[0].videosCommand.list() + expect(data.length).to.equal(2) - servers[0].video = videos.find(video => video.name === 'my super name for server 1') - servers[1].video = videos.find(video => video.name === 'my super name for server 2') + servers[0].video = data.find(video => video.name === 'my super name for server 1') + servers[1].video = data.find(video => video.name === 'my super name for server 2') }) it('Should not have abuses', async function () { @@ -130,7 +127,7 @@ describe('Test abuses', function () { this.timeout(10000) const reason = 'my super bad reason 2' - const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) + const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid }) await commands[0].report({ videoId, reason }) // We wait requests propagation @@ -203,7 +200,7 @@ describe('Test abuses', function () { this.timeout(10000) { - const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid) + const videoId = await servers[1].videosCommand.getId({ uuid: servers[0].video.uuid }) await commands[1].report({ videoId, reason: 'will mute this' }) await waitJobs(servers) @@ -255,7 +252,7 @@ describe('Test abuses', function () { it('Should keep the video abuse when deleting the video', async function () { this.timeout(10000) - await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid) + await servers[1].videosCommand.remove({ id: abuseServer2.video.uuid }) await waitJobs(servers) @@ -279,12 +276,12 @@ describe('Test abuses', function () { const userAccessToken = await servers[0].loginCommand.getAccessToken(user) // upload a third video via this user - const video3Attributes = { + const attributes = { name: 'my second super name for server 1', description: 'my second super description for server 1' } - const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes) - const video3Id = resUpload.body.video.id + const { id } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes }) + const video3Id = id // resume with the test const reason3 = 'my super bad reason 3' @@ -394,7 +391,7 @@ describe('Test abuses', function () { async function getComment (server: ServerInfo, videoIdArg: number | string) { const videoId = typeof videoIdArg === 'string' - ? await getVideoIdFromUUID(server.url, videoIdArg) + ? await server.videosCommand.getId({ uuid: videoIdArg }) : videoIdArg const { data } = await server.commentsCommand.listThreads({ videoId }) @@ -405,8 +402,8 @@ describe('Test abuses', function () { before(async function () { this.timeout(50000) - servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' }) - servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' }) + servers[0].video = await await servers[0].videosCommand.quickUpload({ name: 'server 1' }) + servers[1].video = await await servers[1].videosCommand.quickUpload({ name: 'server 2' }) await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' }) await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' }) @@ -604,7 +601,7 @@ describe('Test abuses', function () { await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' }) const token = await servers[1].usersCommand.generateUserAndToken('user_2') - await uploadVideo(servers[1].url, token, { name: 'super video' }) + await servers[1].videosCommand.upload({ token, attributes: { name: 'super video' } }) await waitJobs(servers) }) @@ -766,7 +763,7 @@ describe('Test abuses', function () { await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) - const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) + const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid }) await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' }) }) diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index b44bcb012..92a0ec681 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -2,15 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - doubleFollow, - flushAndRunMultipleServers, - ServerInfo, - setAccessTokensToServers, - uploadVideo, - waitJobs -} from '@shared/extra-utils' +import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' import { UserNotificationType } from '@shared/models' const expect = chai.expect @@ -44,8 +36,8 @@ describe('Test blocklist', function () { await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 }) { - const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' }) - videoUUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video' } }) + videoUUID = uuid await waitJobs(servers) } @@ -83,7 +75,7 @@ describe('Test blocklist', function () { }) userToken1 = await servers[0].loginCommand.getAccessToken(user) - await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) + await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } }) } { diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index c253b5c11..3c3b2d6fd 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -8,28 +8,23 @@ import { CommentsCommand, doubleFollow, flushAndRunMultipleServers, - getVideosList, - getVideosListWithToken, ServerInfo, setAccessTokensToServers, - uploadVideo, waitJobs } from '@shared/extra-utils' -import { UserNotificationType, Video } from '@shared/models' +import { UserNotificationType } from '@shared/models' const expect = chai.expect async function checkAllVideos (server: ServerInfo, token: string) { { - const res = await getVideosListWithToken(server.url, token) - - expect(res.body.data).to.have.lengthOf(5) + const { data } = await server.videosCommand.listWithToken({ token }) + expect(data).to.have.lengthOf(5) } { - const res = await getVideosList(server.url) - - expect(res.body.data).to.have.lengthOf(5) + const { data } = await server.videosCommand.list() + expect(data).to.have.lengthOf(5) } } @@ -93,7 +88,7 @@ describe('Test blocklist', function () { await servers[0].usersCommand.create({ username: user.username, password: user.password }) userToken1 = await servers[0].loginCommand.getAccessToken(user) - await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) + await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } }) } { @@ -108,22 +103,22 @@ describe('Test blocklist', function () { await servers[1].usersCommand.create({ username: user.username, password: user.password }) userToken2 = await servers[1].loginCommand.getAccessToken(user) - await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) + await servers[1].videosCommand.upload({ token: userToken2, attributes: { name: 'video user 2' } }) } { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) - videoUUID1 = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } }) + videoUUID1 = uuid } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) - videoUUID2 = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } }) + videoUUID2 = uuid } { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' }) - videoUUID3 = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } }) + videoUUID3 = uuid } await doubleFollow(servers[0], servers[1]) @@ -164,12 +159,11 @@ describe('Test blocklist', function () { }) it('Should hide its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + const { data } = await servers[0].videosCommand.listWithToken() - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) + expect(data).to.have.lengthOf(4) - const v = videos.find(v => v.name === 'video user 2') + const v = data.find(v => v.name === 'video user 2') expect(v).to.be.undefined }) @@ -178,12 +172,11 @@ describe('Test blocklist', function () { }) it('Should hide its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + const { data } = await servers[0].videosCommand.listWithToken() - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) + expect(data).to.have.lengthOf(3) - const v = videos.find(v => v.name === 'video user 1') + const v = data.find(v => v.name === 'video user 1') expect(v).to.be.undefined }) @@ -313,12 +306,10 @@ describe('Test blocklist', function () { }) it('Should display its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + const { data } = await servers[0].videosCommand.listWithToken() + expect(data).to.have.lengthOf(4) - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) - - const v = videos.find(v => v.name === 'video user 2') + const v = data.find(v => v.name === 'video user 2') expect(v).not.to.be.undefined }) @@ -387,13 +378,12 @@ describe('Test blocklist', function () { }) it('Should hide its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + const { data } = await servers[0].videosCommand.listWithToken() - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) + expect(data).to.have.lengthOf(3) - const v1 = videos.find(v => v.name === 'video user 2') - const v2 = videos.find(v => v.name === 'video server 2') + const v1 = data.find(v => v.name === 'video user 2') + const v2 = data.find(v => v.name === 'video server 2') expect(v1).to.be.undefined expect(v2).to.be.undefined @@ -498,12 +488,11 @@ describe('Test blocklist', function () { it('Should hide its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res = await getVideosListWithToken(servers[0].url, token) + const { data } = await servers[0].videosCommand.listWithToken({ token }) - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) + expect(data).to.have.lengthOf(4) - const v = videos.find(v => v.name === 'video user 2') + const v = data.find(v => v.name === 'video user 2') expect(v).to.be.undefined } }) @@ -514,12 +503,11 @@ describe('Test blocklist', function () { it('Should hide its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res = await getVideosListWithToken(servers[0].url, token) + const { data } = await servers[0].videosCommand.listWithToken({ token }) - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) + expect(data).to.have.lengthOf(3) - const v = videos.find(v => v.name === 'video user 1') + const v = data.find(v => v.name === 'video user 1') expect(v).to.be.undefined } }) @@ -593,12 +581,10 @@ describe('Test blocklist', function () { it('Should display its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res = await getVideosListWithToken(servers[0].url, token) - - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) + const { data } = await servers[0].videosCommand.listWithToken({ token }) + expect(data).to.have.lengthOf(4) - const v = videos.find(v => v.name === 'video user 2') + const v = data.find(v => v.name === 'video user 2') expect(v).not.to.be.undefined } }) @@ -652,15 +638,17 @@ describe('Test blocklist', function () { it('Should hide its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res1 = await getVideosList(servers[0].url) - const res2 = await getVideosListWithToken(servers[0].url, token) + const requests = [ + servers[0].videosCommand.list(), + servers[0].videosCommand.listWithToken({ token }) + ] - for (const res of [ res1, res2 ]) { - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) + for (const req of requests) { + const { data } = await req + expect(data).to.have.lengthOf(3) - const v1 = videos.find(v => v.name === 'video user 2') - const v2 = videos.find(v => v.name === 'video server 2') + const v1 = data.find(v => v.name === 'video user 2') + const v2 = data.find(v => v.name === 'video server 2') expect(v1).to.be.undefined expect(v2).to.be.undefined diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index ef25cfb8e..2f2e678e7 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -8,15 +8,11 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getMyVideos, - getVideosList, ImportsCommand, killallServers, reRunServer, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, waitJobs } from '@shared/extra-utils' import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' @@ -29,10 +25,9 @@ describe('Test video blacklist', function () { let command: BlacklistCommand async function blacklistVideosOnServer (server: ServerInfo) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const videos = res.body.data - for (const video of videos) { + for (const video of data) { await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' }) } } @@ -50,8 +45,8 @@ describe('Test video blacklist', function () { await doubleFollow(servers[0], servers[1]) // Upload 2 videos on server 2 - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' }) - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) + await servers[1].videosCommand.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } }) + await servers[1].videosCommand.upload({ attributes: { name: 'My 2nd video', description: 'A video on server 2' } }) // Wait videos propagation, server 2 has transcoding enabled await waitJobs(servers) @@ -66,11 +61,11 @@ describe('Test video blacklist', function () { it('Should not have the video blacklisted in videos list/search on server 1', async function () { { - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) + expect(total).to.equal(0) + expect(data).to.be.an('array') + expect(data.length).to.equal(0) } { @@ -84,11 +79,11 @@ describe('Test video blacklist', function () { it('Should have the blacklisted video in videos list/search on server 2', async function () { { - const res = await getVideosList(servers[1].url) + const { total, data } = await servers[1].videosCommand.list() - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(2) + expect(total).to.equal(2) + expect(data).to.be.an('array') + expect(data.length).to.equal(2) } { @@ -186,12 +181,12 @@ describe('Test video blacklist', function () { it('Should display blacklisted videos', async function () { await blacklistVideosOnServer(servers[1]) - const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5) + const { total, data } = await servers[1].videosCommand.listMyVideos() - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + expect(total).to.equal(2) + expect(data).to.have.lengthOf(2) - for (const video of res.body.data) { + for (const video of data) { expect(video.blacklisted).to.be.true expect(video.blacklistedReason).to.equal('super reason') } @@ -203,10 +198,10 @@ describe('Test video blacklist', function () { let blacklist = [] it('Should not have any video in videos list on server 1', async function () { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(0) + expect(data).to.be.an('array') + expect(data.length).to.equal(0) }) it('Should remove a video from the blacklist on server 1', async function () { @@ -220,15 +215,14 @@ describe('Test video blacklist', function () { }) it('Should have the ex-blacklisted video in videos list on server 1', async function () { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(1) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(1) - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(1) + expect(data).to.be.an('array') + expect(data.length).to.equal(1) - expect(videos[0].name).to.equal(videoToRemove.video.name) - expect(videos[0].id).to.equal(videoToRemove.video.id) + expect(data[0].name).to.equal(videoToRemove.video.name) + expect(data[0].id).to.equal(videoToRemove.video.id) }) it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { @@ -250,12 +244,12 @@ describe('Test video blacklist', function () { this.timeout(10000) { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' }) - video3UUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 3' } }) + video3UUID = uuid } { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 4' }) - video4UUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 4' } }) + video4UUID = uuid } await waitJobs(servers) @@ -269,13 +263,13 @@ describe('Test video blacklist', function () { await waitJobs(servers) { - const res = await getVideosList(servers[0].url) - expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined + const { data } = await servers[0].videosCommand.list() + expect(data.find(v => v.uuid === video3UUID)).to.be.undefined } { - const res = await getVideosList(servers[1].url) - expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined + const { data } = await servers[1].videosCommand.list() + expect(data.find(v => v.uuid === video3UUID)).to.not.be.undefined } }) @@ -287,21 +281,21 @@ describe('Test video blacklist', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined + const { data } = await server.videosCommand.list() + expect(data.find(v => v.uuid === video4UUID)).to.be.undefined } }) it('Should have the video unfederated even after an Update AP message', async function () { this.timeout(10000) - await updateVideo(servers[0].url, servers[0].accessToken, video4UUID, { description: 'super description' }) + await servers[0].videosCommand.update({ id: video4UUID, attributes: { description: 'super description' } }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined + const { data } = await server.videosCommand.list() + expect(data.find(v => v.uuid === video4UUID)).to.be.undefined } }) @@ -324,8 +318,8 @@ describe('Test video blacklist', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined + const { data } = await server.videosCommand.list() + expect(data.find(v => v.uuid === video4UUID)).to.not.be.undefined } }) @@ -383,7 +377,7 @@ describe('Test video blacklist', function () { }) it('Should auto blacklist a video on upload', async function () { - await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) + await servers[0].videosCommand.upload({ token: userWithoutFlag, attributes: { name: 'blacklisted' } }) const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(1) @@ -419,7 +413,7 @@ describe('Test video blacklist', function () { }) it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { - await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) + await servers[0].videosCommand.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } }) const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(3) -- cgit v1.2.3 From 89d241a79c262b9775c233b73cff080043ebb5e6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:04:35 +0200 Subject: Shorter server command names --- server/tests/api/moderation/abuses.ts | 96 +++++++++++----------- .../tests/api/moderation/blocklist-notification.ts | 46 +++++------ server/tests/api/moderation/blocklist.ts | 76 ++++++++--------- server/tests/api/moderation/video-blacklist.ts | 58 ++++++------- 4 files changed, 138 insertions(+), 138 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index 7574b8f4a..97a0d95c4 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -33,7 +33,7 @@ describe('Test abuses', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - commands = servers.map(s => s.abusesCommand) + commands = servers.map(s => s.abuses) }) describe('Video abuses', function () { @@ -47,7 +47,7 @@ describe('Test abuses', function () { name: 'my super name for server 1', description: 'my super description for server 1' } - await servers[0].videosCommand.upload({ attributes }) + await servers[0].videos.upload({ attributes }) } { @@ -55,17 +55,17 @@ describe('Test abuses', function () { name: 'my super name for server 2', description: 'my super description for server 2' } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) } // Wait videos propagation, server 2 has transcoding enabled await waitJobs(servers) - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() expect(data.length).to.equal(2) - servers[0].video = data.find(video => video.name === 'my super name for server 1') - servers[1].video = data.find(video => video.name === 'my super name for server 2') + servers[0].store.video = data.find(video => video.name === 'my super name for server 1') + servers[1].store.video = data.find(video => video.name === 'my super name for server 2') }) it('Should not have abuses', async function () { @@ -80,7 +80,7 @@ describe('Test abuses', function () { this.timeout(15000) const reason = 'my super bad reason' - await commands[0].report({ videoId: servers[0].video.id, reason }) + await commands[0].report({ videoId: servers[0].store.video.id, reason }) // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 await waitJobs(servers) @@ -100,7 +100,7 @@ describe('Test abuses', function () { expect(abuse.reporterAccount.name).to.equal('root') expect(abuse.reporterAccount.host).to.equal(servers[0].host) - expect(abuse.video.id).to.equal(servers[0].video.id) + expect(abuse.video.id).to.equal(servers[0].store.video.id) expect(abuse.video.channel).to.exist expect(abuse.comment).to.be.null @@ -127,7 +127,7 @@ describe('Test abuses', function () { this.timeout(10000) const reason = 'my super bad reason 2' - const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid }) + const videoId = await servers[0].videos.getId({ uuid: servers[1].store.video.uuid }) await commands[0].report({ videoId, reason }) // We wait requests propagation @@ -146,7 +146,7 @@ describe('Test abuses', function () { expect(abuse1.reporterAccount.name).to.equal('root') expect(abuse1.reporterAccount.host).to.equal(servers[0].host) - expect(abuse1.video.id).to.equal(servers[0].video.id) + expect(abuse1.video.id).to.equal(servers[0].store.video.id) expect(abuse1.video.countReports).to.equal(1) expect(abuse1.video.nthReport).to.equal(1) @@ -165,7 +165,7 @@ describe('Test abuses', function () { expect(abuse2.reporterAccount.name).to.equal('root') expect(abuse2.reporterAccount.host).to.equal(servers[0].host) - expect(abuse2.video.id).to.equal(servers[1].video.id) + expect(abuse2.video.id).to.equal(servers[1].store.video.id) expect(abuse2.comment).to.be.null @@ -200,7 +200,7 @@ describe('Test abuses', function () { this.timeout(10000) { - const videoId = await servers[1].videosCommand.getId({ uuid: servers[0].video.uuid }) + const videoId = await servers[1].videos.getId({ uuid: servers[0].store.video.uuid }) await commands[1].report({ videoId, reason: 'will mute this' }) await waitJobs(servers) @@ -211,7 +211,7 @@ describe('Test abuses', function () { const accountToBlock = 'root@' + servers[1].host { - await servers[0].blocklistCommand.addToServerBlocklist({ account: accountToBlock }) + await servers[0].blocklist.addToServerBlocklist({ account: accountToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(2) @@ -221,7 +221,7 @@ describe('Test abuses', function () { } { - await servers[0].blocklistCommand.removeFromServerBlocklist({ account: accountToBlock }) + await servers[0].blocklist.removeFromServerBlocklist({ account: accountToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(3) @@ -232,7 +232,7 @@ describe('Test abuses', function () { const serverToBlock = servers[1].host { - await servers[0].blocklistCommand.addToServerBlocklist({ server: serverToBlock }) + await servers[0].blocklist.addToServerBlocklist({ server: serverToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(2) @@ -242,7 +242,7 @@ describe('Test abuses', function () { } { - await servers[0].blocklistCommand.removeFromServerBlocklist({ server: serverToBlock }) + await servers[0].blocklist.removeFromServerBlocklist({ server: serverToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(3) @@ -252,7 +252,7 @@ describe('Test abuses', function () { it('Should keep the video abuse when deleting the video', async function () { this.timeout(10000) - await servers[1].videosCommand.remove({ id: abuseServer2.video.uuid }) + await servers[1].videos.remove({ id: abuseServer2.video.uuid }) await waitJobs(servers) @@ -272,15 +272,15 @@ describe('Test abuses', function () { // register a second user to have two reporters/reportees const user = { username: 'user2', password: 'password' } - await servers[0].usersCommand.create({ ...user }) - const userAccessToken = await servers[0].loginCommand.getAccessToken(user) + await servers[0].users.create({ ...user }) + const userAccessToken = await servers[0].login.getAccessToken(user) // upload a third video via this user const attributes = { name: 'my second super name for server 1', description: 'my second super description for server 1' } - const { id } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes }) + const { id } = await servers[0].videos.upload({ token: userAccessToken, attributes }) const video3Id = id // resume with the test @@ -288,7 +288,7 @@ describe('Test abuses', function () { await commands[0].report({ videoId: video3Id, reason: reason3 }) const reason4 = 'my super bad reason 4' - await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: reason4 }) + await commands[0].report({ token: userAccessToken, videoId: servers[0].store.video.id, reason: reason4 }) { const body = await commands[0].getAdminList() @@ -301,7 +301,7 @@ describe('Test abuses', function () { expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse") expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse") - const abuseServer1 = abuses.find(a => a.video.id === servers[0].video.id) + const abuseServer1 = abuses.find(a => a.video.id === servers[0].store.video.id) expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse") } }) @@ -312,7 +312,7 @@ describe('Test abuses', function () { const reason5 = 'my super bad reason 5' const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ] const createRes = await commands[0].report({ - videoId: servers[0].video.id, + videoId: servers[0].store.video.id, reason: reason5, predefinedReasons: predefinedReasons5, startAt: 1, @@ -391,10 +391,10 @@ describe('Test abuses', function () { async function getComment (server: ServerInfo, videoIdArg: number | string) { const videoId = typeof videoIdArg === 'string' - ? await server.videosCommand.getId({ uuid: videoIdArg }) + ? await server.videos.getId({ uuid: videoIdArg }) : videoIdArg - const { data } = await server.commentsCommand.listThreads({ videoId }) + const { data } = await server.comments.listThreads({ videoId }) return data[0] } @@ -402,11 +402,11 @@ describe('Test abuses', function () { before(async function () { this.timeout(50000) - servers[0].video = await await servers[0].videosCommand.quickUpload({ name: 'server 1' }) - servers[1].video = await await servers[1].videosCommand.quickUpload({ name: 'server 2' }) + servers[0].store.video = await await servers[0].videos.quickUpload({ name: 'server 1' }) + servers[1].store.video = await await servers[1].videos.quickUpload({ name: 'server 2' }) - await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' }) - await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' }) + await servers[0].comments.createThread({ videoId: servers[0].store.video.id, text: 'comment server 1' }) + await servers[1].comments.createThread({ videoId: servers[1].store.video.id, text: 'comment server 2' }) await waitJobs(servers) }) @@ -414,7 +414,7 @@ describe('Test abuses', function () { it('Should report abuse on a comment', async function () { this.timeout(15000) - const comment = await getComment(servers[0], servers[0].video.id) + const comment = await getComment(servers[0], servers[0].store.video.id) const reason = 'it is a bad comment' await commands[0].report({ commentId: comment.id, reason }) @@ -424,7 +424,7 @@ describe('Test abuses', function () { it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () { { - const comment = await getComment(servers[0], servers[0].video.id) + const comment = await getComment(servers[0], servers[0].store.video.id) const body = await commands[0].getAdminList({ filter: 'comment' }) expect(body.total).to.equal(1) @@ -442,8 +442,8 @@ describe('Test abuses', function () { expect(abuse.comment.id).to.equal(comment.id) expect(abuse.comment.text).to.equal(comment.text) expect(abuse.comment.video.name).to.equal('server 1') - expect(abuse.comment.video.id).to.equal(servers[0].video.id) - expect(abuse.comment.video.uuid).to.equal(servers[0].video.uuid) + expect(abuse.comment.video.id).to.equal(servers[0].store.video.id) + expect(abuse.comment.video.uuid).to.equal(servers[0].store.video.uuid) expect(abuse.countReportsForReporter).to.equal(5) expect(abuse.countReportsForReportee).to.equal(5) @@ -459,7 +459,7 @@ describe('Test abuses', function () { it('Should report abuse on a remote comment', async function () { this.timeout(10000) - const comment = await getComment(servers[0], servers[1].video.uuid) + const comment = await getComment(servers[0], servers[1].store.video.uuid) const reason = 'it is a really bad comment' await commands[0].report({ commentId: comment.id, reason }) @@ -468,7 +468,7 @@ describe('Test abuses', function () { }) it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { - const commentServer2 = await getComment(servers[0], servers[1].video.id) + const commentServer2 = await getComment(servers[0], servers[1].store.video.id) { const body = await commands[0].getAdminList({ filter: 'comment' }) @@ -493,7 +493,7 @@ describe('Test abuses', function () { expect(abuse2.comment.id).to.equal(commentServer2.id) expect(abuse2.comment.text).to.equal(commentServer2.text) expect(abuse2.comment.video.name).to.equal('server 2') - expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid) + expect(abuse2.comment.video.uuid).to.equal(servers[1].store.video.uuid) expect(abuse2.state.id).to.equal(AbuseState.PENDING) expect(abuse2.state.label).to.equal('Pending') @@ -527,9 +527,9 @@ describe('Test abuses', function () { it('Should keep the comment abuse when deleting the comment', async function () { this.timeout(10000) - const commentServer2 = await getComment(servers[0], servers[1].video.id) + const commentServer2 = await getComment(servers[0], servers[1].store.video.id) - await servers[0].commentsCommand.delete({ videoId: servers[1].video.uuid, commentId: commentServer2.id }) + await servers[0].comments.delete({ videoId: servers[1].store.video.uuid, commentId: commentServer2.id }) await waitJobs(servers) @@ -592,16 +592,16 @@ describe('Test abuses', function () { describe('Account abuses', function () { function getAccountFromServer (server: ServerInfo, targetName: string, targetServer: ServerInfo) { - return server.accountsCommand.get({ accountName: targetName + '@' + targetServer.host }) + return server.accounts.get({ accountName: targetName + '@' + targetServer.host }) } before(async function () { this.timeout(50000) - await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' }) + await servers[0].users.create({ username: 'user_1', password: 'donald' }) - const token = await servers[1].usersCommand.generateUserAndToken('user_2') - await servers[1].videosCommand.upload({ token, attributes: { name: 'super video' } }) + const token = await servers[1].users.generateUserAndToken('user_2') + await servers[1].videos.upload({ token, attributes: { name: 'super video' } }) await waitJobs(servers) }) @@ -702,7 +702,7 @@ describe('Test abuses', function () { this.timeout(10000) const account = await getAccountFromServer(servers[1], 'user_2', servers[1]) - await servers[1].usersCommand.remove({ userId: account.userId }) + await servers[1].users.remove({ userId: account.userId }) await waitJobs(servers) @@ -759,11 +759,11 @@ describe('Test abuses', function () { let userAccessToken: string before(async function () { - userAccessToken = await servers[0].usersCommand.generateUserAndToken('user_42') + userAccessToken = await servers[0].users.generateUserAndToken('user_42') - await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) + await commands[0].report({ token: userAccessToken, videoId: servers[0].store.video.id, reason: 'user reason 1' }) - const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid }) + const videoId = await servers[0].videos.getId({ uuid: servers[1].store.video.uuid }) await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' }) }) @@ -830,9 +830,9 @@ describe('Test abuses', function () { let abuseMessageModerationId: number before(async function () { - userToken = await servers[0].usersCommand.generateUserAndToken('user_43') + userToken = await servers[0].users.generateUserAndToken('user_43') - const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' }) + const body = await commands[0].report({ token: userToken, videoId: servers[0].store.video.id, reason: 'user 43 reason 1' }) abuseId = body.abuse.id }) diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index 92a0ec681..6b56fdd65 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -8,7 +8,7 @@ import { UserNotificationType } from '@shared/models' const expect = chai.expect async function checkNotifications (server: ServerInfo, token: string, expected: UserNotificationType[]) { - const { data } = await server.notificationsCommand.list({ token, start: 0, count: 10, unread: true }) + const { data } = await server.notifications.list({ token, start: 0, count: 10, unread: true }) expect(data).to.have.lengthOf(expected.length) for (const type of expected) { @@ -26,24 +26,24 @@ describe('Test blocklist', function () { async function resetState () { try { - await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host }) - await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host }) + await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host }) + await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host }) } catch {} await waitJobs(servers) - await servers[0].notificationsCommand.markAsReadAll({ token: userToken1 }) - await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 }) + await servers[0].notifications.markAsReadAll({ token: userToken1 }) + await servers[0].notifications.markAsReadAll({ token: userToken2 }) { - const { uuid } = await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video' } }) + const { uuid } = await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video' } }) videoUUID = uuid await waitJobs(servers) } { - await servers[1].commentsCommand.createThread({ + await servers[1].comments.createThread({ token: remoteUserToken, videoId: videoUUID, text: '@user2@' + servers[0].host + ' hello' @@ -52,8 +52,8 @@ describe('Test blocklist', function () { { - await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host }) - await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host }) + await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host }) + await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host }) } await waitJobs(servers) @@ -67,29 +67,29 @@ describe('Test blocklist', function () { { const user = { username: 'user1', password: 'password' } - await servers[0].usersCommand.create({ + await servers[0].users.create({ username: user.username, password: user.password, videoQuota: -1, videoQuotaDaily: -1 }) - userToken1 = await servers[0].loginCommand.getAccessToken(user) - await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } }) + userToken1 = await servers[0].login.getAccessToken(user) + await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } }) } { const user = { username: 'user2', password: 'password' } - await servers[0].usersCommand.create({ username: user.username, password: user.password }) + await servers[0].users.create({ username: user.username, password: user.password }) - userToken2 = await servers[0].loginCommand.getAccessToken(user) + userToken2 = await servers[0].login.getAccessToken(user) } { const user = { username: 'user3', password: 'password' } - await servers[1].usersCommand.create({ username: user.username, password: user.password }) + await servers[1].users.create({ username: user.username, password: user.password }) - remoteUserToken = await servers[1].loginCommand.getAccessToken(user) + remoteUserToken = await servers[1].login.getAccessToken(user) } await doubleFollow(servers[0], servers[1]) @@ -111,7 +111,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) + await servers[0].blocklist.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) await waitJobs(servers) }) @@ -124,7 +124,7 @@ describe('Test blocklist', function () { await checkNotifications(servers[0], userToken2, notifs) - await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) + await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) }) }) @@ -144,7 +144,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host }) + await servers[0].blocklist.addToMyBlocklist({ token: userToken1, server: servers[1].host }) await waitJobs(servers) }) @@ -157,7 +157,7 @@ describe('Test blocklist', function () { await checkNotifications(servers[0], userToken2, notifs) - await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host }) + await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, server: servers[1].host }) }) }) @@ -184,7 +184,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host }) + await servers[0].blocklist.addToServerBlocklist({ account: 'user3@' + servers[1].host }) await waitJobs(servers) }) @@ -192,7 +192,7 @@ describe('Test blocklist', function () { await checkNotifications(servers[0], userToken1, []) await checkNotifications(servers[0], userToken2, []) - await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host }) + await servers[0].blocklist.removeFromServerBlocklist({ account: 'user3@' + servers[1].host }) }) }) @@ -219,7 +219,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host }) + await servers[0].blocklist.addToServerBlocklist({ server: servers[1].host }) await waitJobs(servers) }) diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 3c3b2d6fd..9a4a3b3b9 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -18,24 +18,24 @@ const expect = chai.expect async function checkAllVideos (server: ServerInfo, token: string) { { - const { data } = await server.videosCommand.listWithToken({ token }) + const { data } = await server.videos.listWithToken({ token }) expect(data).to.have.lengthOf(5) } { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.have.lengthOf(5) } } async function checkAllComments (server: ServerInfo, token: string, videoUUID: string) { - const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token }) + const { data } = await server.comments.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token }) const threads = data.filter(t => t.isDeleted === false) expect(threads).to.have.lengthOf(2) for (const thread of threads) { - const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId: thread.id, token }) + const tree = await server.comments.getThread({ videoId: videoUUID, threadId: thread.id, token }) expect(tree.children).to.have.lengthOf(1) } } @@ -45,13 +45,13 @@ async function checkCommentNotification ( comment: { server: ServerInfo, token: string, videoUUID: string, text: string }, check: 'presence' | 'absence' ) { - const command = comment.server.commentsCommand + const command = comment.server.comments const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text }) await waitJobs([ mainServer, comment.server ]) - const { data } = await mainServer.notificationsCommand.list({ start: 0, count: 30 }) + const { data } = await mainServer.notifications.list({ start: 0, count: 30 }) const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt) if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) @@ -80,44 +80,44 @@ describe('Test blocklist', function () { servers = await flushAndRunMultipleServers(3) await setAccessTokensToServers(servers) - command = servers[0].blocklistCommand - commentsCommand = servers.map(s => s.commentsCommand) + command = servers[0].blocklist + commentsCommand = servers.map(s => s.comments) { const user = { username: 'user1', password: 'password' } - await servers[0].usersCommand.create({ username: user.username, password: user.password }) + await servers[0].users.create({ username: user.username, password: user.password }) - userToken1 = await servers[0].loginCommand.getAccessToken(user) - await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } }) + userToken1 = await servers[0].login.getAccessToken(user) + await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } }) } { const user = { username: 'moderator', password: 'password' } - await servers[0].usersCommand.create({ username: user.username, password: user.password }) + await servers[0].users.create({ username: user.username, password: user.password }) - userModeratorToken = await servers[0].loginCommand.getAccessToken(user) + userModeratorToken = await servers[0].login.getAccessToken(user) } { const user = { username: 'user2', password: 'password' } - await servers[1].usersCommand.create({ username: user.username, password: user.password }) + await servers[1].users.create({ username: user.username, password: user.password }) - userToken2 = await servers[1].loginCommand.getAccessToken(user) - await servers[1].videosCommand.upload({ token: userToken2, attributes: { name: 'video user 2' } }) + userToken2 = await servers[1].login.getAccessToken(user) + await servers[1].videos.upload({ token: userToken2, attributes: { name: 'video user 2' } }) } { - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } }) videoUUID1 = uuid } { - const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } }) + const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } }) videoUUID2 = uuid } { - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } }) videoUUID3 = uuid } @@ -159,7 +159,7 @@ describe('Test blocklist', function () { }) it('Should hide its videos', async function () { - const { data } = await servers[0].videosCommand.listWithToken() + const { data } = await servers[0].videos.listWithToken() expect(data).to.have.lengthOf(4) @@ -172,7 +172,7 @@ describe('Test blocklist', function () { }) it('Should hide its videos', async function () { - const { data } = await servers[0].videosCommand.listWithToken() + const { data } = await servers[0].videos.listWithToken() expect(data).to.have.lengthOf(3) @@ -289,12 +289,12 @@ describe('Test blocklist', function () { // Server 1 and 3 should only have uploader comments for (const server of [ servers[0], servers[2] ]) { - const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) + const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) expect(data).to.have.lengthOf(1) expect(data[0].text).to.equal('uploader') - const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id }) + const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id }) if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0) else expect(tree.children).to.have.lengthOf(1) @@ -306,7 +306,7 @@ describe('Test blocklist', function () { }) it('Should display its videos', async function () { - const { data } = await servers[0].videosCommand.listWithToken() + const { data } = await servers[0].videos.listWithToken() expect(data).to.have.lengthOf(4) const v = data.find(v => v.name === 'video user 2') @@ -315,7 +315,7 @@ describe('Test blocklist', function () { it('Should display its comments on my video', async function () { for (const server of servers) { - const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) + const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment if (server.serverNumber === 3) { @@ -327,7 +327,7 @@ describe('Test blocklist', function () { expect(data[0].text).to.equal('uploader') expect(data[1].text).to.equal('comment user 2') - const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id }) + const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id }) expect(tree.children).to.have.lengthOf(1) expect(tree.children[0].comment.text).to.equal('reply by user 2') expect(tree.children[0].children).to.have.lengthOf(1) @@ -378,7 +378,7 @@ describe('Test blocklist', function () { }) it('Should hide its videos', async function () { - const { data } = await servers[0].videosCommand.listWithToken() + const { data } = await servers[0].videos.listWithToken() expect(data).to.have.lengthOf(3) @@ -488,7 +488,7 @@ describe('Test blocklist', function () { it('Should hide its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const { data } = await servers[0].videosCommand.listWithToken({ token }) + const { data } = await servers[0].videos.listWithToken({ token }) expect(data).to.have.lengthOf(4) @@ -503,7 +503,7 @@ describe('Test blocklist', function () { it('Should hide its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const { data } = await servers[0].videosCommand.listWithToken({ token }) + const { data } = await servers[0].videos.listWithToken({ token }) expect(data).to.have.lengthOf(3) @@ -581,7 +581,7 @@ describe('Test blocklist', function () { it('Should display its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const { data } = await servers[0].videosCommand.listWithToken({ token }) + const { data } = await servers[0].videos.listWithToken({ token }) expect(data).to.have.lengthOf(4) const v = data.find(v => v.name === 'video user 2') @@ -639,8 +639,8 @@ describe('Test blocklist', function () { it('Should hide its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { const requests = [ - servers[0].videosCommand.list(), - servers[0].videosCommand.listWithToken({ token }) + servers[0].videos.list(), + servers[0].videos.listWithToken({ token }) ] for (const req of requests) { @@ -688,13 +688,13 @@ describe('Test blocklist', function () { { const now = new Date() - await servers[1].followsCommand.unfollow({ target: servers[0] }) + await servers[1].follows.unfollow({ target: servers[0] }) await waitJobs(servers) - await servers[1].followsCommand.follow({ targets: [ servers[0].host ] }) + await servers[1].follows.follow({ targets: [ servers[0].host ] }) await waitJobs(servers) - const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 }) + const { data } = await servers[0].notifications.list({ start: 0, count: 30 }) const commentNotifications = data.filter(n => { return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString() }) @@ -749,13 +749,13 @@ describe('Test blocklist', function () { { const now = new Date() - await servers[1].followsCommand.unfollow({ target: servers[0] }) + await servers[1].follows.unfollow({ target: servers[0] }) await waitJobs(servers) - await servers[1].followsCommand.follow({ targets: [ servers[0].host ] }) + await servers[1].follows.follow({ targets: [ servers[0].host ] }) await waitJobs(servers) - const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 }) + const { data } = await servers[0].notifications.list({ start: 0, count: 30 }) const commentNotifications = data.filter(n => { return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString() }) diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index 2f2e678e7..d23d23bcb 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -25,10 +25,10 @@ describe('Test video blacklist', function () { let command: BlacklistCommand async function blacklistVideosOnServer (server: ServerInfo) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() for (const video of data) { - await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' }) + await server.blacklist.add({ videoId: video.id, reason: 'super reason' }) } } @@ -45,13 +45,13 @@ describe('Test video blacklist', function () { await doubleFollow(servers[0], servers[1]) // Upload 2 videos on server 2 - await servers[1].videosCommand.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } }) - await servers[1].videosCommand.upload({ attributes: { name: 'My 2nd video', description: 'A video on server 2' } }) + await servers[1].videos.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } }) + await servers[1].videos.upload({ attributes: { name: 'My 2nd video', description: 'A video on server 2' } }) // Wait videos propagation, server 2 has transcoding enabled await waitJobs(servers) - command = servers[0].blacklistCommand + command = servers[0].blacklist // Blacklist the two videos on server 1 await blacklistVideosOnServer(servers[0]) @@ -61,7 +61,7 @@ describe('Test video blacklist', function () { it('Should not have the video blacklisted in videos list/search on server 1', async function () { { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(0) expect(data).to.be.an('array') @@ -69,7 +69,7 @@ describe('Test video blacklist', function () { } { - const body = await servers[0].searchCommand.searchVideos({ search: 'video' }) + const body = await servers[0].search.searchVideos({ search: 'video' }) expect(body.total).to.equal(0) expect(body.data).to.be.an('array') @@ -79,7 +79,7 @@ describe('Test video blacklist', function () { it('Should have the blacklisted video in videos list/search on server 2', async function () { { - const { total, data } = await servers[1].videosCommand.list() + const { total, data } = await servers[1].videos.list() expect(total).to.equal(2) expect(data).to.be.an('array') @@ -87,7 +87,7 @@ describe('Test video blacklist', function () { } { - const body = await servers[1].searchCommand.searchVideos({ search: 'video' }) + const body = await servers[1].search.searchVideos({ search: 'video' }) expect(body.total).to.equal(2) expect(body.data).to.be.an('array') @@ -181,7 +181,7 @@ describe('Test video blacklist', function () { it('Should display blacklisted videos', async function () { await blacklistVideosOnServer(servers[1]) - const { total, data } = await servers[1].videosCommand.listMyVideos() + const { total, data } = await servers[1].videos.listMyVideos() expect(total).to.equal(2) expect(data).to.have.lengthOf(2) @@ -198,7 +198,7 @@ describe('Test video blacklist', function () { let blacklist = [] it('Should not have any video in videos list on server 1', async function () { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(0) expect(data).to.be.an('array') expect(data.length).to.equal(0) @@ -215,7 +215,7 @@ describe('Test video blacklist', function () { }) it('Should have the ex-blacklisted video in videos list on server 1', async function () { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(1) expect(data).to.be.an('array') @@ -244,11 +244,11 @@ describe('Test video blacklist', function () { this.timeout(10000) { - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 3' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'Video 3' } }) video3UUID = uuid } { - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 4' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'Video 4' } }) video4UUID = uuid } @@ -263,12 +263,12 @@ describe('Test video blacklist', function () { await waitJobs(servers) { - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() expect(data.find(v => v.uuid === video3UUID)).to.be.undefined } { - const { data } = await servers[1].videosCommand.list() + const { data } = await servers[1].videos.list() expect(data.find(v => v.uuid === video3UUID)).to.not.be.undefined } }) @@ -281,7 +281,7 @@ describe('Test video blacklist', function () { await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data.find(v => v.uuid === video4UUID)).to.be.undefined } }) @@ -289,12 +289,12 @@ describe('Test video blacklist', function () { it('Should have the video unfederated even after an Update AP message', async function () { this.timeout(10000) - await servers[0].videosCommand.update({ id: video4UUID, attributes: { description: 'super description' } }) + await servers[0].videos.update({ id: video4UUID, attributes: { description: 'super description' } }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data.find(v => v.uuid === video4UUID)).to.be.undefined } }) @@ -318,7 +318,7 @@ describe('Test video blacklist', function () { await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data.find(v => v.uuid === video4UUID)).to.not.be.undefined } }) @@ -348,36 +348,36 @@ describe('Test video blacklist', function () { { const user = { username: 'user_without_flag', password: 'password' } - await servers[0].usersCommand.create({ + await servers[0].users.create({ username: user.username, adminFlags: UserAdminFlag.NONE, password: user.password, role: UserRole.USER }) - userWithoutFlag = await servers[0].loginCommand.getAccessToken(user) + userWithoutFlag = await servers[0].login.getAccessToken(user) - const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: userWithoutFlag }) + const { videoChannels } = await servers[0].users.getMyInfo({ token: userWithoutFlag }) channelOfUserWithoutFlag = videoChannels[0].id } { const user = { username: 'user_with_flag', password: 'password' } - await servers[0].usersCommand.create({ + await servers[0].users.create({ username: user.username, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST, password: user.password, role: UserRole.USER }) - userWithFlag = await servers[0].loginCommand.getAccessToken(user) + userWithFlag = await servers[0].login.getAccessToken(user) } await waitJobs(servers) }) it('Should auto blacklist a video on upload', async function () { - await servers[0].videosCommand.upload({ token: userWithoutFlag, attributes: { name: 'blacklisted' } }) + await servers[0].videos.upload({ token: userWithoutFlag, attributes: { name: 'blacklisted' } }) const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(1) @@ -392,7 +392,7 @@ describe('Test video blacklist', function () { name: 'URL import', channelId: channelOfUserWithoutFlag } - await servers[0].importsCommand.importVideo({ token: userWithoutFlag, attributes }) + await servers[0].imports.importVideo({ token: userWithoutFlag, attributes }) const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(2) @@ -405,7 +405,7 @@ describe('Test video blacklist', function () { name: 'Torrent import', channelId: channelOfUserWithoutFlag } - await servers[0].importsCommand.importVideo({ token: userWithoutFlag, attributes }) + await servers[0].imports.importVideo({ token: userWithoutFlag, attributes }) const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(3) @@ -413,7 +413,7 @@ describe('Test video blacklist', function () { }) it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { - await servers[0].videosCommand.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } }) + await servers[0].videos.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } }) const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(3) -- cgit v1.2.3 From 254d3579f5338f5fd775c17d15cdfc37078bcfb4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:47:51 +0200 Subject: Use an object to represent a server --- server/tests/api/moderation/abuses.ts | 12 ++++++------ server/tests/api/moderation/blocklist-notification.ts | 8 ++++---- server/tests/api/moderation/blocklist.ts | 16 ++++++++-------- server/tests/api/moderation/video-blacklist.ts | 13 ++++++------- 4 files changed, 24 insertions(+), 25 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index 97a0d95c4..360b9de35 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -6,8 +6,8 @@ import { AbusesCommand, cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' @@ -16,7 +16,7 @@ import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, Use const expect = chai.expect describe('Test abuses', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let abuseServer1: AdminAbuse let abuseServer2: AdminAbuse let commands: AbusesCommand[] @@ -25,7 +25,7 @@ describe('Test abuses', function () { this.timeout(50000) // Run servers - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) @@ -389,7 +389,7 @@ describe('Test abuses', function () { describe('Comment abuses', function () { - async function getComment (server: ServerInfo, videoIdArg: number | string) { + async function getComment (server: PeerTubeServer, videoIdArg: number | string) { const videoId = typeof videoIdArg === 'string' ? await server.videos.getId({ uuid: videoIdArg }) : videoIdArg @@ -591,7 +591,7 @@ describe('Test abuses', function () { describe('Account abuses', function () { - function getAccountFromServer (server: ServerInfo, targetName: string, targetServer: ServerInfo) { + function getAccountFromServer (server: PeerTubeServer, targetName: string, targetServer: PeerTubeServer) { return server.accounts.get({ accountName: targetName + '@' + targetServer.host }) } diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index 6b56fdd65..fdfbcbced 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -2,12 +2,12 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' import { UserNotificationType } from '@shared/models' const expect = chai.expect -async function checkNotifications (server: ServerInfo, token: string, expected: UserNotificationType[]) { +async function checkNotifications (server: PeerTubeServer, token: string, expected: UserNotificationType[]) { const { data } = await server.notifications.list({ token, start: 0, count: 10, unread: true }) expect(data).to.have.lengthOf(expected.length) @@ -17,7 +17,7 @@ async function checkNotifications (server: ServerInfo, token: string, expected: } describe('Test blocklist', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let videoUUID: string let userToken1: string @@ -62,7 +62,7 @@ describe('Test blocklist', function () { before(async function () { this.timeout(60000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) { diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 9a4a3b3b9..593291e87 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -7,8 +7,8 @@ import { cleanupTests, CommentsCommand, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' @@ -16,7 +16,7 @@ import { UserNotificationType } from '@shared/models' const expect = chai.expect -async function checkAllVideos (server: ServerInfo, token: string) { +async function checkAllVideos (server: PeerTubeServer, token: string) { { const { data } = await server.videos.listWithToken({ token }) expect(data).to.have.lengthOf(5) @@ -28,7 +28,7 @@ async function checkAllVideos (server: ServerInfo, token: string) { } } -async function checkAllComments (server: ServerInfo, token: string, videoUUID: string) { +async function checkAllComments (server: PeerTubeServer, token: string, videoUUID: string) { const { data } = await server.comments.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token }) const threads = data.filter(t => t.isDeleted === false) @@ -41,8 +41,8 @@ async function checkAllComments (server: ServerInfo, token: string, videoUUID: s } async function checkCommentNotification ( - mainServer: ServerInfo, - comment: { server: ServerInfo, token: string, videoUUID: string, text: string }, + mainServer: PeerTubeServer, + comment: { server: PeerTubeServer, token: string, videoUUID: string, text: string }, check: 'presence' | 'absence' ) { const command = comment.server.comments @@ -63,7 +63,7 @@ async function checkCommentNotification ( } describe('Test blocklist', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let videoUUID1: string let videoUUID2: string let videoUUID3: string @@ -77,7 +77,7 @@ describe('Test blocklist', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) await setAccessTokensToServers(servers) command = servers[0].blocklist diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index d23d23bcb..62cbf2e07 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -7,11 +7,10 @@ import { BlacklistCommand, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, ImportsCommand, killallServers, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' @@ -20,11 +19,11 @@ import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@sh const expect = chai.expect describe('Test video blacklist', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let videoId: number let command: BlacklistCommand - async function blacklistVideosOnServer (server: ServerInfo) { + async function blacklistVideosOnServer (server: PeerTubeServer) { const { data } = await server.videos.list() for (const video of data) { @@ -36,7 +35,7 @@ describe('Test video blacklist', function () { this.timeout(50000) // Run servers - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) @@ -344,7 +343,7 @@ describe('Test video blacklist', function () { } } } - await reRunServer(servers[0], config) + await servers[0].run(config) { const user = { username: 'user_without_flag', password: 'password' } -- cgit v1.2.3 From 59bbcced37005dd511daca9bd58ae2998cb931b1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:19:16 +0200 Subject: Centralize test URLs --- server/tests/api/moderation/video-blacklist.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index 62cbf2e07..d5838191a 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -6,9 +6,9 @@ import { orderBy } from 'lodash' import { BlacklistCommand, cleanupTests, - doubleFollow, createMultipleServers, - ImportsCommand, + doubleFollow, + FIXTURE_URLS, killallServers, PeerTubeServer, setAccessTokensToServers, @@ -387,7 +387,7 @@ describe('Test video blacklist', function () { this.timeout(15000) const attributes = { - targetUrl: ImportsCommand.getGoodVideoUrl(), + targetUrl: FIXTURE_URLS.goodVideo, name: 'URL import', channelId: channelOfUserWithoutFlag } @@ -400,7 +400,7 @@ describe('Test video blacklist', function () { it('Should auto blacklist a video on torrent import', async function () { const attributes = { - magnetUri: ImportsCommand.getMagnetURI(), + magnetUri: FIXTURE_URLS.magnet, name: 'Torrent import', channelId: channelOfUserWithoutFlag } -- cgit v1.2.3 From c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:42:24 +0200 Subject: Refactor requests --- server/tests/api/moderation/abuses.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index 360b9de35..8d6360eb3 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { AbusesCommand, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs @@ -65,7 +65,7 @@ describe('Test abuses', function () { expect(data.length).to.equal(2) servers[0].store.video = data.find(video => video.name === 'my super name for server 1') - servers[1].store.video = data.find(video => video.name === 'my super name for server 2') + servers[1].store.video = data.find(video => video.name === 'my super name for server 2') }) it('Should not have abuses', async function () { @@ -402,8 +402,8 @@ describe('Test abuses', function () { before(async function () { this.timeout(50000) - servers[0].store.video = await await servers[0].videos.quickUpload({ name: 'server 1' }) - servers[1].store.video = await await servers[1].videos.quickUpload({ name: 'server 2' }) + servers[0].store.video = await servers[0].videos.quickUpload({ name: 'server 1' }) + servers[1].store.video = await servers[1].videos.quickUpload({ name: 'server 2' }) await servers[0].comments.createThread({ videoId: servers[0].store.video.id, text: 'comment server 1' }) await servers[1].comments.createThread({ videoId: servers[1].store.video.id, text: 'comment server 2' }) -- cgit v1.2.3 From 4c7e60bc17ee5830399bac4aa273356903421b4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 14:27:30 +0200 Subject: Reorganize imports --- server/tests/api/moderation/blocklist-notification.ts | 2 +- server/tests/api/moderation/blocklist.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index fdfbcbced..75b15c298 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' import { UserNotificationType } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 593291e87..8ed5ad9e5 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -6,8 +6,8 @@ import { BlocklistCommand, cleanupTests, CommentsCommand, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs -- cgit v1.2.3 From 4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Jul 2021 14:15:15 +0200 Subject: Add ability for instances to follow any actor --- server/tests/api/moderation/blocklist.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 8ed5ad9e5..089af8b15 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -690,7 +690,7 @@ describe('Test blocklist', function () { const now = new Date() await servers[1].follows.unfollow({ target: servers[0] }) await waitJobs(servers) - await servers[1].follows.follow({ targets: [ servers[0].host ] }) + await servers[1].follows.follow({ hosts: [ servers[0].host ] }) await waitJobs(servers) @@ -751,7 +751,7 @@ describe('Test blocklist', function () { const now = new Date() await servers[1].follows.unfollow({ target: servers[0] }) await waitJobs(servers) - await servers[1].follows.follow({ targets: [ servers[0].host ] }) + await servers[1].follows.follow({ hosts: [ servers[0].host ] }) await waitJobs(servers) -- cgit v1.2.3