aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/moderation/blocklist.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/moderation/blocklist.ts')
-rw-r--r--server/tests/api/moderation/blocklist.ts446
1 files changed, 193 insertions, 253 deletions
diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts
index 793abbcb4..089af8b15 100644
--- a/server/tests/api/moderation/blocklist.ts
+++ b/server/tests/api/moderation/blocklist.ts
@@ -3,106 +3,67 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 addAccountToAccountBlocklist, 6 BlocklistCommand,
7 addAccountToServerBlocklist,
8 addServerToAccountBlocklist,
9 addServerToServerBlocklist,
10 addVideoCommentReply,
11 addVideoCommentThread,
12 cleanupTests, 7 cleanupTests,
13 createUser, 8 CommentsCommand,
14 deleteVideoComment, 9 createMultipleServers,
15 doubleFollow, 10 doubleFollow,
16 findCommentId, 11 PeerTubeServer,
17 flushAndRunMultipleServers,
18 follow,
19 getAccountBlocklistByAccount,
20 getAccountBlocklistByServer,
21 getServerBlocklistByAccount,
22 getServerBlocklistByServer,
23 getUserNotifications,
24 getVideoCommentThreads,
25 getVideosList,
26 getVideosListWithToken,
27 getVideoThreadComments,
28 removeAccountFromAccountBlocklist,
29 removeAccountFromServerBlocklist,
30 removeServerFromAccountBlocklist,
31 removeServerFromServerBlocklist,
32 ServerInfo,
33 setAccessTokensToServers, 12 setAccessTokensToServers,
34 unfollow,
35 uploadVideo,
36 userLogin,
37 waitJobs 13 waitJobs
38} from '@shared/extra-utils' 14} from '@shared/extra-utils'
39import { 15import { UserNotificationType } from '@shared/models'
40 AccountBlock,
41 ServerBlock,
42 UserNotification,
43 UserNotificationType,
44 Video,
45 VideoComment,
46 VideoCommentThreadTree
47} from '@shared/models'
48 16
49const expect = chai.expect 17const expect = chai.expect
50 18
51async function checkAllVideos (url: string, token: string) { 19async function checkAllVideos (server: PeerTubeServer, token: string) {
52 { 20 {
53 const res = await getVideosListWithToken(url, token) 21 const { data } = await server.videos.listWithToken({ token })
54 22 expect(data).to.have.lengthOf(5)
55 expect(res.body.data).to.have.lengthOf(5)
56 } 23 }
57 24
58 { 25 {
59 const res = await getVideosList(url) 26 const { data } = await server.videos.list()
60 27 expect(data).to.have.lengthOf(5)
61 expect(res.body.data).to.have.lengthOf(5)
62 } 28 }
63} 29}
64 30
65async function checkAllComments (url: string, token: string, videoUUID: string) { 31async function checkAllComments (server: PeerTubeServer, token: string, videoUUID: string) {
66 const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 25, '-createdAt', token) 32 const { data } = await server.comments.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token })
67 33
68 const allThreads: VideoComment[] = resThreads.body.data 34 const threads = data.filter(t => t.isDeleted === false)
69 const threads = allThreads.filter(t => t.isDeleted === false)
70 expect(threads).to.have.lengthOf(2) 35 expect(threads).to.have.lengthOf(2)
71 36
72 for (const thread of threads) { 37 for (const thread of threads) {
73 const res = await getVideoThreadComments(url, videoUUID, thread.id, token) 38 const tree = await server.comments.getThread({ videoId: videoUUID, threadId: thread.id, token })
74
75 const tree: VideoCommentThreadTree = res.body
76 expect(tree.children).to.have.lengthOf(1) 39 expect(tree.children).to.have.lengthOf(1)
77 } 40 }
78} 41}
79 42
80async function checkCommentNotification ( 43async function checkCommentNotification (
81 mainServer: ServerInfo, 44 mainServer: PeerTubeServer,
82 comment: { server: ServerInfo, token: string, videoUUID: string, text: string }, 45 comment: { server: PeerTubeServer, token: string, videoUUID: string, text: string },
83 check: 'presence' | 'absence' 46 check: 'presence' | 'absence'
84) { 47) {
85 const resComment = await addVideoCommentThread(comment.server.url, comment.token, comment.videoUUID, comment.text) 48 const command = comment.server.comments
86 const created = resComment.body.comment as VideoComment 49
87 const threadId = created.id 50 const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text })
88 const createdAt = created.createdAt
89 51
90 await waitJobs([ mainServer, comment.server ]) 52 await waitJobs([ mainServer, comment.server ])
91 53
92 const res = await getUserNotifications(mainServer.url, mainServer.accessToken, 0, 30) 54 const { data } = await mainServer.notifications.list({ start: 0, count: 30 })
93 const commentNotifications = (res.body.data as UserNotification[]) 55 const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
94 .filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
95 56
96 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) 57 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
97 else expect(commentNotifications).to.have.lengthOf(0) 58 else expect(commentNotifications).to.have.lengthOf(0)
98 59
99 await deleteVideoComment(comment.server.url, comment.token, comment.videoUUID, threadId) 60 await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId })
100 61
101 await waitJobs([ mainServer, comment.server ]) 62 await waitJobs([ mainServer, comment.server ])
102} 63}
103 64
104describe('Test blocklist', function () { 65describe('Test blocklist', function () {
105 let servers: ServerInfo[] 66 let servers: PeerTubeServer[]
106 let videoUUID1: string 67 let videoUUID1: string
107 let videoUUID2: string 68 let videoUUID2: string
108 let videoUUID3: string 69 let videoUUID3: string
@@ -110,62 +71,73 @@ describe('Test blocklist', function () {
110 let userModeratorToken: string 71 let userModeratorToken: string
111 let userToken2: string 72 let userToken2: string
112 73
74 let command: BlocklistCommand
75 let commentsCommand: CommentsCommand[]
76
113 before(async function () { 77 before(async function () {
114 this.timeout(120000) 78 this.timeout(120000)
115 79
116 servers = await flushAndRunMultipleServers(3) 80 servers = await createMultipleServers(3)
117 await setAccessTokensToServers(servers) 81 await setAccessTokensToServers(servers)
118 82
83 command = servers[0].blocklist
84 commentsCommand = servers.map(s => s.comments)
85
119 { 86 {
120 const user = { username: 'user1', password: 'password' } 87 const user = { username: 'user1', password: 'password' }
121 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 88 await servers[0].users.create({ username: user.username, password: user.password })
122 89
123 userToken1 = await userLogin(servers[0], user) 90 userToken1 = await servers[0].login.getAccessToken(user)
124 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) 91 await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } })
125 } 92 }
126 93
127 { 94 {
128 const user = { username: 'moderator', password: 'password' } 95 const user = { username: 'moderator', password: 'password' }
129 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 96 await servers[0].users.create({ username: user.username, password: user.password })
130 97
131 userModeratorToken = await userLogin(servers[0], user) 98 userModeratorToken = await servers[0].login.getAccessToken(user)
132 } 99 }
133 100
134 { 101 {
135 const user = { username: 'user2', password: 'password' } 102 const user = { username: 'user2', password: 'password' }
136 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) 103 await servers[1].users.create({ username: user.username, password: user.password })
137 104
138 userToken2 = await userLogin(servers[1], user) 105 userToken2 = await servers[1].login.getAccessToken(user)
139 await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) 106 await servers[1].videos.upload({ token: userToken2, attributes: { name: 'video user 2' } })
140 } 107 }
141 108
142 { 109 {
143 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) 110 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
144 videoUUID1 = res.body.video.uuid 111 videoUUID1 = uuid
145 } 112 }
146 113
147 { 114 {
148 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) 115 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
149 videoUUID2 = res.body.video.uuid 116 videoUUID2 = uuid
150 } 117 }
151 118
152 { 119 {
153 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' }) 120 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } })
154 videoUUID3 = res.body.video.uuid 121 videoUUID3 = uuid
155 } 122 }
156 123
157 await doubleFollow(servers[0], servers[1]) 124 await doubleFollow(servers[0], servers[1])
158 await doubleFollow(servers[0], servers[2]) 125 await doubleFollow(servers[0], servers[2])
159 126
160 { 127 {
161 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID1, 'comment root 1') 128 const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' })
162 const resReply = await addVideoCommentReply(servers[0].url, userToken1, videoUUID1, resComment.body.comment.id, 'comment user 1') 129 const reply = await commentsCommand[0].addReply({
163 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resReply.body.comment.id, 'comment root 1') 130 token: userToken1,
131 videoId: videoUUID1,
132 toCommentId: created.id,
133 text: 'comment user 1'
134 })
135 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' })
164 } 136 }
165 137
166 { 138 {
167 const resComment = await addVideoCommentThread(servers[0].url, userToken1, videoUUID1, 'comment user 1') 139 const created = await commentsCommand[0].createThread({ token: userToken1, videoId: videoUUID1, text: 'comment user 1' })
168 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resComment.body.comment.id, 'comment root 1') 140 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: created.id, text: 'comment root 1' })
169 } 141 }
170 142
171 await waitJobs(servers) 143 await waitJobs(servers)
@@ -175,55 +147,60 @@ describe('Test blocklist', function () {
175 147
176 describe('When managing account blocklist', function () { 148 describe('When managing account blocklist', function () {
177 it('Should list all videos', function () { 149 it('Should list all videos', function () {
178 return checkAllVideos(servers[0].url, servers[0].accessToken) 150 return checkAllVideos(servers[0], servers[0].accessToken)
179 }) 151 })
180 152
181 it('Should list the comments', function () { 153 it('Should list the comments', function () {
182 return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) 154 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
183 }) 155 })
184 156
185 it('Should block a remote account', async function () { 157 it('Should block a remote account', async function () {
186 await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) 158 await command.addToMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
187 }) 159 })
188 160
189 it('Should hide its videos', async function () { 161 it('Should hide its videos', async function () {
190 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) 162 const { data } = await servers[0].videos.listWithToken()
191 163
192 const videos: Video[] = res.body.data 164 expect(data).to.have.lengthOf(4)
193 expect(videos).to.have.lengthOf(4)
194 165
195 const v = videos.find(v => v.name === 'video user 2') 166 const v = data.find(v => v.name === 'video user 2')
196 expect(v).to.be.undefined 167 expect(v).to.be.undefined
197 }) 168 })
198 169
199 it('Should block a local account', async function () { 170 it('Should block a local account', async function () {
200 await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') 171 await command.addToMyBlocklist({ account: 'user1' })
201 }) 172 })
202 173
203 it('Should hide its videos', async function () { 174 it('Should hide its videos', async function () {
204 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) 175 const { data } = await servers[0].videos.listWithToken()
205 176
206 const videos: Video[] = res.body.data 177 expect(data).to.have.lengthOf(3)
207 expect(videos).to.have.lengthOf(3)
208 178
209 const v = videos.find(v => v.name === 'video user 1') 179 const v = data.find(v => v.name === 'video user 1')
210 expect(v).to.be.undefined 180 expect(v).to.be.undefined
211 }) 181 })
212 182
213 it('Should hide its comments', async function () { 183 it('Should hide its comments', async function () {
214 const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 25, '-createdAt', servers[0].accessToken) 184 const { data } = await commentsCommand[0].listThreads({
215 185 token: servers[0].accessToken,
216 const threads: VideoComment[] = resThreads.body.data 186 videoId: videoUUID1,
217 expect(threads).to.have.lengthOf(1) 187 start: 0,
218 expect(threads[0].totalReplies).to.equal(1) 188 count: 25,
219 189 sort: '-createdAt'
220 const t = threads.find(t => t.text === 'comment user 1') 190 })
191
192 expect(data).to.have.lengthOf(1)
193 expect(data[0].totalReplies).to.equal(1)
194
195 const t = data.find(t => t.text === 'comment user 1')
221 expect(t).to.be.undefined 196 expect(t).to.be.undefined
222 197
223 for (const thread of threads) { 198 for (const thread of data) {
224 const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, servers[0].accessToken) 199 const tree = await commentsCommand[0].getThread({
225 200 videoId: videoUUID1,
226 const tree: VideoCommentThreadTree = res.body 201 threadId: thread.id,
202 token: servers[0].accessToken
203 })
227 expect(tree.children).to.have.lengthOf(0) 204 expect(tree.children).to.have.lengthOf(0)
228 } 205 }
229 }) 206 })
@@ -248,17 +225,15 @@ describe('Test blocklist', function () {
248 }) 225 })
249 226
250 it('Should list all the videos with another user', async function () { 227 it('Should list all the videos with another user', async function () {
251 return checkAllVideos(servers[0].url, userToken1) 228 return checkAllVideos(servers[0], userToken1)
252 }) 229 })
253 230
254 it('Should list blocked accounts', async function () { 231 it('Should list blocked accounts', async function () {
255 { 232 {
256 const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') 233 const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
257 const blocks: AccountBlock[] = res.body.data 234 expect(body.total).to.equal(2)
258 235
259 expect(res.body.total).to.equal(2) 236 const block = body.data[0]
260
261 const block = blocks[0]
262 expect(block.byAccount.displayName).to.equal('root') 237 expect(block.byAccount.displayName).to.equal('root')
263 expect(block.byAccount.name).to.equal('root') 238 expect(block.byAccount.name).to.equal('root')
264 expect(block.blockedAccount.displayName).to.equal('user2') 239 expect(block.blockedAccount.displayName).to.equal('user2')
@@ -267,12 +242,10 @@ describe('Test blocklist', function () {
267 } 242 }
268 243
269 { 244 {
270 const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt') 245 const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
271 const blocks: AccountBlock[] = res.body.data 246 expect(body.total).to.equal(2)
272
273 expect(res.body.total).to.equal(2)
274 247
275 const block = blocks[0] 248 const block = body.data[0]
276 expect(block.byAccount.displayName).to.equal('root') 249 expect(block.byAccount.displayName).to.equal('root')
277 expect(block.byAccount.name).to.equal('root') 250 expect(block.byAccount.name).to.equal('root')
278 expect(block.blockedAccount.displayName).to.equal('user1') 251 expect(block.blockedAccount.displayName).to.equal('user1')
@@ -285,32 +258,29 @@ describe('Test blocklist', function () {
285 this.timeout(60000) 258 this.timeout(60000)
286 259
287 { 260 {
288 await addVideoCommentThread(servers[1].url, userToken2, videoUUID3, 'comment user 2') 261 await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' })
289 await waitJobs(servers) 262 await waitJobs(servers)
290 263
291 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID3, 'uploader') 264 await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' })
292 await waitJobs(servers) 265 await waitJobs(servers)
293 266
294 const commentId = await findCommentId(servers[1].url, videoUUID3, 'uploader') 267 const commentId = await commentsCommand[1].findCommentId({ videoId: videoUUID3, text: 'uploader' })
295 const message = 'reply by user 2' 268 const message = 'reply by user 2'
296 const resReply = await addVideoCommentReply(servers[1].url, userToken2, videoUUID3, commentId, message) 269 const reply = await commentsCommand[1].addReply({ token: userToken2, videoId: videoUUID3, toCommentId: commentId, text: message })
297 await addVideoCommentReply(servers[1].url, servers[1].accessToken, videoUUID3, resReply.body.comment.id, 'another reply') 270 await commentsCommand[1].addReply({ videoId: videoUUID3, toCommentId: reply.id, text: 'another reply' })
298 271
299 await waitJobs(servers) 272 await waitJobs(servers)
300 } 273 }
301 274
302 // Server 2 has all the comments 275 // Server 2 has all the comments
303 { 276 {
304 const resThreads = await getVideoCommentThreads(servers[1].url, videoUUID3, 0, 25, '-createdAt') 277 const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
305 const threads: VideoComment[] = resThreads.body.data
306
307 expect(threads).to.have.lengthOf(2)
308 expect(threads[0].text).to.equal('uploader')
309 expect(threads[1].text).to.equal('comment user 2')
310 278
311 const resReplies = await getVideoThreadComments(servers[1].url, videoUUID3, threads[0].id) 279 expect(data).to.have.lengthOf(2)
280 expect(data[0].text).to.equal('uploader')
281 expect(data[1].text).to.equal('comment user 2')
312 282
313 const tree: VideoCommentThreadTree = resReplies.body 283 const tree = await commentsCommand[1].getThread({ videoId: videoUUID3, threadId: data[0].id })
314 expect(tree.children).to.have.lengthOf(1) 284 expect(tree.children).to.have.lengthOf(1)
315 expect(tree.children[0].comment.text).to.equal('reply by user 2') 285 expect(tree.children[0].comment.text).to.equal('reply by user 2')
316 expect(tree.children[0].children).to.have.lengthOf(1) 286 expect(tree.children[0].children).to.have.lengthOf(1)
@@ -319,55 +289,45 @@ describe('Test blocklist', function () {
319 289
320 // Server 1 and 3 should only have uploader comments 290 // Server 1 and 3 should only have uploader comments
321 for (const server of [ servers[0], servers[2] ]) { 291 for (const server of [ servers[0], servers[2] ]) {
322 const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt') 292 const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
323 const threads: VideoComment[] = resThreads.body.data
324 293
325 expect(threads).to.have.lengthOf(1) 294 expect(data).to.have.lengthOf(1)
326 expect(threads[0].text).to.equal('uploader') 295 expect(data[0].text).to.equal('uploader')
327 296
328 const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id) 297 const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
329 298
330 const tree: VideoCommentThreadTree = resReplies.body 299 if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0)
331 if (server.serverNumber === 1) { 300 else expect(tree.children).to.have.lengthOf(1)
332 expect(tree.children).to.have.lengthOf(0)
333 } else {
334 expect(tree.children).to.have.lengthOf(1)
335 }
336 } 301 }
337 }) 302 })
338 303
339 it('Should unblock the remote account', async function () { 304 it('Should unblock the remote account', async function () {
340 await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) 305 await command.removeFromMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
341 }) 306 })
342 307
343 it('Should display its videos', async function () { 308 it('Should display its videos', async function () {
344 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) 309 const { data } = await servers[0].videos.listWithToken()
345 310 expect(data).to.have.lengthOf(4)
346 const videos: Video[] = res.body.data
347 expect(videos).to.have.lengthOf(4)
348 311
349 const v = videos.find(v => v.name === 'video user 2') 312 const v = data.find(v => v.name === 'video user 2')
350 expect(v).not.to.be.undefined 313 expect(v).not.to.be.undefined
351 }) 314 })
352 315
353 it('Should display its comments on my video', async function () { 316 it('Should display its comments on my video', async function () {
354 for (const server of servers) { 317 for (const server of servers) {
355 const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt') 318 const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
356 const threads: VideoComment[] = resThreads.body.data
357 319
358 // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment 320 // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment
359 if (server.serverNumber === 3) { 321 if (server.serverNumber === 3) {
360 expect(threads).to.have.lengthOf(1) 322 expect(data).to.have.lengthOf(1)
361 continue 323 continue
362 } 324 }
363 325
364 expect(threads).to.have.lengthOf(2) 326 expect(data).to.have.lengthOf(2)
365 expect(threads[0].text).to.equal('uploader') 327 expect(data[0].text).to.equal('uploader')
366 expect(threads[1].text).to.equal('comment user 2') 328 expect(data[1].text).to.equal('comment user 2')
367 329
368 const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id) 330 const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
369
370 const tree: VideoCommentThreadTree = resReplies.body
371 expect(tree.children).to.have.lengthOf(1) 331 expect(tree.children).to.have.lengthOf(1)
372 expect(tree.children[0].comment.text).to.equal('reply by user 2') 332 expect(tree.children[0].comment.text).to.equal('reply by user 2')
373 expect(tree.children[0].children).to.have.lengthOf(1) 333 expect(tree.children[0].children).to.have.lengthOf(1)
@@ -376,11 +336,11 @@ describe('Test blocklist', function () {
376 }) 336 })
377 337
378 it('Should unblock the local account', async function () { 338 it('Should unblock the local account', async function () {
379 await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') 339 await command.removeFromMyBlocklist({ account: 'user1' })
380 }) 340 })
381 341
382 it('Should display its comments', function () { 342 it('Should display its comments', function () {
383 return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) 343 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
384 }) 344 })
385 345
386 it('Should have a notification from a non blocked account', async function () { 346 it('Should have a notification from a non blocked account', async function () {
@@ -404,46 +364,45 @@ describe('Test blocklist', function () {
404 }) 364 })
405 365
406 describe('When managing server blocklist', function () { 366 describe('When managing server blocklist', function () {
367
407 it('Should list all videos', function () { 368 it('Should list all videos', function () {
408 return checkAllVideos(servers[0].url, servers[0].accessToken) 369 return checkAllVideos(servers[0], servers[0].accessToken)
409 }) 370 })
410 371
411 it('Should list the comments', function () { 372 it('Should list the comments', function () {
412 return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) 373 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
413 }) 374 })
414 375
415 it('Should block a remote server', async function () { 376 it('Should block a remote server', async function () {
416 await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) 377 await command.addToMyBlocklist({ server: 'localhost:' + servers[1].port })
417 }) 378 })
418 379
419 it('Should hide its videos', async function () { 380 it('Should hide its videos', async function () {
420 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) 381 const { data } = await servers[0].videos.listWithToken()
421 382
422 const videos: Video[] = res.body.data 383 expect(data).to.have.lengthOf(3)
423 expect(videos).to.have.lengthOf(3)
424 384
425 const v1 = videos.find(v => v.name === 'video user 2') 385 const v1 = data.find(v => v.name === 'video user 2')
426 const v2 = videos.find(v => v.name === 'video server 2') 386 const v2 = data.find(v => v.name === 'video server 2')
427 387
428 expect(v1).to.be.undefined 388 expect(v1).to.be.undefined
429 expect(v2).to.be.undefined 389 expect(v2).to.be.undefined
430 }) 390 })
431 391
432 it('Should list all the videos with another user', async function () { 392 it('Should list all the videos with another user', async function () {
433 return checkAllVideos(servers[0].url, userToken1) 393 return checkAllVideos(servers[0], userToken1)
434 }) 394 })
435 395
436 it('Should hide its comments', async function () { 396 it('Should hide its comments', async function () {
437 this.timeout(10000) 397 this.timeout(10000)
438 398
439 const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2') 399 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
440 const threadId = resThreads.body.comment.id
441 400
442 await waitJobs(servers) 401 await waitJobs(servers)
443 402
444 await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) 403 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
445 404
446 await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId) 405 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
447 }) 406 })
448 407
449 it('Should not have notifications from blocked server', async function () { 408 it('Should not have notifications from blocked server', async function () {
@@ -466,27 +425,25 @@ describe('Test blocklist', function () {
466 }) 425 })
467 426
468 it('Should list blocked servers', async function () { 427 it('Should list blocked servers', async function () {
469 const res = await getServerBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') 428 const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
470 const blocks: ServerBlock[] = res.body.data 429 expect(body.total).to.equal(1)
471
472 expect(res.body.total).to.equal(1)
473 430
474 const block = blocks[0] 431 const block = body.data[0]
475 expect(block.byAccount.displayName).to.equal('root') 432 expect(block.byAccount.displayName).to.equal('root')
476 expect(block.byAccount.name).to.equal('root') 433 expect(block.byAccount.name).to.equal('root')
477 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) 434 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
478 }) 435 })
479 436
480 it('Should unblock the remote server', async function () { 437 it('Should unblock the remote server', async function () {
481 await removeServerFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) 438 await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port })
482 }) 439 })
483 440
484 it('Should display its videos', function () { 441 it('Should display its videos', function () {
485 return checkAllVideos(servers[0].url, servers[0].accessToken) 442 return checkAllVideos(servers[0], servers[0].accessToken)
486 }) 443 })
487 444
488 it('Should display its comments', function () { 445 it('Should display its comments', function () {
489 return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) 446 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
490 }) 447 })
491 448
492 it('Should have notification from unblocked server', async function () { 449 it('Should have notification from unblocked server', async function () {
@@ -515,54 +472,50 @@ describe('Test blocklist', function () {
515 describe('When managing account blocklist', function () { 472 describe('When managing account blocklist', function () {
516 it('Should list all videos', async function () { 473 it('Should list all videos', async function () {
517 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 474 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
518 await checkAllVideos(servers[0].url, token) 475 await checkAllVideos(servers[0], token)
519 } 476 }
520 }) 477 })
521 478
522 it('Should list the comments', async function () { 479 it('Should list the comments', async function () {
523 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 480 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
524 await checkAllComments(servers[0].url, token, videoUUID1) 481 await checkAllComments(servers[0], token, videoUUID1)
525 } 482 }
526 }) 483 })
527 484
528 it('Should block a remote account', async function () { 485 it('Should block a remote account', async function () {
529 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) 486 await command.addToServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
530 }) 487 })
531 488
532 it('Should hide its videos', async function () { 489 it('Should hide its videos', async function () {
533 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 490 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
534 const res = await getVideosListWithToken(servers[0].url, token) 491 const { data } = await servers[0].videos.listWithToken({ token })
535 492
536 const videos: Video[] = res.body.data 493 expect(data).to.have.lengthOf(4)
537 expect(videos).to.have.lengthOf(4)
538 494
539 const v = videos.find(v => v.name === 'video user 2') 495 const v = data.find(v => v.name === 'video user 2')
540 expect(v).to.be.undefined 496 expect(v).to.be.undefined
541 } 497 }
542 }) 498 })
543 499
544 it('Should block a local account', async function () { 500 it('Should block a local account', async function () {
545 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') 501 await command.addToServerBlocklist({ account: 'user1' })
546 }) 502 })
547 503
548 it('Should hide its videos', async function () { 504 it('Should hide its videos', async function () {
549 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 505 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
550 const res = await getVideosListWithToken(servers[0].url, token) 506 const { data } = await servers[0].videos.listWithToken({ token })
551 507
552 const videos: Video[] = res.body.data 508 expect(data).to.have.lengthOf(3)
553 expect(videos).to.have.lengthOf(3)
554 509
555 const v = videos.find(v => v.name === 'video user 1') 510 const v = data.find(v => v.name === 'video user 1')
556 expect(v).to.be.undefined 511 expect(v).to.be.undefined
557 } 512 }
558 }) 513 })
559 514
560 it('Should hide its comments', async function () { 515 it('Should hide its comments', async function () {
561 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 516 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
562 const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 20, '-createdAt', token) 517 const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token })
563 518 const threads = data.filter(t => t.isDeleted === false)
564 let threads: VideoComment[] = resThreads.body.data
565 threads = threads.filter(t => t.isDeleted === false)
566 519
567 expect(threads).to.have.lengthOf(1) 520 expect(threads).to.have.lengthOf(1)
568 expect(threads[0].totalReplies).to.equal(1) 521 expect(threads[0].totalReplies).to.equal(1)
@@ -571,9 +524,7 @@ describe('Test blocklist', function () {
571 expect(t).to.be.undefined 524 expect(t).to.be.undefined
572 525
573 for (const thread of threads) { 526 for (const thread of threads) {
574 const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, token) 527 const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token })
575
576 const tree: VideoCommentThreadTree = res.body
577 expect(tree.children).to.have.lengthOf(0) 528 expect(tree.children).to.have.lengthOf(0)
578 } 529 }
579 } 530 }
@@ -600,12 +551,10 @@ describe('Test blocklist', function () {
600 551
601 it('Should list blocked accounts', async function () { 552 it('Should list blocked accounts', async function () {
602 { 553 {
603 const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') 554 const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
604 const blocks: AccountBlock[] = res.body.data 555 expect(body.total).to.equal(2)
605
606 expect(res.body.total).to.equal(2)
607 556
608 const block = blocks[0] 557 const block = body.data[0]
609 expect(block.byAccount.displayName).to.equal('peertube') 558 expect(block.byAccount.displayName).to.equal('peertube')
610 expect(block.byAccount.name).to.equal('peertube') 559 expect(block.byAccount.name).to.equal('peertube')
611 expect(block.blockedAccount.displayName).to.equal('user2') 560 expect(block.blockedAccount.displayName).to.equal('user2')
@@ -614,12 +563,10 @@ describe('Test blocklist', function () {
614 } 563 }
615 564
616 { 565 {
617 const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt') 566 const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
618 const blocks: AccountBlock[] = res.body.data 567 expect(body.total).to.equal(2)
619 568
620 expect(res.body.total).to.equal(2) 569 const block = body.data[0]
621
622 const block = blocks[0]
623 expect(block.byAccount.displayName).to.equal('peertube') 570 expect(block.byAccount.displayName).to.equal('peertube')
624 expect(block.byAccount.name).to.equal('peertube') 571 expect(block.byAccount.name).to.equal('peertube')
625 expect(block.blockedAccount.displayName).to.equal('user1') 572 expect(block.blockedAccount.displayName).to.equal('user1')
@@ -629,28 +576,26 @@ describe('Test blocklist', function () {
629 }) 576 })
630 577
631 it('Should unblock the remote account', async function () { 578 it('Should unblock the remote account', async function () {
632 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) 579 await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
633 }) 580 })
634 581
635 it('Should display its videos', async function () { 582 it('Should display its videos', async function () {
636 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 583 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
637 const res = await getVideosListWithToken(servers[0].url, token) 584 const { data } = await servers[0].videos.listWithToken({ token })
638 585 expect(data).to.have.lengthOf(4)
639 const videos: Video[] = res.body.data
640 expect(videos).to.have.lengthOf(4)
641 586
642 const v = videos.find(v => v.name === 'video user 2') 587 const v = data.find(v => v.name === 'video user 2')
643 expect(v).not.to.be.undefined 588 expect(v).not.to.be.undefined
644 } 589 }
645 }) 590 })
646 591
647 it('Should unblock the local account', async function () { 592 it('Should unblock the local account', async function () {
648 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') 593 await command.removeFromServerBlocklist({ account: 'user1' })
649 }) 594 })
650 595
651 it('Should display its comments', async function () { 596 it('Should display its comments', async function () {
652 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 597 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
653 await checkAllComments(servers[0].url, token, videoUUID1) 598 await checkAllComments(servers[0], token, videoUUID1)
654 } 599 }
655 }) 600 })
656 601
@@ -677,31 +622,33 @@ describe('Test blocklist', function () {
677 describe('When managing server blocklist', function () { 622 describe('When managing server blocklist', function () {
678 it('Should list all videos', async function () { 623 it('Should list all videos', async function () {
679 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 624 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
680 await checkAllVideos(servers[0].url, token) 625 await checkAllVideos(servers[0], token)
681 } 626 }
682 }) 627 })
683 628
684 it('Should list the comments', async function () { 629 it('Should list the comments', async function () {
685 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 630 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
686 await checkAllComments(servers[0].url, token, videoUUID1) 631 await checkAllComments(servers[0], token, videoUUID1)
687 } 632 }
688 }) 633 })
689 634
690 it('Should block a remote server', async function () { 635 it('Should block a remote server', async function () {
691 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) 636 await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port })
692 }) 637 })
693 638
694 it('Should hide its videos', async function () { 639 it('Should hide its videos', async function () {
695 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 640 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
696 const res1 = await getVideosList(servers[0].url) 641 const requests = [
697 const res2 = await getVideosListWithToken(servers[0].url, token) 642 servers[0].videos.list(),
643 servers[0].videos.listWithToken({ token })
644 ]
698 645
699 for (const res of [ res1, res2 ]) { 646 for (const req of requests) {
700 const videos: Video[] = res.body.data 647 const { data } = await req
701 expect(videos).to.have.lengthOf(3) 648 expect(data).to.have.lengthOf(3)
702 649
703 const v1 = videos.find(v => v.name === 'video user 2') 650 const v1 = data.find(v => v.name === 'video user 2')
704 const v2 = videos.find(v => v.name === 'video server 2') 651 const v2 = data.find(v => v.name === 'video server 2')
705 652
706 expect(v1).to.be.undefined 653 expect(v1).to.be.undefined
707 expect(v2).to.be.undefined 654 expect(v2).to.be.undefined
@@ -712,14 +659,13 @@ describe('Test blocklist', function () {
712 it('Should hide its comments', async function () { 659 it('Should hide its comments', async function () {
713 this.timeout(10000) 660 this.timeout(10000)
714 661
715 const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2') 662 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
716 const threadId = resThreads.body.comment.id
717 663
718 await waitJobs(servers) 664 await waitJobs(servers)
719 665
720 await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) 666 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
721 667
722 await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId) 668 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
723 }) 669 })
724 670
725 it('Should not have notification from blocked instances by instance', async function () { 671 it('Should not have notification from blocked instances by instance', async function () {
@@ -742,48 +688,44 @@ describe('Test blocklist', function () {
742 688
743 { 689 {
744 const now = new Date() 690 const now = new Date()
745 await unfollow(servers[1].url, servers[1].accessToken, servers[0]) 691 await servers[1].follows.unfollow({ target: servers[0] })
746 await waitJobs(servers) 692 await waitJobs(servers)
747 await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken) 693 await servers[1].follows.follow({ hosts: [ servers[0].host ] })
748 694
749 await waitJobs(servers) 695 await waitJobs(servers)
750 696
751 const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30) 697 const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
752 const commentNotifications = (res.body.data as UserNotification[]) 698 const commentNotifications = data.filter(n => {
753 .filter(n => { 699 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
754 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && 700 })
755 n.createdAt >= now.toISOString()
756 })
757 701
758 expect(commentNotifications).to.have.lengthOf(0) 702 expect(commentNotifications).to.have.lengthOf(0)
759 } 703 }
760 }) 704 })
761 705
762 it('Should list blocked servers', async function () { 706 it('Should list blocked servers', async function () {
763 const res = await getServerBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') 707 const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
764 const blocks: ServerBlock[] = res.body.data 708 expect(body.total).to.equal(1)
765
766 expect(res.body.total).to.equal(1)
767 709
768 const block = blocks[0] 710 const block = body.data[0]
769 expect(block.byAccount.displayName).to.equal('peertube') 711 expect(block.byAccount.displayName).to.equal('peertube')
770 expect(block.byAccount.name).to.equal('peertube') 712 expect(block.byAccount.name).to.equal('peertube')
771 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) 713 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
772 }) 714 })
773 715
774 it('Should unblock the remote server', async function () { 716 it('Should unblock the remote server', async function () {
775 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) 717 await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port })
776 }) 718 })
777 719
778 it('Should list all videos', async function () { 720 it('Should list all videos', async function () {
779 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 721 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
780 await checkAllVideos(servers[0].url, token) 722 await checkAllVideos(servers[0], token)
781 } 723 }
782 }) 724 })
783 725
784 it('Should list the comments', async function () { 726 it('Should list the comments', async function () {
785 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 727 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
786 await checkAllComments(servers[0].url, token, videoUUID1) 728 await checkAllComments(servers[0], token, videoUUID1)
787 } 729 }
788 }) 730 })
789 731
@@ -807,18 +749,16 @@ describe('Test blocklist', function () {
807 749
808 { 750 {
809 const now = new Date() 751 const now = new Date()
810 await unfollow(servers[1].url, servers[1].accessToken, servers[0]) 752 await servers[1].follows.unfollow({ target: servers[0] })
811 await waitJobs(servers) 753 await waitJobs(servers)
812 await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken) 754 await servers[1].follows.follow({ hosts: [ servers[0].host ] })
813 755
814 await waitJobs(servers) 756 await waitJobs(servers)
815 757
816 const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30) 758 const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
817 const commentNotifications = (res.body.data as UserNotification[]) 759 const commentNotifications = data.filter(n => {
818 .filter(n => { 760 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
819 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && 761 })
820 n.createdAt >= now.toISOString()
821 })
822 762
823 expect(commentNotifications).to.have.lengthOf(1) 763 expect(commentNotifications).to.have.lengthOf(1)
824 } 764 }