aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/moderation
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-09 14:15:11 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commit12edc1495a36b2199f1bf1ba37f50c7b694be382 (patch)
tree3abfe2e5b54076de73fbfa25386d0313fc3b7242 /server/tests/api/moderation
parenta54618880c394ad7571f3f3222dc96ec2dd10d9a (diff)
downloadPeerTube-12edc1495a36b2199f1bf1ba37f50c7b694be382.tar.gz
PeerTube-12edc1495a36b2199f1bf1ba37f50c7b694be382.tar.zst
PeerTube-12edc1495a36b2199f1bf1ba37f50c7b694be382.zip
Introduce comments command
Diffstat (limited to 'server/tests/api/moderation')
-rw-r--r--server/tests/api/moderation/abuses.ts29
-rw-r--r--server/tests/api/moderation/blocklist-notification.ts7
-rw-r--r--server/tests/api/moderation/blocklist.ts196
3 files changed, 110 insertions, 122 deletions
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'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 AbusesCommand, 6 AbusesCommand,
7 addVideoCommentThread,
8 cleanupTests, 7 cleanupTests,
9 createUser, 8 createUser,
10 deleteVideoComment,
11 doubleFollow, 9 doubleFollow,
12 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
13 generateUserAccessToken, 11 generateUserAccessToken,
14 getVideoCommentThreads,
15 getVideoIdFromUUID, 12 getVideoIdFromUUID,
16 getVideosList, 13 getVideosList,
17 removeUser, 14 removeUser,
@@ -23,7 +20,7 @@ import {
23 userLogin, 20 userLogin,
24 waitJobs 21 waitJobs
25} from '@shared/extra-utils' 22} from '@shared/extra-utils'
26import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse, VideoComment } from '@shared/models' 23import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
27 24
28const expect = chai.expect 25const expect = chai.expect
29 26
@@ -399,14 +396,14 @@ describe('Test abuses', function () {
399 396
400 describe('Comment abuses', function () { 397 describe('Comment abuses', function () {
401 398
402 async function getComment (url: string, videoIdArg: number | string) { 399 async function getComment (server: ServerInfo, videoIdArg: number | string) {
403 const videoId = typeof videoIdArg === 'string' 400 const videoId = typeof videoIdArg === 'string'
404 ? await getVideoIdFromUUID(url, videoIdArg) 401 ? await getVideoIdFromUUID(server.url, videoIdArg)
405 : videoIdArg 402 : videoIdArg
406 403
407 const res = await getVideoCommentThreads(url, videoId, 0, 5) 404 const { data } = await server.commentsCommand.listThreads({ videoId })
408 405
409 return res.body.data[0] as VideoComment 406 return data[0]
410 } 407 }
411 408
412 before(async function () { 409 before(async function () {
@@ -415,8 +412,8 @@ describe('Test abuses', function () {
415 servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' }) 412 servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })
416 servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' }) 413 servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })
417 414
418 await addVideoCommentThread(servers[0].url, servers[0].accessToken, servers[0].video.id, 'comment server 1') 415 await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' })
419 await addVideoCommentThread(servers[1].url, servers[1].accessToken, servers[1].video.id, 'comment server 2') 416 await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' })
420 417
421 await waitJobs(servers) 418 await waitJobs(servers)
422 }) 419 })
@@ -424,7 +421,7 @@ describe('Test abuses', function () {
424 it('Should report abuse on a comment', async function () { 421 it('Should report abuse on a comment', async function () {
425 this.timeout(15000) 422 this.timeout(15000)
426 423
427 const comment = await getComment(servers[0].url, servers[0].video.id) 424 const comment = await getComment(servers[0], servers[0].video.id)
428 425
429 const reason = 'it is a bad comment' 426 const reason = 'it is a bad comment'
430 await commands[0].report({ commentId: comment.id, reason }) 427 await commands[0].report({ commentId: comment.id, reason })
@@ -434,7 +431,7 @@ describe('Test abuses', function () {
434 431
435 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () { 432 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
436 { 433 {
437 const comment = await getComment(servers[0].url, servers[0].video.id) 434 const comment = await getComment(servers[0], servers[0].video.id)
438 const body = await commands[0].getAdminList({ filter: 'comment' }) 435 const body = await commands[0].getAdminList({ filter: 'comment' })
439 436
440 expect(body.total).to.equal(1) 437 expect(body.total).to.equal(1)
@@ -469,7 +466,7 @@ describe('Test abuses', function () {
469 it('Should report abuse on a remote comment', async function () { 466 it('Should report abuse on a remote comment', async function () {
470 this.timeout(10000) 467 this.timeout(10000)
471 468
472 const comment = await getComment(servers[0].url, servers[1].video.uuid) 469 const comment = await getComment(servers[0], servers[1].video.uuid)
473 470
474 const reason = 'it is a really bad comment' 471 const reason = 'it is a really bad comment'
475 await commands[0].report({ commentId: comment.id, reason }) 472 await commands[0].report({ commentId: comment.id, reason })
@@ -478,7 +475,7 @@ describe('Test abuses', function () {
478 }) 475 })
479 476
480 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { 477 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
481 const commentServer2 = await getComment(servers[0].url, servers[1].video.id) 478 const commentServer2 = await getComment(servers[0], servers[1].video.id)
482 479
483 { 480 {
484 const body = await commands[0].getAdminList({ filter: 'comment' }) 481 const body = await commands[0].getAdminList({ filter: 'comment' })
@@ -537,9 +534,9 @@ describe('Test abuses', function () {
537 it('Should keep the comment abuse when deleting the comment', async function () { 534 it('Should keep the comment abuse when deleting the comment', async function () {
538 this.timeout(10000) 535 this.timeout(10000)
539 536
540 const commentServer2 = await getComment(servers[0].url, servers[1].video.id) 537 const commentServer2 = await getComment(servers[0], servers[1].video.id)
541 538
542 await deleteVideoComment(servers[0].url, servers[0].accessToken, servers[1].video.uuid, commentServer2.id) 539 await servers[0].commentsCommand.delete({ videoId: servers[1].video.uuid, commentId: commentServer2.id })
543 540
544 await waitJobs(servers) 541 await waitJobs(servers)
545 542
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 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 addVideoCommentThread,
7 cleanupTests, 6 cleanupTests,
8 createUser, 7 createUser,
9 doubleFollow, 8 doubleFollow,
@@ -59,7 +58,11 @@ describe('Test blocklist', function () {
59 } 58 }
60 59
61 { 60 {
62 await addVideoCommentThread(servers[1].url, remoteUserToken, videoUUID, '@user2@' + servers[0].host + ' hello') 61 await servers[1].commentsCommand.createThread({
62 token: remoteUserToken,
63 videoId: videoUUID,
64 text: '@user2@' + servers[0].host + ' hello'
65 })
63 } 66 }
64 67
65 { 68 {
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 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 addVideoCommentReply,
7 addVideoCommentThread,
8 BlocklistCommand, 6 BlocklistCommand,
9 cleanupTests, 7 cleanupTests,
8 CommentsCommand,
10 createUser, 9 createUser,
11 deleteVideoComment,
12 doubleFollow, 10 doubleFollow,
13 findCommentId,
14 flushAndRunMultipleServers, 11 flushAndRunMultipleServers,
15 getUserNotifications, 12 getUserNotifications,
16 getVideoCommentThreads,
17 getVideosList, 13 getVideosList,
18 getVideosListWithToken, 14 getVideosListWithToken,
19 getVideoThreadComments,
20 ServerInfo, 15 ServerInfo,
21 setAccessTokensToServers, 16 setAccessTokensToServers,
22 uploadVideo, 17 uploadVideo,
23 userLogin, 18 userLogin,
24 waitJobs 19 waitJobs
25} from '@shared/extra-utils' 20} from '@shared/extra-utils'
26import { UserNotification, UserNotificationType, Video, VideoComment, VideoCommentThreadTree } from '@shared/models' 21import { UserNotification, UserNotificationType, Video } from '@shared/models'
27 22
28const expect = chai.expect 23const expect = chai.expect
29 24
30async function checkAllVideos (url: string, token: string) { 25async function checkAllVideos (server: ServerInfo, token: string) {
31 { 26 {
32 const res = await getVideosListWithToken(url, token) 27 const res = await getVideosListWithToken(server.url, token)
33 28
34 expect(res.body.data).to.have.lengthOf(5) 29 expect(res.body.data).to.have.lengthOf(5)
35 } 30 }
36 31
37 { 32 {
38 const res = await getVideosList(url) 33 const res = await getVideosList(server.url)
39 34
40 expect(res.body.data).to.have.lengthOf(5) 35 expect(res.body.data).to.have.lengthOf(5)
41 } 36 }
42} 37}
43 38
44async function checkAllComments (url: string, token: string, videoUUID: string) { 39async function checkAllComments (server: ServerInfo, token: string, videoUUID: string) {
45 const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 25, '-createdAt', token) 40 const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token })
46 41
47 const allThreads: VideoComment[] = resThreads.body.data 42 const threads = data.filter(t => t.isDeleted === false)
48 const threads = allThreads.filter(t => t.isDeleted === false)
49 expect(threads).to.have.lengthOf(2) 43 expect(threads).to.have.lengthOf(2)
50 44
51 for (const thread of threads) { 45 for (const thread of threads) {
52 const res = await getVideoThreadComments(url, videoUUID, thread.id, token) 46 const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId: thread.id, token })
53
54 const tree: VideoCommentThreadTree = res.body
55 expect(tree.children).to.have.lengthOf(1) 47 expect(tree.children).to.have.lengthOf(1)
56 } 48 }
57} 49}
@@ -61,10 +53,9 @@ async function checkCommentNotification (
61 comment: { server: ServerInfo, token: string, videoUUID: string, text: string }, 53 comment: { server: ServerInfo, token: string, videoUUID: string, text: string },
62 check: 'presence' | 'absence' 54 check: 'presence' | 'absence'
63) { 55) {
64 const resComment = await addVideoCommentThread(comment.server.url, comment.token, comment.videoUUID, comment.text) 56 const command = comment.server.commentsCommand
65 const created = resComment.body.comment as VideoComment 57
66 const threadId = created.id 58 const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text })
67 const createdAt = created.createdAt
68 59
69 await waitJobs([ mainServer, comment.server ]) 60 await waitJobs([ mainServer, comment.server ])
70 61
@@ -75,7 +66,7 @@ async function checkCommentNotification (
75 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) 66 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
76 else expect(commentNotifications).to.have.lengthOf(0) 67 else expect(commentNotifications).to.have.lengthOf(0)
77 68
78 await deleteVideoComment(comment.server.url, comment.token, comment.videoUUID, threadId) 69 await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId })
79 70
80 await waitJobs([ mainServer, comment.server ]) 71 await waitJobs([ mainServer, comment.server ])
81} 72}
@@ -90,6 +81,7 @@ describe('Test blocklist', function () {
90 let userToken2: string 81 let userToken2: string
91 82
92 let command: BlocklistCommand 83 let command: BlocklistCommand
84 let commentsCommand: CommentsCommand[]
93 85
94 before(async function () { 86 before(async function () {
95 this.timeout(120000) 87 this.timeout(120000)
@@ -97,6 +89,9 @@ describe('Test blocklist', function () {
97 servers = await flushAndRunMultipleServers(3) 89 servers = await flushAndRunMultipleServers(3)
98 await setAccessTokensToServers(servers) 90 await setAccessTokensToServers(servers)
99 91
92 command = servers[0].blocklistCommand
93 commentsCommand = servers.map(s => s.commentsCommand)
94
100 { 95 {
101 const user = { username: 'user1', password: 'password' } 96 const user = { username: 'user1', password: 'password' }
102 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 97 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
@@ -139,30 +134,33 @@ describe('Test blocklist', function () {
139 await doubleFollow(servers[0], servers[2]) 134 await doubleFollow(servers[0], servers[2])
140 135
141 { 136 {
142 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID1, 'comment root 1') 137 const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' })
143 const resReply = await addVideoCommentReply(servers[0].url, userToken1, videoUUID1, resComment.body.comment.id, 'comment user 1') 138 const reply = await commentsCommand[0].addReply({
144 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resReply.body.comment.id, 'comment root 1') 139 token: userToken1,
140 videoId: videoUUID1,
141 toCommentId: created.id,
142 text: 'comment user 1'
143 })
144 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' })
145 } 145 }
146 146
147 { 147 {
148 const resComment = await addVideoCommentThread(servers[0].url, userToken1, videoUUID1, 'comment user 1') 148 const created = await commentsCommand[0].createThread({ token: userToken1, videoId: videoUUID1, text: 'comment user 1' })
149 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resComment.body.comment.id, 'comment root 1') 149 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: created.id, text: 'comment root 1' })
150 } 150 }
151 151
152 await waitJobs(servers) 152 await waitJobs(servers)
153
154 command = servers[0].blocklistCommand
155 }) 153 })
156 154
157 describe('User blocklist', function () { 155 describe('User blocklist', function () {
158 156
159 describe('When managing account blocklist', function () { 157 describe('When managing account blocklist', function () {
160 it('Should list all videos', function () { 158 it('Should list all videos', function () {
161 return checkAllVideos(servers[0].url, servers[0].accessToken) 159 return checkAllVideos(servers[0], servers[0].accessToken)
162 }) 160 })
163 161
164 it('Should list the comments', function () { 162 it('Should list the comments', function () {
165 return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) 163 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
166 }) 164 })
167 165
168 it('Should block a remote account', async function () { 166 it('Should block a remote account', async function () {
@@ -194,19 +192,26 @@ describe('Test blocklist', function () {
194 }) 192 })
195 193
196 it('Should hide its comments', async function () { 194 it('Should hide its comments', async function () {
197 const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 25, '-createdAt', servers[0].accessToken) 195 const { data } = await commentsCommand[0].listThreads({
198 196 token: servers[0].accessToken,
199 const threads: VideoComment[] = resThreads.body.data 197 videoId: videoUUID1,
200 expect(threads).to.have.lengthOf(1) 198 start: 0,
201 expect(threads[0].totalReplies).to.equal(1) 199 count: 25,
202 200 sort: '-createdAt'
203 const t = threads.find(t => t.text === 'comment user 1') 201 })
202
203 expect(data).to.have.lengthOf(1)
204 expect(data[0].totalReplies).to.equal(1)
205
206 const t = data.find(t => t.text === 'comment user 1')
204 expect(t).to.be.undefined 207 expect(t).to.be.undefined
205 208
206 for (const thread of threads) { 209 for (const thread of data) {
207 const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, servers[0].accessToken) 210 const tree = await commentsCommand[0].getThread({
208 211 videoId: videoUUID1,
209 const tree: VideoCommentThreadTree = res.body 212 threadId: thread.id,
213 token: servers[0].accessToken
214 })
210 expect(tree.children).to.have.lengthOf(0) 215 expect(tree.children).to.have.lengthOf(0)
211 } 216 }
212 }) 217 })
@@ -231,7 +236,7 @@ describe('Test blocklist', function () {
231 }) 236 })
232 237
233 it('Should list all the videos with another user', async function () { 238 it('Should list all the videos with another user', async function () {
234 return checkAllVideos(servers[0].url, userToken1) 239 return checkAllVideos(servers[0], userToken1)
235 }) 240 })
236 241
237 it('Should list blocked accounts', async function () { 242 it('Should list blocked accounts', async function () {
@@ -264,32 +269,29 @@ describe('Test blocklist', function () {
264 this.timeout(60000) 269 this.timeout(60000)
265 270
266 { 271 {
267 await addVideoCommentThread(servers[1].url, userToken2, videoUUID3, 'comment user 2') 272 await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' })
268 await waitJobs(servers) 273 await waitJobs(servers)
269 274
270 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID3, 'uploader') 275 await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' })
271 await waitJobs(servers) 276 await waitJobs(servers)
272 277
273 const commentId = await findCommentId(servers[1].url, videoUUID3, 'uploader') 278 const commentId = await commentsCommand[1].findCommentId({ videoId: videoUUID3, text: 'uploader' })
274 const message = 'reply by user 2' 279 const message = 'reply by user 2'
275 const resReply = await addVideoCommentReply(servers[1].url, userToken2, videoUUID3, commentId, message) 280 const reply = await commentsCommand[1].addReply({ token: userToken2, videoId: videoUUID3, toCommentId: commentId, text: message })
276 await addVideoCommentReply(servers[1].url, servers[1].accessToken, videoUUID3, resReply.body.comment.id, 'another reply') 281 await commentsCommand[1].addReply({ videoId: videoUUID3, toCommentId: reply.id, text: 'another reply' })
277 282
278 await waitJobs(servers) 283 await waitJobs(servers)
279 } 284 }
280 285
281 // Server 2 has all the comments 286 // Server 2 has all the comments
282 { 287 {
283 const resThreads = await getVideoCommentThreads(servers[1].url, videoUUID3, 0, 25, '-createdAt') 288 const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
284 const threads: VideoComment[] = resThreads.body.data
285
286 expect(threads).to.have.lengthOf(2)
287 expect(threads[0].text).to.equal('uploader')
288 expect(threads[1].text).to.equal('comment user 2')
289 289
290 const resReplies = await getVideoThreadComments(servers[1].url, videoUUID3, threads[0].id) 290 expect(data).to.have.lengthOf(2)
291 expect(data[0].text).to.equal('uploader')
292 expect(data[1].text).to.equal('comment user 2')
291 293
292 const tree: VideoCommentThreadTree = resReplies.body 294 const tree = await commentsCommand[1].getThread({ videoId: videoUUID3, threadId: data[0].id })
293 expect(tree.children).to.have.lengthOf(1) 295 expect(tree.children).to.have.lengthOf(1)
294 expect(tree.children[0].comment.text).to.equal('reply by user 2') 296 expect(tree.children[0].comment.text).to.equal('reply by user 2')
295 expect(tree.children[0].children).to.have.lengthOf(1) 297 expect(tree.children[0].children).to.have.lengthOf(1)
@@ -298,20 +300,15 @@ describe('Test blocklist', function () {
298 300
299 // Server 1 and 3 should only have uploader comments 301 // Server 1 and 3 should only have uploader comments
300 for (const server of [ servers[0], servers[2] ]) { 302 for (const server of [ servers[0], servers[2] ]) {
301 const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt') 303 const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
302 const threads: VideoComment[] = resThreads.body.data
303 304
304 expect(threads).to.have.lengthOf(1) 305 expect(data).to.have.lengthOf(1)
305 expect(threads[0].text).to.equal('uploader') 306 expect(data[0].text).to.equal('uploader')
306 307
307 const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id) 308 const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id })
308 309
309 const tree: VideoCommentThreadTree = resReplies.body 310 if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0)
310 if (server.serverNumber === 1) { 311 else expect(tree.children).to.have.lengthOf(1)
311 expect(tree.children).to.have.lengthOf(0)
312 } else {
313 expect(tree.children).to.have.lengthOf(1)
314 }
315 } 312 }
316 }) 313 })
317 314
@@ -331,22 +328,19 @@ describe('Test blocklist', function () {
331 328
332 it('Should display its comments on my video', async function () { 329 it('Should display its comments on my video', async function () {
333 for (const server of servers) { 330 for (const server of servers) {
334 const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt') 331 const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
335 const threads: VideoComment[] = resThreads.body.data
336 332
337 // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment 333 // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment
338 if (server.serverNumber === 3) { 334 if (server.serverNumber === 3) {
339 expect(threads).to.have.lengthOf(1) 335 expect(data).to.have.lengthOf(1)
340 continue 336 continue
341 } 337 }
342 338
343 expect(threads).to.have.lengthOf(2) 339 expect(data).to.have.lengthOf(2)
344 expect(threads[0].text).to.equal('uploader') 340 expect(data[0].text).to.equal('uploader')
345 expect(threads[1].text).to.equal('comment user 2') 341 expect(data[1].text).to.equal('comment user 2')
346
347 const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id)
348 342
349 const tree: VideoCommentThreadTree = resReplies.body 343 const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id })
350 expect(tree.children).to.have.lengthOf(1) 344 expect(tree.children).to.have.lengthOf(1)
351 expect(tree.children[0].comment.text).to.equal('reply by user 2') 345 expect(tree.children[0].comment.text).to.equal('reply by user 2')
352 expect(tree.children[0].children).to.have.lengthOf(1) 346 expect(tree.children[0].children).to.have.lengthOf(1)
@@ -359,7 +353,7 @@ describe('Test blocklist', function () {
359 }) 353 })
360 354
361 it('Should display its comments', function () { 355 it('Should display its comments', function () {
362 return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) 356 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
363 }) 357 })
364 358
365 it('Should have a notification from a non blocked account', async function () { 359 it('Should have a notification from a non blocked account', async function () {
@@ -385,11 +379,11 @@ describe('Test blocklist', function () {
385 describe('When managing server blocklist', function () { 379 describe('When managing server blocklist', function () {
386 380
387 it('Should list all videos', function () { 381 it('Should list all videos', function () {
388 return checkAllVideos(servers[0].url, servers[0].accessToken) 382 return checkAllVideos(servers[0], servers[0].accessToken)
389 }) 383 })
390 384
391 it('Should list the comments', function () { 385 it('Should list the comments', function () {
392 return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) 386 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
393 }) 387 })
394 388
395 it('Should block a remote server', async function () { 389 it('Should block a remote server', async function () {
@@ -410,20 +404,19 @@ describe('Test blocklist', function () {
410 }) 404 })
411 405
412 it('Should list all the videos with another user', async function () { 406 it('Should list all the videos with another user', async function () {
413 return checkAllVideos(servers[0].url, userToken1) 407 return checkAllVideos(servers[0], userToken1)
414 }) 408 })
415 409
416 it('Should hide its comments', async function () { 410 it('Should hide its comments', async function () {
417 this.timeout(10000) 411 this.timeout(10000)
418 412
419 const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2') 413 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
420 const threadId = resThreads.body.comment.id
421 414
422 await waitJobs(servers) 415 await waitJobs(servers)
423 416
424 await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) 417 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
425 418
426 await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId) 419 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
427 }) 420 })
428 421
429 it('Should not have notifications from blocked server', async function () { 422 it('Should not have notifications from blocked server', async function () {
@@ -460,11 +453,11 @@ describe('Test blocklist', function () {
460 }) 453 })
461 454
462 it('Should display its videos', function () { 455 it('Should display its videos', function () {
463 return checkAllVideos(servers[0].url, servers[0].accessToken) 456 return checkAllVideos(servers[0], servers[0].accessToken)
464 }) 457 })
465 458
466 it('Should display its comments', function () { 459 it('Should display its comments', function () {
467 return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) 460 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
468 }) 461 })
469 462
470 it('Should have notification from unblocked server', async function () { 463 it('Should have notification from unblocked server', async function () {
@@ -493,13 +486,13 @@ describe('Test blocklist', function () {
493 describe('When managing account blocklist', function () { 486 describe('When managing account blocklist', function () {
494 it('Should list all videos', async function () { 487 it('Should list all videos', async function () {
495 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 488 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
496 await checkAllVideos(servers[0].url, token) 489 await checkAllVideos(servers[0], token)
497 } 490 }
498 }) 491 })
499 492
500 it('Should list the comments', async function () { 493 it('Should list the comments', async function () {
501 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 494 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
502 await checkAllComments(servers[0].url, token, videoUUID1) 495 await checkAllComments(servers[0], token, videoUUID1)
503 } 496 }
504 }) 497 })
505 498
@@ -537,10 +530,8 @@ describe('Test blocklist', function () {
537 530
538 it('Should hide its comments', async function () { 531 it('Should hide its comments', async function () {
539 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 532 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
540 const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 20, '-createdAt', token) 533 const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token })
541 534 const threads = data.filter(t => t.isDeleted === false)
542 let threads: VideoComment[] = resThreads.body.data
543 threads = threads.filter(t => t.isDeleted === false)
544 535
545 expect(threads).to.have.lengthOf(1) 536 expect(threads).to.have.lengthOf(1)
546 expect(threads[0].totalReplies).to.equal(1) 537 expect(threads[0].totalReplies).to.equal(1)
@@ -549,9 +540,7 @@ describe('Test blocklist', function () {
549 expect(t).to.be.undefined 540 expect(t).to.be.undefined
550 541
551 for (const thread of threads) { 542 for (const thread of threads) {
552 const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, token) 543 const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token })
553
554 const tree: VideoCommentThreadTree = res.body
555 expect(tree.children).to.have.lengthOf(0) 544 expect(tree.children).to.have.lengthOf(0)
556 } 545 }
557 } 546 }
@@ -624,7 +613,7 @@ describe('Test blocklist', function () {
624 613
625 it('Should display its comments', async function () { 614 it('Should display its comments', async function () {
626 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 615 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
627 await checkAllComments(servers[0].url, token, videoUUID1) 616 await checkAllComments(servers[0], token, videoUUID1)
628 } 617 }
629 }) 618 })
630 619
@@ -651,13 +640,13 @@ describe('Test blocklist', function () {
651 describe('When managing server blocklist', function () { 640 describe('When managing server blocklist', function () {
652 it('Should list all videos', async function () { 641 it('Should list all videos', async function () {
653 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 642 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
654 await checkAllVideos(servers[0].url, token) 643 await checkAllVideos(servers[0], token)
655 } 644 }
656 }) 645 })
657 646
658 it('Should list the comments', async function () { 647 it('Should list the comments', async function () {
659 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 648 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
660 await checkAllComments(servers[0].url, token, videoUUID1) 649 await checkAllComments(servers[0], token, videoUUID1)
661 } 650 }
662 }) 651 })
663 652
@@ -686,14 +675,13 @@ describe('Test blocklist', function () {
686 it('Should hide its comments', async function () { 675 it('Should hide its comments', async function () {
687 this.timeout(10000) 676 this.timeout(10000)
688 677
689 const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2') 678 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
690 const threadId = resThreads.body.comment.id
691 679
692 await waitJobs(servers) 680 await waitJobs(servers)
693 681
694 await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) 682 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
695 683
696 await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId) 684 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
697 }) 685 })
698 686
699 it('Should not have notification from blocked instances by instance', async function () { 687 it('Should not have notification from blocked instances by instance', async function () {
@@ -749,13 +737,13 @@ describe('Test blocklist', function () {
749 737
750 it('Should list all videos', async function () { 738 it('Should list all videos', async function () {
751 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 739 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
752 await checkAllVideos(servers[0].url, token) 740 await checkAllVideos(servers[0], token)
753 } 741 }
754 }) 742 })
755 743
756 it('Should list the comments', async function () { 744 it('Should list the comments', async function () {
757 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 745 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
758 await checkAllComments(servers[0].url, token, videoUUID1) 746 await checkAllComments(servers[0], token, videoUUID1)
759 } 747 }
760 }) 748 })
761 749