X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fmoderation%2Fblocklist.ts;h=1b8860571e1267023b306e561100ca3a089e959e;hb=6910f20f114b5bd020258a3a9a3f2117819a60c2;hp=8c9107a509c3c216aa04ec3410468b920ce5ab0d;hpb=17aa80ed016bafa3ccb071af3f86054033823284;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 8c9107a50..1b8860571 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -1,46 +1,29 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { AccountBlock, ServerBlock, Video, UserNotification, UserNotificationType } from '../../../../shared/index' +import * as chai from 'chai' import { + addVideoCommentReply, + addVideoCommentThread, + BlocklistCommand, cleanupTests, createUser, deleteVideoComment, doubleFollow, + findCommentId, flushAndRunMultipleServers, + getUserNotifications, + getVideoCommentThreads, + getVideosList, + getVideosListWithToken, + getVideoThreadComments, ServerInfo, + setAccessTokensToServers, uploadVideo, userLogin, - follow, - unfollow -} from '../../../../shared/extra-utils/index' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' -import { getVideosList, getVideosListWithToken } from '../../../../shared/extra-utils/videos/videos' -import { - addVideoCommentReply, - addVideoCommentThread, - getVideoCommentThreads, - getVideoThreadComments, - findCommentId -} from '../../../../shared/extra-utils/videos/video-comments' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' -import { - addAccountToAccountBlocklist, - addAccountToServerBlocklist, - addServerToAccountBlocklist, - addServerToServerBlocklist, - getAccountBlocklistByAccount, - getAccountBlocklistByServer, - getServerBlocklistByAccount, - getServerBlocklistByServer, - removeAccountFromAccountBlocklist, - removeAccountFromServerBlocklist, - removeServerFromAccountBlocklist, - removeServerFromServerBlocklist -} from '../../../../shared/extra-utils/users/blocklist' -import { getUserNotifications } from '../../../../shared/extra-utils/users/user-notifications' + waitJobs +} from '@shared/extra-utils' +import { UserNotification, UserNotificationType, Video, VideoComment, VideoCommentThreadTree } from '@shared/models' const expect = chai.expect @@ -106,8 +89,10 @@ describe('Test blocklist', function () { let userModeratorToken: string let userToken2: string + let command: BlocklistCommand + before(async function () { - this.timeout(60000) + this.timeout(120000) servers = await flushAndRunMultipleServers(3) await setAccessTokensToServers(servers) @@ -165,6 +150,8 @@ describe('Test blocklist', function () { } await waitJobs(servers) + + command = servers[0].blocklistCommand }) describe('User blocklist', function () { @@ -179,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 () { @@ -193,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 () { @@ -211,7 +198,7 @@ describe('Test blocklist', function () { const threads: VideoComment[] = resThreads.body.data expect(threads).to.have.lengthOf(1) - expect(threads[0].totalReplies).to.equal(0) + expect(threads[0].totalReplies).to.equal(1) const t = threads.find(t => t.text === 'comment user 1') expect(t).to.be.undefined @@ -249,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') @@ -263,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') @@ -333,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 () { @@ -372,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 () { @@ -400,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) }) @@ -409,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 () { @@ -462,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 () { @@ -522,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 () { @@ -538,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 () { @@ -561,7 +543,7 @@ describe('Test blocklist', function () { threads = threads.filter(t => t.isDeleted === false) expect(threads).to.have.lengthOf(1) - expect(threads[0].totalReplies).to.equal(0) + expect(threads[0].totalReplies).to.equal(1) const t = threads.find(t => t.text === 'comment user 1') expect(t).to.be.undefined @@ -596,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') @@ -610,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') @@ -625,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 () { @@ -641,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 () { @@ -684,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 () { @@ -738,9 +716,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) @@ -756,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 () { @@ -803,9 +779,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)