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/blocklist.ts') 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 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/blocklist.ts | 100 ++++++++++++------------------- 1 file changed, 37 insertions(+), 63 deletions(-) (limited to 'server/tests/api/moderation/blocklist.ts') 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 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/blocklist.ts | 196 +++++++++++++++---------------- 1 file changed, 92 insertions(+), 104 deletions(-) (limited to 'server/tests/api/moderation/blocklist.ts') 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 dd0ebb715123dfa126a82d4e4fe3a04064ae77b8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 16:23:01 +0200 Subject: Introduce notifications command --- server/tests/api/moderation/blocklist.ts | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'server/tests/api/moderation/blocklist.ts') 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/blocklist.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'server/tests/api/moderation/blocklist.ts') 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' }) } -- 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/blocklist.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'server/tests/api/moderation/blocklist.ts') 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' }) -- 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/blocklist.ts | 100 ++++++++++++++----------------- 1 file changed, 44 insertions(+), 56 deletions(-) (limited to 'server/tests/api/moderation/blocklist.ts') 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 -- 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/blocklist.ts | 76 ++++++++++++++++---------------- 1 file changed, 38 insertions(+), 38 deletions(-) (limited to 'server/tests/api/moderation/blocklist.ts') 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() }) -- 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/blocklist.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'server/tests/api/moderation/blocklist.ts') 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 -- 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.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/tests/api/moderation/blocklist.ts') 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/blocklist.ts') 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