aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/moderation
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/moderation')
-rw-r--r--server/tests/api/moderation/abuses.ts756
-rw-r--r--server/tests/api/moderation/blocklist-notification.ts121
-rw-r--r--server/tests/api/moderation/blocklist.ts446
-rw-r--r--server/tests/api/moderation/video-blacklist.ts304
4 files changed, 715 insertions, 912 deletions
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts
index fb765e7e3..8d6360eb3 100644
--- a/server/tests/api/moderation/abuses.ts
+++ b/server/tests/api/moderation/abuses.ts
@@ -3,70 +3,37 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 AbuseFilter, 6 AbusesCommand,
7 AbuseMessage,
8 AbusePredefinedReasonsString,
9 AbuseState,
10 Account,
11 AdminAbuse,
12 UserAbuse,
13 VideoComment
14} from '@shared/models'
15import {
16 addAbuseMessage,
17 addVideoCommentThread,
18 cleanupTests, 7 cleanupTests,
19 createUser, 8 createMultipleServers,
20 deleteAbuse, 9 doubleFollow,
21 deleteAbuseMessage, 10 PeerTubeServer,
22 deleteVideoComment,
23 flushAndRunMultipleServers,
24 generateUserAccessToken,
25 getAccount,
26 getAdminAbusesList,
27 getUserAbusesList,
28 getVideoCommentThreads,
29 getVideoIdFromUUID,
30 getVideosList,
31 immutableAssign,
32 listAbuseMessages,
33 removeUser,
34 removeVideo,
35 reportAbuse,
36 ServerInfo,
37 setAccessTokensToServers, 11 setAccessTokensToServers,
38 updateAbuse, 12 waitJobs
39 uploadVideo, 13} from '@shared/extra-utils'
40 uploadVideoAndGetId, 14import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
41 userLogin
42} from '../../../../shared/extra-utils/index'
43import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
44import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
45import {
46 addAccountToServerBlocklist,
47 addServerToServerBlocklist,
48 removeAccountFromServerBlocklist,
49 removeServerFromServerBlocklist
50} from '../../../../shared/extra-utils/users/blocklist'
51 15
52const expect = chai.expect 16const expect = chai.expect
53 17
54describe('Test abuses', function () { 18describe('Test abuses', function () {
55 let servers: ServerInfo[] = [] 19 let servers: PeerTubeServer[] = []
56 let abuseServer1: AdminAbuse 20 let abuseServer1: AdminAbuse
57 let abuseServer2: AdminAbuse 21 let abuseServer2: AdminAbuse
22 let commands: AbusesCommand[]
58 23
59 before(async function () { 24 before(async function () {
60 this.timeout(50000) 25 this.timeout(50000)
61 26
62 // Run servers 27 // Run servers
63 servers = await flushAndRunMultipleServers(2) 28 servers = await createMultipleServers(2)
64 29
65 // Get the access tokens 30 // Get the access tokens
66 await setAccessTokensToServers(servers) 31 await setAccessTokensToServers(servers)
67 32
68 // Server 1 and server 2 follow each other 33 // Server 1 and server 2 follow each other
69 await doubleFollow(servers[0], servers[1]) 34 await doubleFollow(servers[0], servers[1])
35
36 commands = servers.map(s => s.abuses)
70 }) 37 })
71 38
72 describe('Video abuses', function () { 39 describe('Video abuses', function () {
@@ -75,179 +42,189 @@ describe('Test abuses', function () {
75 this.timeout(50000) 42 this.timeout(50000)
76 43
77 // Upload some videos on each servers 44 // Upload some videos on each servers
78 const video1Attributes = { 45 {
79 name: 'my super name for server 1', 46 const attributes = {
80 description: 'my super description for server 1' 47 name: 'my super name for server 1',
48 description: 'my super description for server 1'
49 }
50 await servers[0].videos.upload({ attributes })
81 } 51 }
82 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
83 52
84 const video2Attributes = { 53 {
85 name: 'my super name for server 2', 54 const attributes = {
86 description: 'my super description for server 2' 55 name: 'my super name for server 2',
56 description: 'my super description for server 2'
57 }
58 await servers[1].videos.upload({ attributes })
87 } 59 }
88 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
89 60
90 // Wait videos propagation, server 2 has transcoding enabled 61 // Wait videos propagation, server 2 has transcoding enabled
91 await waitJobs(servers) 62 await waitJobs(servers)
92 63
93 const res = await getVideosList(servers[0].url) 64 const { data } = await servers[0].videos.list()
94 const videos = res.body.data 65 expect(data.length).to.equal(2)
95 66
96 expect(videos.length).to.equal(2) 67 servers[0].store.video = data.find(video => video.name === 'my super name for server 1')
97 68 servers[1].store.video = data.find(video => video.name === 'my super name for server 2')
98 servers[0].video = videos.find(video => video.name === 'my super name for server 1')
99 servers[1].video = videos.find(video => video.name === 'my super name for server 2')
100 }) 69 })
101 70
102 it('Should not have abuses', async function () { 71 it('Should not have abuses', async function () {
103 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 72 const body = await commands[0].getAdminList()
104 73
105 expect(res.body.total).to.equal(0) 74 expect(body.total).to.equal(0)
106 expect(res.body.data).to.be.an('array') 75 expect(body.data).to.be.an('array')
107 expect(res.body.data.length).to.equal(0) 76 expect(body.data.length).to.equal(0)
108 }) 77 })
109 78
110 it('Should report abuse on a local video', async function () { 79 it('Should report abuse on a local video', async function () {
111 this.timeout(15000) 80 this.timeout(15000)
112 81
113 const reason = 'my super bad reason' 82 const reason = 'my super bad reason'
114 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: servers[0].video.id, reason }) 83 await commands[0].report({ videoId: servers[0].store.video.id, reason })
115 84
116 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 85 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
117 await waitJobs(servers) 86 await waitJobs(servers)
118 }) 87 })
119 88
120 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { 89 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
121 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 90 {
91 const body = await commands[0].getAdminList()
122 92
123 expect(res1.body.total).to.equal(1) 93 expect(body.total).to.equal(1)
124 expect(res1.body.data).to.be.an('array') 94 expect(body.data).to.be.an('array')
125 expect(res1.body.data.length).to.equal(1) 95 expect(body.data.length).to.equal(1)
126 96
127 const abuse: AdminAbuse = res1.body.data[0] 97 const abuse = body.data[0]
128 expect(abuse.reason).to.equal('my super bad reason') 98 expect(abuse.reason).to.equal('my super bad reason')
129 99
130 expect(abuse.reporterAccount.name).to.equal('root') 100 expect(abuse.reporterAccount.name).to.equal('root')
131 expect(abuse.reporterAccount.host).to.equal(servers[0].host) 101 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
132 102
133 expect(abuse.video.id).to.equal(servers[0].video.id) 103 expect(abuse.video.id).to.equal(servers[0].store.video.id)
134 expect(abuse.video.channel).to.exist 104 expect(abuse.video.channel).to.exist
135 105
136 expect(abuse.comment).to.be.null 106 expect(abuse.comment).to.be.null
137 107
138 expect(abuse.flaggedAccount.name).to.equal('root') 108 expect(abuse.flaggedAccount.name).to.equal('root')
139 expect(abuse.flaggedAccount.host).to.equal(servers[0].host) 109 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
140 110
141 expect(abuse.video.countReports).to.equal(1) 111 expect(abuse.video.countReports).to.equal(1)
142 expect(abuse.video.nthReport).to.equal(1) 112 expect(abuse.video.nthReport).to.equal(1)
143 113
144 expect(abuse.countReportsForReporter).to.equal(1) 114 expect(abuse.countReportsForReporter).to.equal(1)
145 expect(abuse.countReportsForReportee).to.equal(1) 115 expect(abuse.countReportsForReportee).to.equal(1)
116 }
146 117
147 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 118 {
148 expect(res2.body.total).to.equal(0) 119 const body = await commands[1].getAdminList()
149 expect(res2.body.data).to.be.an('array') 120 expect(body.total).to.equal(0)
150 expect(res2.body.data.length).to.equal(0) 121 expect(body.data).to.be.an('array')
122 expect(body.data.length).to.equal(0)
123 }
151 }) 124 })
152 125
153 it('Should report abuse on a remote video', async function () { 126 it('Should report abuse on a remote video', async function () {
154 this.timeout(10000) 127 this.timeout(10000)
155 128
156 const reason = 'my super bad reason 2' 129 const reason = 'my super bad reason 2'
157 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) 130 const videoId = await servers[0].videos.getId({ uuid: servers[1].store.video.uuid })
158 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId, reason }) 131 await commands[0].report({ videoId, reason })
159 132
160 // We wait requests propagation 133 // We wait requests propagation
161 await waitJobs(servers) 134 await waitJobs(servers)
162 }) 135 })
163 136
164 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { 137 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
165 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 138 {
139 const body = await commands[0].getAdminList()
166 140
167 expect(res1.body.total).to.equal(2) 141 expect(body.total).to.equal(2)
168 expect(res1.body.data.length).to.equal(2) 142 expect(body.data.length).to.equal(2)
169 143
170 const abuse1: AdminAbuse = res1.body.data[0] 144 const abuse1 = body.data[0]
171 expect(abuse1.reason).to.equal('my super bad reason') 145 expect(abuse1.reason).to.equal('my super bad reason')
172 expect(abuse1.reporterAccount.name).to.equal('root') 146 expect(abuse1.reporterAccount.name).to.equal('root')
173 expect(abuse1.reporterAccount.host).to.equal(servers[0].host) 147 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
174 148
175 expect(abuse1.video.id).to.equal(servers[0].video.id) 149 expect(abuse1.video.id).to.equal(servers[0].store.video.id)
176 expect(abuse1.video.countReports).to.equal(1) 150 expect(abuse1.video.countReports).to.equal(1)
177 expect(abuse1.video.nthReport).to.equal(1) 151 expect(abuse1.video.nthReport).to.equal(1)
178 152
179 expect(abuse1.comment).to.be.null 153 expect(abuse1.comment).to.be.null
180 154
181 expect(abuse1.flaggedAccount.name).to.equal('root') 155 expect(abuse1.flaggedAccount.name).to.equal('root')
182 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host) 156 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
183 157
184 expect(abuse1.state.id).to.equal(AbuseState.PENDING) 158 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
185 expect(abuse1.state.label).to.equal('Pending') 159 expect(abuse1.state.label).to.equal('Pending')
186 expect(abuse1.moderationComment).to.be.null 160 expect(abuse1.moderationComment).to.be.null
187 161
188 const abuse2: AdminAbuse = res1.body.data[1] 162 const abuse2 = body.data[1]
189 expect(abuse2.reason).to.equal('my super bad reason 2') 163 expect(abuse2.reason).to.equal('my super bad reason 2')
190 164
191 expect(abuse2.reporterAccount.name).to.equal('root') 165 expect(abuse2.reporterAccount.name).to.equal('root')
192 expect(abuse2.reporterAccount.host).to.equal(servers[0].host) 166 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
193 167
194 expect(abuse2.video.id).to.equal(servers[1].video.id) 168 expect(abuse2.video.id).to.equal(servers[1].store.video.id)
195 169
196 expect(abuse2.comment).to.be.null 170 expect(abuse2.comment).to.be.null
197 171
198 expect(abuse2.flaggedAccount.name).to.equal('root') 172 expect(abuse2.flaggedAccount.name).to.equal('root')
199 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) 173 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
200 174
201 expect(abuse2.state.id).to.equal(AbuseState.PENDING) 175 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
202 expect(abuse2.state.label).to.equal('Pending') 176 expect(abuse2.state.label).to.equal('Pending')
203 expect(abuse2.moderationComment).to.be.null 177 expect(abuse2.moderationComment).to.be.null
178 }
204 179
205 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 180 {
206 expect(res2.body.total).to.equal(1) 181 const body = await commands[1].getAdminList()
207 expect(res2.body.data.length).to.equal(1) 182 expect(body.total).to.equal(1)
183 expect(body.data.length).to.equal(1)
208 184
209 abuseServer2 = res2.body.data[0] 185 abuseServer2 = body.data[0]
210 expect(abuseServer2.reason).to.equal('my super bad reason 2') 186 expect(abuseServer2.reason).to.equal('my super bad reason 2')
211 expect(abuseServer2.reporterAccount.name).to.equal('root') 187 expect(abuseServer2.reporterAccount.name).to.equal('root')
212 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) 188 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
213 189
214 expect(abuse2.flaggedAccount.name).to.equal('root') 190 expect(abuseServer2.flaggedAccount.name).to.equal('root')
215 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) 191 expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host)
216 192
217 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) 193 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
218 expect(abuseServer2.state.label).to.equal('Pending') 194 expect(abuseServer2.state.label).to.equal('Pending')
219 expect(abuseServer2.moderationComment).to.be.null 195 expect(abuseServer2.moderationComment).to.be.null
196 }
220 }) 197 })
221 198
222 it('Should hide video abuses from blocked accounts', async function () { 199 it('Should hide video abuses from blocked accounts', async function () {
223 this.timeout(10000) 200 this.timeout(10000)
224 201
225 { 202 {
226 const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid) 203 const videoId = await servers[1].videos.getId({ uuid: servers[0].store.video.uuid })
227 await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'will mute this' }) 204 await commands[1].report({ videoId, reason: 'will mute this' })
228 await waitJobs(servers) 205 await waitJobs(servers)
229 206
230 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 207 const body = await commands[0].getAdminList()
231 expect(res.body.total).to.equal(3) 208 expect(body.total).to.equal(3)
232 } 209 }
233 210
234 const accountToBlock = 'root@' + servers[1].host 211 const accountToBlock = 'root@' + servers[1].host
235 212
236 { 213 {
237 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) 214 await servers[0].blocklist.addToServerBlocklist({ account: accountToBlock })
238 215
239 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 216 const body = await commands[0].getAdminList()
240 expect(res.body.total).to.equal(2) 217 expect(body.total).to.equal(2)
241 218
242 const abuse = res.body.data.find(a => a.reason === 'will mute this') 219 const abuse = body.data.find(a => a.reason === 'will mute this')
243 expect(abuse).to.be.undefined 220 expect(abuse).to.be.undefined
244 } 221 }
245 222
246 { 223 {
247 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) 224 await servers[0].blocklist.removeFromServerBlocklist({ account: accountToBlock })
248 225
249 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 226 const body = await commands[0].getAdminList()
250 expect(res.body.total).to.equal(3) 227 expect(body.total).to.equal(3)
251 } 228 }
252 }) 229 })
253 230
@@ -255,35 +232,35 @@ describe('Test abuses', function () {
255 const serverToBlock = servers[1].host 232 const serverToBlock = servers[1].host
256 233
257 { 234 {
258 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) 235 await servers[0].blocklist.addToServerBlocklist({ server: serverToBlock })
259 236
260 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 237 const body = await commands[0].getAdminList()
261 expect(res.body.total).to.equal(2) 238 expect(body.total).to.equal(2)
262 239
263 const abuse = res.body.data.find(a => a.reason === 'will mute this') 240 const abuse = body.data.find(a => a.reason === 'will mute this')
264 expect(abuse).to.be.undefined 241 expect(abuse).to.be.undefined
265 } 242 }
266 243
267 { 244 {
268 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) 245 await servers[0].blocklist.removeFromServerBlocklist({ server: serverToBlock })
269 246
270 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 247 const body = await commands[0].getAdminList()
271 expect(res.body.total).to.equal(3) 248 expect(body.total).to.equal(3)
272 } 249 }
273 }) 250 })
274 251
275 it('Should keep the video abuse when deleting the video', async function () { 252 it('Should keep the video abuse when deleting the video', async function () {
276 this.timeout(10000) 253 this.timeout(10000)
277 254
278 await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid) 255 await servers[1].videos.remove({ id: abuseServer2.video.uuid })
279 256
280 await waitJobs(servers) 257 await waitJobs(servers)
281 258
282 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 259 const body = await commands[1].getAdminList()
283 expect(res.body.total).to.equal(2, "wrong number of videos returned") 260 expect(body.total).to.equal(2, "wrong number of videos returned")
284 expect(res.body.data).to.have.lengthOf(2, "wrong number of videos returned") 261 expect(body.data).to.have.lengthOf(2, "wrong number of videos returned")
285 262
286 const abuse: AdminAbuse = res.body.data[0] 263 const abuse = body.data[0]
287 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video") 264 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video")
288 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id") 265 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
289 expect(abuse.video.channel).to.exist 266 expect(abuse.video.channel).to.exist
@@ -295,39 +272,36 @@ describe('Test abuses', function () {
295 272
296 // register a second user to have two reporters/reportees 273 // register a second user to have two reporters/reportees
297 const user = { username: 'user2', password: 'password' } 274 const user = { username: 'user2', password: 'password' }
298 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user }) 275 await servers[0].users.create({ ...user })
299 const userAccessToken = await userLogin(servers[0], user) 276 const userAccessToken = await servers[0].login.getAccessToken(user)
300 277
301 // upload a third video via this user 278 // upload a third video via this user
302 const video3Attributes = { 279 const attributes = {
303 name: 'my second super name for server 1', 280 name: 'my second super name for server 1',
304 description: 'my second super description for server 1' 281 description: 'my second super description for server 1'
305 } 282 }
306 await uploadVideo(servers[0].url, userAccessToken, video3Attributes) 283 const { id } = await servers[0].videos.upload({ token: userAccessToken, attributes })
307 284 const video3Id = id
308 const res1 = await getVideosList(servers[0].url)
309 const videos = res1.body.data
310 const video3 = videos.find(video => video.name === 'my second super name for server 1')
311 285
312 // resume with the test 286 // resume with the test
313 const reason3 = 'my super bad reason 3' 287 const reason3 = 'my super bad reason 3'
314 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video3.id, reason: reason3 }) 288 await commands[0].report({ videoId: video3Id, reason: reason3 })
315 289
316 const reason4 = 'my super bad reason 4' 290 const reason4 = 'my super bad reason 4'
317 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: reason4 }) 291 await commands[0].report({ token: userAccessToken, videoId: servers[0].store.video.id, reason: reason4 })
318 292
319 { 293 {
320 const res2 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 294 const body = await commands[0].getAdminList()
321 const abuses = res2.body.data as AdminAbuse[] 295 const abuses = body.data
322 296
323 const abuseVideo3 = res2.body.data.find(a => a.video.id === video3.id) 297 const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
324 expect(abuseVideo3).to.not.be.undefined 298 expect(abuseVideo3).to.not.be.undefined
325 expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3") 299 expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3")
326 expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3") 300 expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3")
327 expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse") 301 expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse")
328 expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse") 302 expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse")
329 303
330 const abuseServer1 = abuses.find(a => a.video.id === servers[0].video.id) 304 const abuseServer1 = abuses.find(a => a.video.id === servers[0].store.video.id)
331 expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse") 305 expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse")
332 } 306 }
333 }) 307 })
@@ -337,20 +311,18 @@ describe('Test abuses', function () {
337 311
338 const reason5 = 'my super bad reason 5' 312 const reason5 = 'my super bad reason 5'
339 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ] 313 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
340 const createdAbuse = (await reportAbuse({ 314 const createRes = await commands[0].report({
341 url: servers[0].url, 315 videoId: servers[0].store.video.id,
342 token: servers[0].accessToken,
343 videoId: servers[0].video.id,
344 reason: reason5, 316 reason: reason5,
345 predefinedReasons: predefinedReasons5, 317 predefinedReasons: predefinedReasons5,
346 startAt: 1, 318 startAt: 1,
347 endAt: 5 319 endAt: 5
348 })).body.abuse 320 })
349 321
350 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 322 const body = await commands[0].getAdminList()
351 323
352 { 324 {
353 const abuse = (res.body.data as AdminAbuse[]).find(a => a.id === createdAbuse.id) 325 const abuse = body.data.find(a => a.id === createRes.abuse.id)
354 expect(abuse.reason).to.equals(reason5) 326 expect(abuse.reason).to.equals(reason5)
355 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported") 327 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported")
356 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported") 328 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
@@ -361,37 +333,30 @@ describe('Test abuses', function () {
361 it('Should delete the video abuse', async function () { 333 it('Should delete the video abuse', async function () {
362 this.timeout(10000) 334 this.timeout(10000)
363 335
364 await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) 336 await commands[1].delete({ abuseId: abuseServer2.id })
365 337
366 await waitJobs(servers) 338 await waitJobs(servers)
367 339
368 { 340 {
369 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 341 const body = await commands[1].getAdminList()
370 expect(res.body.total).to.equal(1) 342 expect(body.total).to.equal(1)
371 expect(res.body.data.length).to.equal(1) 343 expect(body.data.length).to.equal(1)
372 expect(res.body.data[0].id).to.not.equal(abuseServer2.id) 344 expect(body.data[0].id).to.not.equal(abuseServer2.id)
373 } 345 }
374 346
375 { 347 {
376 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 348 const body = await commands[0].getAdminList()
377 expect(res.body.total).to.equal(6) 349 expect(body.total).to.equal(6)
378 } 350 }
379 }) 351 })
380 352
381 it('Should list and filter video abuses', async function () { 353 it('Should list and filter video abuses', async function () {
382 this.timeout(10000) 354 this.timeout(10000)
383 355
384 async function list (query: Omit<Parameters<typeof getAdminAbusesList>[0], 'url' | 'token'>) { 356 async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) {
385 const options = { 357 const body = await commands[0].getAdminList(query)
386 url: servers[0].url,
387 token: servers[0].accessToken
388 }
389
390 Object.assign(options, query)
391 358
392 const res = await getAdminAbusesList(options) 359 return body.data
393
394 return res.body.data as AdminAbuse[]
395 } 360 }
396 361
397 expect(await list({ id: 56 })).to.have.lengthOf(0) 362 expect(await list({ id: 56 })).to.have.lengthOf(0)
@@ -424,24 +389,24 @@ describe('Test abuses', function () {
424 389
425 describe('Comment abuses', function () { 390 describe('Comment abuses', function () {
426 391
427 async function getComment (url: string, videoIdArg: number | string) { 392 async function getComment (server: PeerTubeServer, videoIdArg: number | string) {
428 const videoId = typeof videoIdArg === 'string' 393 const videoId = typeof videoIdArg === 'string'
429 ? await getVideoIdFromUUID(url, videoIdArg) 394 ? await server.videos.getId({ uuid: videoIdArg })
430 : videoIdArg 395 : videoIdArg
431 396
432 const res = await getVideoCommentThreads(url, videoId, 0, 5) 397 const { data } = await server.comments.listThreads({ videoId })
433 398
434 return res.body.data[0] as VideoComment 399 return data[0]
435 } 400 }
436 401
437 before(async function () { 402 before(async function () {
438 this.timeout(50000) 403 this.timeout(50000)
439 404
440 servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' }) 405 servers[0].store.video = await servers[0].videos.quickUpload({ name: 'server 1' })
441 servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' }) 406 servers[1].store.video = await servers[1].videos.quickUpload({ name: 'server 2' })
442 407
443 await addVideoCommentThread(servers[0].url, servers[0].accessToken, servers[0].video.id, 'comment server 1') 408 await servers[0].comments.createThread({ videoId: servers[0].store.video.id, text: 'comment server 1' })
444 await addVideoCommentThread(servers[1].url, servers[1].accessToken, servers[1].video.id, 'comment server 2') 409 await servers[1].comments.createThread({ videoId: servers[1].store.video.id, text: 'comment server 2' })
445 410
446 await waitJobs(servers) 411 await waitJobs(servers)
447 }) 412 })
@@ -449,23 +414,23 @@ describe('Test abuses', function () {
449 it('Should report abuse on a comment', async function () { 414 it('Should report abuse on a comment', async function () {
450 this.timeout(15000) 415 this.timeout(15000)
451 416
452 const comment = await getComment(servers[0].url, servers[0].video.id) 417 const comment = await getComment(servers[0], servers[0].store.video.id)
453 418
454 const reason = 'it is a bad comment' 419 const reason = 'it is a bad comment'
455 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason }) 420 await commands[0].report({ commentId: comment.id, reason })
456 421
457 await waitJobs(servers) 422 await waitJobs(servers)
458 }) 423 })
459 424
460 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () { 425 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
461 { 426 {
462 const comment = await getComment(servers[0].url, servers[0].video.id) 427 const comment = await getComment(servers[0], servers[0].store.video.id)
463 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 428 const body = await commands[0].getAdminList({ filter: 'comment' })
464 429
465 expect(res.body.total).to.equal(1) 430 expect(body.total).to.equal(1)
466 expect(res.body.data).to.have.lengthOf(1) 431 expect(body.data).to.have.lengthOf(1)
467 432
468 const abuse: AdminAbuse = res.body.data[0] 433 const abuse = body.data[0]
469 expect(abuse.reason).to.equal('it is a bad comment') 434 expect(abuse.reason).to.equal('it is a bad comment')
470 435
471 expect(abuse.reporterAccount.name).to.equal('root') 436 expect(abuse.reporterAccount.name).to.equal('root')
@@ -477,98 +442,102 @@ describe('Test abuses', function () {
477 expect(abuse.comment.id).to.equal(comment.id) 442 expect(abuse.comment.id).to.equal(comment.id)
478 expect(abuse.comment.text).to.equal(comment.text) 443 expect(abuse.comment.text).to.equal(comment.text)
479 expect(abuse.comment.video.name).to.equal('server 1') 444 expect(abuse.comment.video.name).to.equal('server 1')
480 expect(abuse.comment.video.id).to.equal(servers[0].video.id) 445 expect(abuse.comment.video.id).to.equal(servers[0].store.video.id)
481 expect(abuse.comment.video.uuid).to.equal(servers[0].video.uuid) 446 expect(abuse.comment.video.uuid).to.equal(servers[0].store.video.uuid)
482 447
483 expect(abuse.countReportsForReporter).to.equal(5) 448 expect(abuse.countReportsForReporter).to.equal(5)
484 expect(abuse.countReportsForReportee).to.equal(5) 449 expect(abuse.countReportsForReportee).to.equal(5)
485 } 450 }
486 451
487 { 452 {
488 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 453 const body = await commands[1].getAdminList({ filter: 'comment' })
489 expect(res.body.total).to.equal(0) 454 expect(body.total).to.equal(0)
490 expect(res.body.data.length).to.equal(0) 455 expect(body.data.length).to.equal(0)
491 } 456 }
492 }) 457 })
493 458
494 it('Should report abuse on a remote comment', async function () { 459 it('Should report abuse on a remote comment', async function () {
495 this.timeout(10000) 460 this.timeout(10000)
496 461
497 const comment = await getComment(servers[0].url, servers[1].video.uuid) 462 const comment = await getComment(servers[0], servers[1].store.video.uuid)
498 463
499 const reason = 'it is a really bad comment' 464 const reason = 'it is a really bad comment'
500 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason }) 465 await commands[0].report({ commentId: comment.id, reason })
501 466
502 await waitJobs(servers) 467 await waitJobs(servers)
503 }) 468 })
504 469
505 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { 470 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
506 const commentServer2 = await getComment(servers[0].url, servers[1].video.id) 471 const commentServer2 = await getComment(servers[0], servers[1].store.video.id)
507 472
508 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 473 {
509 expect(res1.body.total).to.equal(2) 474 const body = await commands[0].getAdminList({ filter: 'comment' })
510 expect(res1.body.data.length).to.equal(2) 475 expect(body.total).to.equal(2)
476 expect(body.data.length).to.equal(2)
511 477
512 const abuse: AdminAbuse = res1.body.data[0] 478 const abuse = body.data[0]
513 expect(abuse.reason).to.equal('it is a bad comment') 479 expect(abuse.reason).to.equal('it is a bad comment')
514 expect(abuse.countReportsForReporter).to.equal(6) 480 expect(abuse.countReportsForReporter).to.equal(6)
515 expect(abuse.countReportsForReportee).to.equal(5) 481 expect(abuse.countReportsForReportee).to.equal(5)
516 482
517 const abuse2: AdminAbuse = res1.body.data[1] 483 const abuse2 = body.data[1]
518 484
519 expect(abuse2.reason).to.equal('it is a really bad comment') 485 expect(abuse2.reason).to.equal('it is a really bad comment')
520 486
521 expect(abuse2.reporterAccount.name).to.equal('root') 487 expect(abuse2.reporterAccount.name).to.equal('root')
522 expect(abuse2.reporterAccount.host).to.equal(servers[0].host) 488 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
523 489
524 expect(abuse2.video).to.be.null 490 expect(abuse2.video).to.be.null
525 491
526 expect(abuse2.comment.deleted).to.be.false 492 expect(abuse2.comment.deleted).to.be.false
527 expect(abuse2.comment.id).to.equal(commentServer2.id) 493 expect(abuse2.comment.id).to.equal(commentServer2.id)
528 expect(abuse2.comment.text).to.equal(commentServer2.text) 494 expect(abuse2.comment.text).to.equal(commentServer2.text)
529 expect(abuse2.comment.video.name).to.equal('server 2') 495 expect(abuse2.comment.video.name).to.equal('server 2')
530 expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid) 496 expect(abuse2.comment.video.uuid).to.equal(servers[1].store.video.uuid)
531 497
532 expect(abuse2.state.id).to.equal(AbuseState.PENDING) 498 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
533 expect(abuse2.state.label).to.equal('Pending') 499 expect(abuse2.state.label).to.equal('Pending')
534 500
535 expect(abuse2.moderationComment).to.be.null 501 expect(abuse2.moderationComment).to.be.null
536 502
537 expect(abuse2.countReportsForReporter).to.equal(6) 503 expect(abuse2.countReportsForReporter).to.equal(6)
538 expect(abuse2.countReportsForReportee).to.equal(2) 504 expect(abuse2.countReportsForReportee).to.equal(2)
505 }
539 506
540 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 507 {
541 expect(res2.body.total).to.equal(1) 508 const body = await commands[1].getAdminList({ filter: 'comment' })
542 expect(res2.body.data.length).to.equal(1) 509 expect(body.total).to.equal(1)
510 expect(body.data.length).to.equal(1)
543 511
544 abuseServer2 = res2.body.data[0] 512 abuseServer2 = body.data[0]
545 expect(abuseServer2.reason).to.equal('it is a really bad comment') 513 expect(abuseServer2.reason).to.equal('it is a really bad comment')
546 expect(abuseServer2.reporterAccount.name).to.equal('root') 514 expect(abuseServer2.reporterAccount.name).to.equal('root')
547 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) 515 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
548 516
549 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) 517 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
550 expect(abuseServer2.state.label).to.equal('Pending') 518 expect(abuseServer2.state.label).to.equal('Pending')
551 519
552 expect(abuseServer2.moderationComment).to.be.null 520 expect(abuseServer2.moderationComment).to.be.null
553 521
554 expect(abuseServer2.countReportsForReporter).to.equal(1) 522 expect(abuseServer2.countReportsForReporter).to.equal(1)
555 expect(abuseServer2.countReportsForReportee).to.equal(1) 523 expect(abuseServer2.countReportsForReportee).to.equal(1)
524 }
556 }) 525 })
557 526
558 it('Should keep the comment abuse when deleting the comment', async function () { 527 it('Should keep the comment abuse when deleting the comment', async function () {
559 this.timeout(10000) 528 this.timeout(10000)
560 529
561 const commentServer2 = await getComment(servers[0].url, servers[1].video.id) 530 const commentServer2 = await getComment(servers[0], servers[1].store.video.id)
562 531
563 await deleteVideoComment(servers[0].url, servers[0].accessToken, servers[1].video.uuid, commentServer2.id) 532 await servers[0].comments.delete({ videoId: servers[1].store.video.uuid, commentId: commentServer2.id })
564 533
565 await waitJobs(servers) 534 await waitJobs(servers)
566 535
567 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 536 const body = await commands[0].getAdminList({ filter: 'comment' })
568 expect(res.body.total).to.equal(2) 537 expect(body.total).to.equal(2)
569 expect(res.body.data).to.have.lengthOf(2) 538 expect(body.data).to.have.lengthOf(2)
570 539
571 const abuse = (res.body.data as AdminAbuse[]).find(a => a.comment?.id === commentServer2.id) 540 const abuse = body.data.find(a => a.comment?.id === commentServer2.id)
572 expect(abuse).to.not.be.undefined 541 expect(abuse).to.not.be.undefined
573 542
574 expect(abuse.comment.text).to.be.empty 543 expect(abuse.comment.text).to.be.empty
@@ -579,72 +548,60 @@ describe('Test abuses', function () {
579 it('Should delete the comment abuse', async function () { 548 it('Should delete the comment abuse', async function () {
580 this.timeout(10000) 549 this.timeout(10000)
581 550
582 await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) 551 await commands[1].delete({ abuseId: abuseServer2.id })
583 552
584 await waitJobs(servers) 553 await waitJobs(servers)
585 554
586 { 555 {
587 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 556 const body = await commands[1].getAdminList({ filter: 'comment' })
588 expect(res.body.total).to.equal(0) 557 expect(body.total).to.equal(0)
589 expect(res.body.data.length).to.equal(0) 558 expect(body.data.length).to.equal(0)
590 } 559 }
591 560
592 { 561 {
593 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 562 const body = await commands[0].getAdminList({ filter: 'comment' })
594 expect(res.body.total).to.equal(2) 563 expect(body.total).to.equal(2)
595 } 564 }
596 }) 565 })
597 566
598 it('Should list and filter video abuses', async function () { 567 it('Should list and filter video abuses', async function () {
599 { 568 {
600 const res = await getAdminAbusesList({ 569 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' })
601 url: servers[0].url, 570 expect(body.total).to.equal(0)
602 token: servers[0].accessToken,
603 filter: 'comment',
604 searchReportee: 'foo'
605 })
606 expect(res.body.total).to.equal(0)
607 } 571 }
608 572
609 { 573 {
610 const res = await getAdminAbusesList({ 574 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' })
611 url: servers[0].url, 575 expect(body.total).to.equal(2)
612 token: servers[0].accessToken,
613 filter: 'comment',
614 searchReportee: 'ot'
615 })
616 expect(res.body.total).to.equal(2)
617 } 576 }
618 577
619 { 578 {
620 const baseParams = { url: servers[0].url, token: servers[0].accessToken, filter: 'comment' as AbuseFilter, start: 1, count: 1 } 579 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' })
621 580 expect(body.data).to.have.lengthOf(1)
622 const res1 = await getAdminAbusesList(immutableAssign(baseParams, { sort: 'createdAt' })) 581 expect(body.data[0].comment.text).to.be.empty
623 expect(res1.body.data).to.have.lengthOf(1) 582 }
624 expect(res1.body.data[0].comment.text).to.be.empty
625 583
626 const res2 = await getAdminAbusesList(immutableAssign(baseParams, { sort: '-createdAt' })) 584 {
627 expect(res2.body.data).to.have.lengthOf(1) 585 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' })
628 expect(res2.body.data[0].comment.text).to.equal('comment server 1') 586 expect(body.data).to.have.lengthOf(1)
587 expect(body.data[0].comment.text).to.equal('comment server 1')
629 } 588 }
630 }) 589 })
631 }) 590 })
632 591
633 describe('Account abuses', function () { 592 describe('Account abuses', function () {
634 593
635 async function getAccountFromServer (url: string, name: string, server: ServerInfo) { 594 function getAccountFromServer (server: PeerTubeServer, targetName: string, targetServer: PeerTubeServer) {
636 const res = await getAccount(url, name + '@' + server.host) 595 return server.accounts.get({ accountName: targetName + '@' + targetServer.host })
637
638 return res.body as Account
639 } 596 }
640 597
641 before(async function () { 598 before(async function () {
642 this.timeout(50000) 599 this.timeout(50000)
643 600
644 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' }) 601 await servers[0].users.create({ username: 'user_1', password: 'donald' })
645 602
646 const token = await generateUserAccessToken(servers[1], 'user_2') 603 const token = await servers[1].users.generateUserAndToken('user_2')
647 await uploadVideo(servers[1].url, token, { name: 'super video' }) 604 await servers[1].videos.upload({ token, attributes: { name: 'super video' } })
648 605
649 await waitJobs(servers) 606 await waitJobs(servers)
650 }) 607 })
@@ -652,22 +609,22 @@ describe('Test abuses', function () {
652 it('Should report abuse on an account', async function () { 609 it('Should report abuse on an account', async function () {
653 this.timeout(15000) 610 this.timeout(15000)
654 611
655 const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0]) 612 const account = await getAccountFromServer(servers[0], 'user_1', servers[0])
656 613
657 const reason = 'it is a bad account' 614 const reason = 'it is a bad account'
658 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason }) 615 await commands[0].report({ accountId: account.id, reason })
659 616
660 await waitJobs(servers) 617 await waitJobs(servers)
661 }) 618 })
662 619
663 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () { 620 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
664 { 621 {
665 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) 622 const body = await commands[0].getAdminList({ filter: 'account' })
666 623
667 expect(res.body.total).to.equal(1) 624 expect(body.total).to.equal(1)
668 expect(res.body.data).to.have.lengthOf(1) 625 expect(body.data).to.have.lengthOf(1)
669 626
670 const abuse: AdminAbuse = res.body.data[0] 627 const abuse = body.data[0]
671 expect(abuse.reason).to.equal('it is a bad account') 628 expect(abuse.reason).to.equal('it is a bad account')
672 629
673 expect(abuse.reporterAccount.name).to.equal('root') 630 expect(abuse.reporterAccount.name).to.equal('root')
@@ -681,96 +638,100 @@ describe('Test abuses', function () {
681 } 638 }
682 639
683 { 640 {
684 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 641 const body = await commands[1].getAdminList({ filter: 'comment' })
685 expect(res.body.total).to.equal(0) 642 expect(body.total).to.equal(0)
686 expect(res.body.data.length).to.equal(0) 643 expect(body.data.length).to.equal(0)
687 } 644 }
688 }) 645 })
689 646
690 it('Should report abuse on a remote account', async function () { 647 it('Should report abuse on a remote account', async function () {
691 this.timeout(10000) 648 this.timeout(10000)
692 649
693 const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1]) 650 const account = await getAccountFromServer(servers[0], 'user_2', servers[1])
694 651
695 const reason = 'it is a really bad account' 652 const reason = 'it is a really bad account'
696 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason }) 653 await commands[0].report({ accountId: account.id, reason })
697 654
698 await waitJobs(servers) 655 await waitJobs(servers)
699 }) 656 })
700 657
701 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { 658 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
702 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) 659 {
703 expect(res1.body.total).to.equal(2) 660 const body = await commands[0].getAdminList({ filter: 'account' })
704 expect(res1.body.data.length).to.equal(2) 661 expect(body.total).to.equal(2)
662 expect(body.data.length).to.equal(2)
705 663
706 const abuse: AdminAbuse = res1.body.data[0] 664 const abuse: AdminAbuse = body.data[0]
707 expect(abuse.reason).to.equal('it is a bad account') 665 expect(abuse.reason).to.equal('it is a bad account')
708 666
709 const abuse2: AdminAbuse = res1.body.data[1] 667 const abuse2: AdminAbuse = body.data[1]
710 expect(abuse2.reason).to.equal('it is a really bad account') 668 expect(abuse2.reason).to.equal('it is a really bad account')
711 669
712 expect(abuse2.reporterAccount.name).to.equal('root') 670 expect(abuse2.reporterAccount.name).to.equal('root')
713 expect(abuse2.reporterAccount.host).to.equal(servers[0].host) 671 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
714 672
715 expect(abuse2.video).to.be.null 673 expect(abuse2.video).to.be.null
716 expect(abuse2.comment).to.be.null 674 expect(abuse2.comment).to.be.null
717 675
718 expect(abuse2.state.id).to.equal(AbuseState.PENDING) 676 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
719 expect(abuse2.state.label).to.equal('Pending') 677 expect(abuse2.state.label).to.equal('Pending')
720 678
721 expect(abuse2.moderationComment).to.be.null 679 expect(abuse2.moderationComment).to.be.null
680 }
722 681
723 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) 682 {
724 expect(res2.body.total).to.equal(1) 683 const body = await commands[1].getAdminList({ filter: 'account' })
725 expect(res2.body.data.length).to.equal(1) 684 expect(body.total).to.equal(1)
685 expect(body.data.length).to.equal(1)
726 686
727 abuseServer2 = res2.body.data[0] 687 abuseServer2 = body.data[0]
728 688
729 expect(abuseServer2.reason).to.equal('it is a really bad account') 689 expect(abuseServer2.reason).to.equal('it is a really bad account')
730 690
731 expect(abuseServer2.reporterAccount.name).to.equal('root') 691 expect(abuseServer2.reporterAccount.name).to.equal('root')
732 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) 692 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
733 693
734 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) 694 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
735 expect(abuseServer2.state.label).to.equal('Pending') 695 expect(abuseServer2.state.label).to.equal('Pending')
736 696
737 expect(abuseServer2.moderationComment).to.be.null 697 expect(abuseServer2.moderationComment).to.be.null
698 }
738 }) 699 })
739 700
740 it('Should keep the account abuse when deleting the account', async function () { 701 it('Should keep the account abuse when deleting the account', async function () {
741 this.timeout(10000) 702 this.timeout(10000)
742 703
743 const account = await getAccountFromServer(servers[1].url, 'user_2', servers[1]) 704 const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
744 await removeUser(servers[1].url, account.userId, servers[1].accessToken) 705 await servers[1].users.remove({ userId: account.userId })
745 706
746 await waitJobs(servers) 707 await waitJobs(servers)
747 708
748 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) 709 const body = await commands[0].getAdminList({ filter: 'account' })
749 expect(res.body.total).to.equal(2) 710 expect(body.total).to.equal(2)
750 expect(res.body.data).to.have.lengthOf(2) 711 expect(body.data).to.have.lengthOf(2)
751 712
752 const abuse = (res.body.data as AdminAbuse[]).find(a => a.reason === 'it is a really bad account') 713 const abuse = body.data.find(a => a.reason === 'it is a really bad account')
753 expect(abuse).to.not.be.undefined 714 expect(abuse).to.not.be.undefined
754 }) 715 })
755 716
756 it('Should delete the account abuse', async function () { 717 it('Should delete the account abuse', async function () {
757 this.timeout(10000) 718 this.timeout(10000)
758 719
759 await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) 720 await commands[1].delete({ abuseId: abuseServer2.id })
760 721
761 await waitJobs(servers) 722 await waitJobs(servers)
762 723
763 { 724 {
764 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) 725 const body = await commands[1].getAdminList({ filter: 'account' })
765 expect(res.body.total).to.equal(0) 726 expect(body.total).to.equal(0)
766 expect(res.body.data.length).to.equal(0) 727 expect(body.data.length).to.equal(0)
767 } 728 }
768 729
769 { 730 {
770 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) 731 const body = await commands[0].getAdminList({ filter: 'account' })
771 expect(res.body.total).to.equal(2) 732 expect(body.total).to.equal(2)
772 733
773 abuseServer1 = res.body.data[0] 734 abuseServer1 = body.data[0]
774 } 735 }
775 }) 736 })
776 }) 737 })
@@ -778,20 +739,18 @@ describe('Test abuses', function () {
778 describe('Common actions on abuses', function () { 739 describe('Common actions on abuses', function () {
779 740
780 it('Should update the state of an abuse', async function () { 741 it('Should update the state of an abuse', async function () {
781 const body = { state: AbuseState.REJECTED } 742 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } })
782 await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body)
783 743
784 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) 744 const body = await commands[0].getAdminList({ id: abuseServer1.id })
785 expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED) 745 expect(body.data[0].state.id).to.equal(AbuseState.REJECTED)
786 }) 746 })
787 747
788 it('Should add a moderation comment', async function () { 748 it('Should add a moderation comment', async function () {
789 const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' } 749 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } })
790 await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body)
791 750
792 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) 751 const body = await commands[0].getAdminList({ id: abuseServer1.id })
793 expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED) 752 expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
794 expect(res.body.data[0].moderationComment).to.equal('It is valid') 753 expect(body.data[0].moderationComment).to.equal('Valid')
795 }) 754 })
796 }) 755 })
797 756
@@ -800,20 +759,20 @@ describe('Test abuses', function () {
800 let userAccessToken: string 759 let userAccessToken: string
801 760
802 before(async function () { 761 before(async function () {
803 userAccessToken = await generateUserAccessToken(servers[0], 'user_42') 762 userAccessToken = await servers[0].users.generateUserAndToken('user_42')
804 763
805 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) 764 await commands[0].report({ token: userAccessToken, videoId: servers[0].store.video.id, reason: 'user reason 1' })
806 765
807 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) 766 const videoId = await servers[0].videos.getId({ uuid: servers[1].store.video.uuid })
808 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId, reason: 'user reason 2' }) 767 await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
809 }) 768 })
810 769
811 it('Should correctly list my abuses', async function () { 770 it('Should correctly list my abuses', async function () {
812 { 771 {
813 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 5, sort: 'createdAt' }) 772 const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
814 expect(res.body.total).to.equal(2) 773 expect(body.total).to.equal(2)
815 774
816 const abuses: UserAbuse[] = res.body.data 775 const abuses = body.data
817 expect(abuses[0].reason).to.equal('user reason 1') 776 expect(abuses[0].reason).to.equal('user reason 1')
818 expect(abuses[1].reason).to.equal('user reason 2') 777 expect(abuses[1].reason).to.equal('user reason 2')
819 778
@@ -821,95 +780,77 @@ describe('Test abuses', function () {
821 } 780 }
822 781
823 { 782 {
824 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: 'createdAt' }) 783 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
825 expect(res.body.total).to.equal(2) 784 expect(body.total).to.equal(2)
826 785
827 const abuses: UserAbuse[] = res.body.data 786 const abuses: UserAbuse[] = body.data
828 expect(abuses[0].reason).to.equal('user reason 2') 787 expect(abuses[0].reason).to.equal('user reason 2')
829 } 788 }
830 789
831 { 790 {
832 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: '-createdAt' }) 791 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
833 expect(res.body.total).to.equal(2) 792 expect(body.total).to.equal(2)
834 793
835 const abuses: UserAbuse[] = res.body.data 794 const abuses: UserAbuse[] = body.data
836 expect(abuses[0].reason).to.equal('user reason 1') 795 expect(abuses[0].reason).to.equal('user reason 1')
837 } 796 }
838 }) 797 })
839 798
840 it('Should correctly filter my abuses by id', async function () { 799 it('Should correctly filter my abuses by id', async function () {
841 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, id: abuseId1 }) 800 const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 })
801 expect(body.total).to.equal(1)
842 802
843 expect(res.body.total).to.equal(1) 803 const abuses: UserAbuse[] = body.data
844
845 const abuses: UserAbuse[] = res.body.data
846 expect(abuses[0].reason).to.equal('user reason 1') 804 expect(abuses[0].reason).to.equal('user reason 1')
847 }) 805 })
848 806
849 it('Should correctly filter my abuses by search', async function () { 807 it('Should correctly filter my abuses by search', async function () {
850 const res = await getUserAbusesList({ 808 const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' })
851 url: servers[0].url, 809 expect(body.total).to.equal(1)
852 token: userAccessToken,
853 search: 'server 2'
854 })
855
856 expect(res.body.total).to.equal(1)
857 810
858 const abuses: UserAbuse[] = res.body.data 811 const abuses: UserAbuse[] = body.data
859 expect(abuses[0].reason).to.equal('user reason 2') 812 expect(abuses[0].reason).to.equal('user reason 2')
860 }) 813 })
861 814
862 it('Should correctly filter my abuses by state', async function () { 815 it('Should correctly filter my abuses by state', async function () {
863 const body = { state: AbuseState.REJECTED } 816 await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } })
864 await updateAbuse(servers[0].url, servers[0].accessToken, abuseId1, body)
865 817
866 const res = await getUserAbusesList({ 818 const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED })
867 url: servers[0].url, 819 expect(body.total).to.equal(1)
868 token: userAccessToken,
869 state: AbuseState.REJECTED
870 })
871
872 expect(res.body.total).to.equal(1)
873 820
874 const abuses: UserAbuse[] = res.body.data 821 const abuses: UserAbuse[] = body.data
875 expect(abuses[0].reason).to.equal('user reason 1') 822 expect(abuses[0].reason).to.equal('user reason 1')
876 }) 823 })
877 }) 824 })
878 825
879 describe('Abuse messages', async function () { 826 describe('Abuse messages', async function () {
880 let abuseId: number 827 let abuseId: number
881 let userAccessToken: string 828 let userToken: string
882 let abuseMessageUserId: number 829 let abuseMessageUserId: number
883 let abuseMessageModerationId: number 830 let abuseMessageModerationId: number
884 831
885 before(async function () { 832 before(async function () {
886 userAccessToken = await generateUserAccessToken(servers[0], 'user_43') 833 userToken = await servers[0].users.generateUserAndToken('user_43')
887 834
888 const res = await reportAbuse({ 835 const body = await commands[0].report({ token: userToken, videoId: servers[0].store.video.id, reason: 'user 43 reason 1' })
889 url: servers[0].url, 836 abuseId = body.abuse.id
890 token: userAccessToken,
891 videoId: servers[0].video.id,
892 reason: 'user 43 reason 1'
893 })
894
895 abuseId = res.body.abuse.id
896 }) 837 })
897 838
898 it('Should create some messages on the abuse', async function () { 839 it('Should create some messages on the abuse', async function () {
899 await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 1') 840 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' })
900 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 2') 841 await commands[0].addMessage({ abuseId, message: 'message 2' })
901 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 3') 842 await commands[0].addMessage({ abuseId, message: 'message 3' })
902 await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 4') 843 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' })
903 }) 844 })
904 845
905 it('Should have the correct messages count when listing abuses', async function () { 846 it('Should have the correct messages count when listing abuses', async function () {
906 const results = await Promise.all([ 847 const results = await Promise.all([
907 getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, start: 0, count: 50 }), 848 commands[0].getAdminList({ start: 0, count: 50 }),
908 getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 50 }) 849 commands[0].getUserList({ token: userToken, start: 0, count: 50 })
909 ]) 850 ])
910 851
911 for (const res of results) { 852 for (const body of results) {
912 const abuses: AdminAbuse[] = res.body.data 853 const abuses = body.data
913 const abuse = abuses.find(a => a.id === abuseId) 854 const abuse = abuses.find(a => a.id === abuseId)
914 expect(abuse.countMessages).to.equal(4) 855 expect(abuse.countMessages).to.equal(4)
915 } 856 }
@@ -917,14 +858,14 @@ describe('Test abuses', function () {
917 858
918 it('Should correctly list messages of this abuse', async function () { 859 it('Should correctly list messages of this abuse', async function () {
919 const results = await Promise.all([ 860 const results = await Promise.all([
920 listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId), 861 commands[0].listMessages({ abuseId }),
921 listAbuseMessages(servers[0].url, userAccessToken, abuseId) 862 commands[0].listMessages({ token: userToken, abuseId })
922 ]) 863 ])
923 864
924 for (const res of results) { 865 for (const body of results) {
925 expect(res.body.total).to.equal(4) 866 expect(body.total).to.equal(4)
926 867
927 const abuseMessages: AbuseMessage[] = res.body.data 868 const abuseMessages: AbuseMessage[] = body.data
928 869
929 expect(abuseMessages[0].message).to.equal('message 1') 870 expect(abuseMessages[0].message).to.equal('message 1')
930 expect(abuseMessages[0].byModerator).to.be.false 871 expect(abuseMessages[0].byModerator).to.be.false
@@ -948,19 +889,18 @@ describe('Test abuses', function () {
948 }) 889 })
949 890
950 it('Should delete messages', async function () { 891 it('Should delete messages', async function () {
951 await deleteAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, abuseMessageModerationId) 892 await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId })
952 await deleteAbuseMessage(servers[0].url, userAccessToken, abuseId, abuseMessageUserId) 893 await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId })
953 894
954 const results = await Promise.all([ 895 const results = await Promise.all([
955 listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId), 896 commands[0].listMessages({ abuseId }),
956 listAbuseMessages(servers[0].url, userAccessToken, abuseId) 897 commands[0].listMessages({ token: userToken, abuseId })
957 ]) 898 ])
958 899
959 for (const res of results) { 900 for (const body of results) {
960 expect(res.body.total).to.equal(2) 901 expect(body.total).to.equal(2)
961
962 const abuseMessages: AbuseMessage[] = res.body.data
963 902
903 const abuseMessages: AbuseMessage[] = body.data
964 expect(abuseMessages[0].message).to.equal('message 2') 904 expect(abuseMessages[0].message).to.equal('message 2')
965 expect(abuseMessages[1].message).to.equal('message 4') 905 expect(abuseMessages[1].message).to.equal('message 4')
966 } 906 }
diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts
index 4fb3c95f2..75b15c298 100644
--- a/server/tests/api/moderation/blocklist-notification.ts
+++ b/server/tests/api/moderation/blocklist-notification.ts
@@ -2,47 +2,22 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { getUserNotifications, markAsReadAllNotifications } from '@shared/extra-utils/users/user-notifications' 5import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
6import { addUserSubscription, removeUserSubscription } from '@shared/extra-utils/users/user-subscriptions' 6import { UserNotificationType } from '@shared/models'
7import { UserNotification, UserNotificationType } from '@shared/models'
8import {
9 cleanupTests,
10 createUser,
11 doubleFollow,
12 flushAndRunMultipleServers,
13 ServerInfo,
14 uploadVideo,
15 userLogin
16} from '../../../../shared/extra-utils/index'
17import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
18import {
19 addAccountToAccountBlocklist,
20 addAccountToServerBlocklist,
21 addServerToAccountBlocklist,
22 addServerToServerBlocklist,
23 removeAccountFromAccountBlocklist,
24 removeAccountFromServerBlocklist,
25 removeServerFromAccountBlocklist
26} from '../../../../shared/extra-utils/users/blocklist'
27import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
28import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
29 7
30const expect = chai.expect 8const expect = chai.expect
31 9
32async function checkNotifications (url: string, token: string, expected: UserNotificationType[]) { 10async function checkNotifications (server: PeerTubeServer, token: string, expected: UserNotificationType[]) {
33 const res = await getUserNotifications(url, token, 0, 10, true) 11 const { data } = await server.notifications.list({ token, start: 0, count: 10, unread: true })
34 12 expect(data).to.have.lengthOf(expected.length)
35 const notifications: UserNotification[] = res.body.data
36
37 expect(notifications).to.have.lengthOf(expected.length)
38 13
39 for (const type of expected) { 14 for (const type of expected) {
40 expect(notifications.find(n => n.type === type)).to.exist 15 expect(data.find(n => n.type === type)).to.exist
41 } 16 }
42} 17}
43 18
44describe('Test blocklist', function () { 19describe('Test blocklist', function () {
45 let servers: ServerInfo[] 20 let servers: PeerTubeServer[]
46 let videoUUID: string 21 let videoUUID: string
47 22
48 let userToken1: string 23 let userToken1: string
@@ -51,30 +26,34 @@ describe('Test blocklist', function () {
51 26
52 async function resetState () { 27 async function resetState () {
53 try { 28 try {
54 await removeUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host) 29 await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host })
55 await removeUserSubscription(servers[1].url, remoteUserToken, 'user2_channel@' + servers[0].host) 30 await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host })
56 } catch {} 31 } catch {}
57 32
58 await waitJobs(servers) 33 await waitJobs(servers)
59 34
60 await markAsReadAllNotifications(servers[0].url, userToken1) 35 await servers[0].notifications.markAsReadAll({ token: userToken1 })
61 await markAsReadAllNotifications(servers[0].url, userToken2) 36 await servers[0].notifications.markAsReadAll({ token: userToken2 })
62 37
63 { 38 {
64 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' }) 39 const { uuid } = await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video' } })
65 videoUUID = res.body.video.uuid 40 videoUUID = uuid
66 41
67 await waitJobs(servers) 42 await waitJobs(servers)
68 } 43 }
69 44
70 { 45 {
71 await addVideoCommentThread(servers[1].url, remoteUserToken, videoUUID, '@user2@' + servers[0].host + ' hello') 46 await servers[1].comments.createThread({
47 token: remoteUserToken,
48 videoId: videoUUID,
49 text: '@user2@' + servers[0].host + ' hello'
50 })
72 } 51 }
73 52
74 { 53 {
75 54
76 await addUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host) 55 await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host })
77 await addUserSubscription(servers[1].url, remoteUserToken, 'user2_channel@' + servers[0].host) 56 await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host })
78 } 57 }
79 58
80 await waitJobs(servers) 59 await waitJobs(servers)
@@ -83,36 +62,34 @@ describe('Test blocklist', function () {
83 before(async function () { 62 before(async function () {
84 this.timeout(60000) 63 this.timeout(60000)
85 64
86 servers = await flushAndRunMultipleServers(2) 65 servers = await createMultipleServers(2)
87 await setAccessTokensToServers(servers) 66 await setAccessTokensToServers(servers)
88 67
89 { 68 {
90 const user = { username: 'user1', password: 'password' } 69 const user = { username: 'user1', password: 'password' }
91 await createUser({ 70 await servers[0].users.create({
92 url: servers[0].url,
93 accessToken: servers[0].accessToken,
94 username: user.username, 71 username: user.username,
95 password: user.password, 72 password: user.password,
96 videoQuota: -1, 73 videoQuota: -1,
97 videoQuotaDaily: -1 74 videoQuotaDaily: -1
98 }) 75 })
99 76
100 userToken1 = await userLogin(servers[0], user) 77 userToken1 = await servers[0].login.getAccessToken(user)
101 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) 78 await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } })
102 } 79 }
103 80
104 { 81 {
105 const user = { username: 'user2', password: 'password' } 82 const user = { username: 'user2', password: 'password' }
106 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 83 await servers[0].users.create({ username: user.username, password: user.password })
107 84
108 userToken2 = await userLogin(servers[0], user) 85 userToken2 = await servers[0].login.getAccessToken(user)
109 } 86 }
110 87
111 { 88 {
112 const user = { username: 'user3', password: 'password' } 89 const user = { username: 'user3', password: 'password' }
113 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) 90 await servers[1].users.create({ username: user.username, password: user.password })
114 91
115 remoteUserToken = await userLogin(servers[1], user) 92 remoteUserToken = await servers[1].login.getAccessToken(user)
116 } 93 }
117 94
118 await doubleFollow(servers[0], servers[1]) 95 await doubleFollow(servers[0], servers[1])
@@ -128,26 +105,26 @@ describe('Test blocklist', function () {
128 105
129 it('Should have appropriate notifications', async function () { 106 it('Should have appropriate notifications', async function () {
130 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 107 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
131 await checkNotifications(servers[0].url, userToken1, notifs) 108 await checkNotifications(servers[0], userToken1, notifs)
132 }) 109 })
133 110
134 it('Should block an account', async function () { 111 it('Should block an account', async function () {
135 this.timeout(10000) 112 this.timeout(10000)
136 113
137 await addAccountToAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host) 114 await servers[0].blocklist.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
138 await waitJobs(servers) 115 await waitJobs(servers)
139 }) 116 })
140 117
141 it('Should not have notifications from this account', async function () { 118 it('Should not have notifications from this account', async function () {
142 await checkNotifications(servers[0].url, userToken1, []) 119 await checkNotifications(servers[0], userToken1, [])
143 }) 120 })
144 121
145 it('Should have notifications of this account on user 2', async function () { 122 it('Should have notifications of this account on user 2', async function () {
146 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 123 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
147 124
148 await checkNotifications(servers[0].url, userToken2, notifs) 125 await checkNotifications(servers[0], userToken2, notifs)
149 126
150 await removeAccountFromAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host) 127 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
151 }) 128 })
152 }) 129 })
153 130
@@ -161,26 +138,26 @@ describe('Test blocklist', function () {
161 138
162 it('Should have appropriate notifications', async function () { 139 it('Should have appropriate notifications', async function () {
163 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 140 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
164 await checkNotifications(servers[0].url, userToken1, notifs) 141 await checkNotifications(servers[0], userToken1, notifs)
165 }) 142 })
166 143
167 it('Should block an account', async function () { 144 it('Should block an account', async function () {
168 this.timeout(10000) 145 this.timeout(10000)
169 146
170 await addServerToAccountBlocklist(servers[0].url, userToken1, servers[1].host) 147 await servers[0].blocklist.addToMyBlocklist({ token: userToken1, server: servers[1].host })
171 await waitJobs(servers) 148 await waitJobs(servers)
172 }) 149 })
173 150
174 it('Should not have notifications from this account', async function () { 151 it('Should not have notifications from this account', async function () {
175 await checkNotifications(servers[0].url, userToken1, []) 152 await checkNotifications(servers[0], userToken1, [])
176 }) 153 })
177 154
178 it('Should have notifications of this account on user 2', async function () { 155 it('Should have notifications of this account on user 2', async function () {
179 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 156 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
180 157
181 await checkNotifications(servers[0].url, userToken2, notifs) 158 await checkNotifications(servers[0], userToken2, notifs)
182 159
183 await removeServerFromAccountBlocklist(servers[0].url, userToken1, servers[1].host) 160 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
184 }) 161 })
185 }) 162 })
186 163
@@ -195,27 +172,27 @@ describe('Test blocklist', function () {
195 it('Should have appropriate notifications', async function () { 172 it('Should have appropriate notifications', async function () {
196 { 173 {
197 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 174 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
198 await checkNotifications(servers[0].url, userToken1, notifs) 175 await checkNotifications(servers[0], userToken1, notifs)
199 } 176 }
200 177
201 { 178 {
202 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 179 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
203 await checkNotifications(servers[0].url, userToken2, notifs) 180 await checkNotifications(servers[0], userToken2, notifs)
204 } 181 }
205 }) 182 })
206 183
207 it('Should block an account', async function () { 184 it('Should block an account', async function () {
208 this.timeout(10000) 185 this.timeout(10000)
209 186
210 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host) 187 await servers[0].blocklist.addToServerBlocklist({ account: 'user3@' + servers[1].host })
211 await waitJobs(servers) 188 await waitJobs(servers)
212 }) 189 })
213 190
214 it('Should not have notifications from this account', async function () { 191 it('Should not have notifications from this account', async function () {
215 await checkNotifications(servers[0].url, userToken1, []) 192 await checkNotifications(servers[0], userToken1, [])
216 await checkNotifications(servers[0].url, userToken2, []) 193 await checkNotifications(servers[0], userToken2, [])
217 194
218 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host) 195 await servers[0].blocklist.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
219 }) 196 })
220 }) 197 })
221 198
@@ -230,25 +207,25 @@ describe('Test blocklist', function () {
230 it('Should have appropriate notifications', async function () { 207 it('Should have appropriate notifications', async function () {
231 { 208 {
232 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 209 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
233 await checkNotifications(servers[0].url, userToken1, notifs) 210 await checkNotifications(servers[0], userToken1, notifs)
234 } 211 }
235 212
236 { 213 {
237 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 214 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
238 await checkNotifications(servers[0].url, userToken2, notifs) 215 await checkNotifications(servers[0], userToken2, notifs)
239 } 216 }
240 }) 217 })
241 218
242 it('Should block an account', async function () { 219 it('Should block an account', async function () {
243 this.timeout(10000) 220 this.timeout(10000)
244 221
245 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) 222 await servers[0].blocklist.addToServerBlocklist({ server: servers[1].host })
246 await waitJobs(servers) 223 await waitJobs(servers)
247 }) 224 })
248 225
249 it('Should not have notifications from this account', async function () { 226 it('Should not have notifications from this account', async function () {
250 await checkNotifications(servers[0].url, userToken1, []) 227 await checkNotifications(servers[0], userToken1, [])
251 await checkNotifications(servers[0].url, userToken2, []) 228 await checkNotifications(servers[0], userToken2, [])
252 }) 229 })
253 }) 230 })
254 231
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 }
diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts
index 52cac20d9..d5838191a 100644
--- a/server/tests/api/moderation/video-blacklist.ts
+++ b/server/tests/api/moderation/video-blacklist.ts
@@ -4,44 +4,30 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { orderBy } from 'lodash' 5import { orderBy } from 'lodash'
6import { 6import {
7 addVideoToBlacklist, 7 BlacklistCommand,
8 cleanupTests, 8 cleanupTests,
9 createUser, 9 createMultipleServers,
10 flushAndRunMultipleServers, 10 doubleFollow,
11 getBlacklistedVideosList, 11 FIXTURE_URLS,
12 getMyUserInformation,
13 getMyVideos,
14 getVideosList,
15 killallServers, 12 killallServers,
16 removeVideoFromBlacklist, 13 PeerTubeServer,
17 reRunServer,
18 searchVideo,
19 ServerInfo,
20 setAccessTokensToServers, 14 setAccessTokensToServers,
21 updateVideo, 15 waitJobs
22 updateVideoBlacklist, 16} from '@shared/extra-utils'
23 uploadVideo, 17import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
24 userLogin
25} from '../../../../shared/extra-utils/index'
26import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
27import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
28import { getGoodVideoUrl, getMagnetURI, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
29import { User, UserRole } from '../../../../shared/models/users'
30import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
31import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos'
32 18
33const expect = chai.expect 19const expect = chai.expect
34 20
35describe('Test video blacklist', function () { 21describe('Test video blacklist', function () {
36 let servers: ServerInfo[] = [] 22 let servers: PeerTubeServer[] = []
37 let videoId: number 23 let videoId: number
24 let command: BlacklistCommand
38 25
39 async function blacklistVideosOnServer (server: ServerInfo) { 26 async function blacklistVideosOnServer (server: PeerTubeServer) {
40 const res = await getVideosList(server.url) 27 const { data } = await server.videos.list()
41 28
42 const videos = res.body.data 29 for (const video of data) {
43 for (const video of videos) { 30 await server.blacklist.add({ videoId: video.id, reason: 'super reason' })
44 await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason')
45 } 31 }
46 } 32 }
47 33
@@ -49,7 +35,7 @@ describe('Test video blacklist', function () {
49 this.timeout(50000) 35 this.timeout(50000)
50 36
51 // Run servers 37 // Run servers
52 servers = await flushAndRunMultipleServers(2) 38 servers = await createMultipleServers(2)
53 39
54 // Get the access tokens 40 // Get the access tokens
55 await setAccessTokensToServers(servers) 41 await setAccessTokensToServers(servers)
@@ -58,12 +44,14 @@ describe('Test video blacklist', function () {
58 await doubleFollow(servers[0], servers[1]) 44 await doubleFollow(servers[0], servers[1])
59 45
60 // Upload 2 videos on server 2 46 // Upload 2 videos on server 2
61 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' }) 47 await servers[1].videos.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } })
62 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) 48 await servers[1].videos.upload({ attributes: { name: 'My 2nd video', description: 'A video on server 2' } })
63 49
64 // Wait videos propagation, server 2 has transcoding enabled 50 // Wait videos propagation, server 2 has transcoding enabled
65 await waitJobs(servers) 51 await waitJobs(servers)
66 52
53 command = servers[0].blacklist
54
67 // Blacklist the two videos on server 1 55 // Blacklist the two videos on server 1
68 await blacklistVideosOnServer(servers[0]) 56 await blacklistVideosOnServer(servers[0])
69 }) 57 })
@@ -72,48 +60,47 @@ describe('Test video blacklist', function () {
72 60
73 it('Should not have the video blacklisted in videos list/search on server 1', async function () { 61 it('Should not have the video blacklisted in videos list/search on server 1', async function () {
74 { 62 {
75 const res = await getVideosList(servers[0].url) 63 const { total, data } = await servers[0].videos.list()
76 64
77 expect(res.body.total).to.equal(0) 65 expect(total).to.equal(0)
78 expect(res.body.data).to.be.an('array') 66 expect(data).to.be.an('array')
79 expect(res.body.data.length).to.equal(0) 67 expect(data.length).to.equal(0)
80 } 68 }
81 69
82 { 70 {
83 const res = await searchVideo(servers[0].url, 'name') 71 const body = await servers[0].search.searchVideos({ search: 'video' })
84 72
85 expect(res.body.total).to.equal(0) 73 expect(body.total).to.equal(0)
86 expect(res.body.data).to.be.an('array') 74 expect(body.data).to.be.an('array')
87 expect(res.body.data.length).to.equal(0) 75 expect(body.data.length).to.equal(0)
88 } 76 }
89 }) 77 })
90 78
91 it('Should have the blacklisted video in videos list/search on server 2', async function () { 79 it('Should have the blacklisted video in videos list/search on server 2', async function () {
92 { 80 {
93 const res = await getVideosList(servers[1].url) 81 const { total, data } = await servers[1].videos.list()
94 82
95 expect(res.body.total).to.equal(2) 83 expect(total).to.equal(2)
96 expect(res.body.data).to.be.an('array') 84 expect(data).to.be.an('array')
97 expect(res.body.data.length).to.equal(2) 85 expect(data.length).to.equal(2)
98 } 86 }
99 87
100 { 88 {
101 const res = await searchVideo(servers[1].url, 'video') 89 const body = await servers[1].search.searchVideos({ search: 'video' })
102 90
103 expect(res.body.total).to.equal(2) 91 expect(body.total).to.equal(2)
104 expect(res.body.data).to.be.an('array') 92 expect(body.data).to.be.an('array')
105 expect(res.body.data.length).to.equal(2) 93 expect(body.data.length).to.equal(2)
106 } 94 }
107 }) 95 })
108 }) 96 })
109 97
110 describe('When listing manually blacklisted videos', function () { 98 describe('When listing manually blacklisted videos', function () {
111 it('Should display all the blacklisted videos', async function () { 99 it('Should display all the blacklisted videos', async function () {
112 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken }) 100 const body = await command.list()
113 101 expect(body.total).to.equal(2)
114 expect(res.body.total).to.equal(2)
115 102
116 const blacklistedVideos = res.body.data 103 const blacklistedVideos = body.data
117 expect(blacklistedVideos).to.be.an('array') 104 expect(blacklistedVideos).to.be.an('array')
118 expect(blacklistedVideos.length).to.equal(2) 105 expect(blacklistedVideos.length).to.equal(2)
119 106
@@ -124,79 +111,66 @@ describe('Test video blacklist', function () {
124 }) 111 })
125 112
126 it('Should display all the blacklisted videos when applying manual type filter', async function () { 113 it('Should display all the blacklisted videos when applying manual type filter', async function () {
127 const res = await getBlacklistedVideosList({ 114 const body = await command.list({ type: VideoBlacklistType.MANUAL })
128 url: servers[0].url, 115 expect(body.total).to.equal(2)
129 token: servers[0].accessToken,
130 type: VideoBlacklistType.MANUAL
131 })
132 116
133 expect(res.body.total).to.equal(2) 117 const blacklistedVideos = body.data
134
135 const blacklistedVideos = res.body.data
136 expect(blacklistedVideos).to.be.an('array') 118 expect(blacklistedVideos).to.be.an('array')
137 expect(blacklistedVideos.length).to.equal(2) 119 expect(blacklistedVideos.length).to.equal(2)
138 }) 120 })
139 121
140 it('Should display nothing when applying automatic type filter', async function () { 122 it('Should display nothing when applying automatic type filter', async function () {
141 const res = await getBlacklistedVideosList({ 123 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
142 url: servers[0].url, 124 expect(body.total).to.equal(0)
143 token: servers[0].accessToken,
144 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
145 })
146
147 expect(res.body.total).to.equal(0)
148 125
149 const blacklistedVideos = res.body.data 126 const blacklistedVideos = body.data
150 expect(blacklistedVideos).to.be.an('array') 127 expect(blacklistedVideos).to.be.an('array')
151 expect(blacklistedVideos.length).to.equal(0) 128 expect(blacklistedVideos.length).to.equal(0)
152 }) 129 })
153 130
154 it('Should get the correct sort when sorting by descending id', async function () { 131 it('Should get the correct sort when sorting by descending id', async function () {
155 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-id' }) 132 const body = await command.list({ sort: '-id' })
156 expect(res.body.total).to.equal(2) 133 expect(body.total).to.equal(2)
157 134
158 const blacklistedVideos = res.body.data 135 const blacklistedVideos = body.data
159 expect(blacklistedVideos).to.be.an('array') 136 expect(blacklistedVideos).to.be.an('array')
160 expect(blacklistedVideos.length).to.equal(2) 137 expect(blacklistedVideos.length).to.equal(2)
161 138
162 const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ]) 139 const result = orderBy(body.data, [ 'id' ], [ 'desc' ])
163
164 expect(blacklistedVideos).to.deep.equal(result) 140 expect(blacklistedVideos).to.deep.equal(result)
165 }) 141 })
166 142
167 it('Should get the correct sort when sorting by descending video name', async function () { 143 it('Should get the correct sort when sorting by descending video name', async function () {
168 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) 144 const body = await command.list({ sort: '-name' })
169 expect(res.body.total).to.equal(2) 145 expect(body.total).to.equal(2)
170 146
171 const blacklistedVideos = res.body.data 147 const blacklistedVideos = body.data
172 expect(blacklistedVideos).to.be.an('array') 148 expect(blacklistedVideos).to.be.an('array')
173 expect(blacklistedVideos.length).to.equal(2) 149 expect(blacklistedVideos.length).to.equal(2)
174 150
175 const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ]) 151 const result = orderBy(body.data, [ 'name' ], [ 'desc' ])
176
177 expect(blacklistedVideos).to.deep.equal(result) 152 expect(blacklistedVideos).to.deep.equal(result)
178 }) 153 })
179 154
180 it('Should get the correct sort when sorting by ascending creation date', async function () { 155 it('Should get the correct sort when sorting by ascending creation date', async function () {
181 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' }) 156 const body = await command.list({ sort: 'createdAt' })
182 expect(res.body.total).to.equal(2) 157 expect(body.total).to.equal(2)
183 158
184 const blacklistedVideos = res.body.data 159 const blacklistedVideos = body.data
185 expect(blacklistedVideos).to.be.an('array') 160 expect(blacklistedVideos).to.be.an('array')
186 expect(blacklistedVideos.length).to.equal(2) 161 expect(blacklistedVideos.length).to.equal(2)
187 162
188 const result = orderBy(res.body.data, [ 'createdAt' ]) 163 const result = orderBy(body.data, [ 'createdAt' ])
189
190 expect(blacklistedVideos).to.deep.equal(result) 164 expect(blacklistedVideos).to.deep.equal(result)
191 }) 165 })
192 }) 166 })
193 167
194 describe('When updating blacklisted videos', function () { 168 describe('When updating blacklisted videos', function () {
195 it('Should change the reason', async function () { 169 it('Should change the reason', async function () {
196 await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') 170 await command.update({ videoId, reason: 'my super reason updated' })
197 171
198 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) 172 const body = await command.list({ sort: '-name' })
199 const video = res.body.data.find(b => b.video.id === videoId) 173 const video = body.data.find(b => b.video.id === videoId)
200 174
201 expect(video.reason).to.equal('my super reason updated') 175 expect(video.reason).to.equal('my super reason updated')
202 }) 176 })
@@ -206,12 +180,12 @@ describe('Test video blacklist', function () {
206 it('Should display blacklisted videos', async function () { 180 it('Should display blacklisted videos', async function () {
207 await blacklistVideosOnServer(servers[1]) 181 await blacklistVideosOnServer(servers[1])
208 182
209 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5) 183 const { total, data } = await servers[1].videos.listMyVideos()
210 184
211 expect(res.body.total).to.equal(2) 185 expect(total).to.equal(2)
212 expect(res.body.data).to.have.lengthOf(2) 186 expect(data).to.have.lengthOf(2)
213 187
214 for (const video of res.body.data) { 188 for (const video of data) {
215 expect(video.blacklisted).to.be.true 189 expect(video.blacklisted).to.be.true
216 expect(video.blacklistedReason).to.equal('super reason') 190 expect(video.blacklistedReason).to.equal('super reason')
217 } 191 }
@@ -223,39 +197,38 @@ describe('Test video blacklist', function () {
223 let blacklist = [] 197 let blacklist = []
224 198
225 it('Should not have any video in videos list on server 1', async function () { 199 it('Should not have any video in videos list on server 1', async function () {
226 const res = await getVideosList(servers[0].url) 200 const { total, data } = await servers[0].videos.list()
227 expect(res.body.total).to.equal(0) 201 expect(total).to.equal(0)
228 expect(res.body.data).to.be.an('array') 202 expect(data).to.be.an('array')
229 expect(res.body.data.length).to.equal(0) 203 expect(data.length).to.equal(0)
230 }) 204 })
231 205
232 it('Should remove a video from the blacklist on server 1', async function () { 206 it('Should remove a video from the blacklist on server 1', async function () {
233 // Get one video in the blacklist 207 // Get one video in the blacklist
234 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) 208 const body = await command.list({ sort: '-name' })
235 videoToRemove = res.body.data[0] 209 videoToRemove = body.data[0]
236 blacklist = res.body.data.slice(1) 210 blacklist = body.data.slice(1)
237 211
238 // Remove it 212 // Remove it
239 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id) 213 await command.remove({ videoId: videoToRemove.video.id })
240 }) 214 })
241 215
242 it('Should have the ex-blacklisted video in videos list on server 1', async function () { 216 it('Should have the ex-blacklisted video in videos list on server 1', async function () {
243 const res = await getVideosList(servers[0].url) 217 const { total, data } = await servers[0].videos.list()
244 expect(res.body.total).to.equal(1) 218 expect(total).to.equal(1)
245 219
246 const videos = res.body.data 220 expect(data).to.be.an('array')
247 expect(videos).to.be.an('array') 221 expect(data.length).to.equal(1)
248 expect(videos.length).to.equal(1)
249 222
250 expect(videos[0].name).to.equal(videoToRemove.video.name) 223 expect(data[0].name).to.equal(videoToRemove.video.name)
251 expect(videos[0].id).to.equal(videoToRemove.video.id) 224 expect(data[0].id).to.equal(videoToRemove.video.id)
252 }) 225 })
253 226
254 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { 227 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
255 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) 228 const body = await command.list({ sort: '-name' })
256 expect(res.body.total).to.equal(1) 229 expect(body.total).to.equal(1)
257 230
258 const videos = res.body.data 231 const videos = body.data
259 expect(videos).to.be.an('array') 232 expect(videos).to.be.an('array')
260 expect(videos.length).to.equal(1) 233 expect(videos.length).to.equal(1)
261 expect(videos).to.deep.equal(blacklist) 234 expect(videos).to.deep.equal(blacklist)
@@ -270,12 +243,12 @@ describe('Test video blacklist', function () {
270 this.timeout(10000) 243 this.timeout(10000)
271 244
272 { 245 {
273 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' }) 246 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'Video 3' } })
274 video3UUID = res.body.video.uuid 247 video3UUID = uuid
275 } 248 }
276 { 249 {
277 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 4' }) 250 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'Video 4' } })
278 video4UUID = res.body.video.uuid 251 video4UUID = uuid
279 } 252 }
280 253
281 await waitJobs(servers) 254 await waitJobs(servers)
@@ -284,51 +257,51 @@ describe('Test video blacklist', function () {
284 it('Should blacklist video 3 and keep it federated', async function () { 257 it('Should blacklist video 3 and keep it federated', async function () {
285 this.timeout(10000) 258 this.timeout(10000)
286 259
287 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video3UUID, 'super reason', false) 260 await command.add({ videoId: video3UUID, reason: 'super reason', unfederate: false })
288 261
289 await waitJobs(servers) 262 await waitJobs(servers)
290 263
291 { 264 {
292 const res = await getVideosList(servers[0].url) 265 const { data } = await servers[0].videos.list()
293 expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined 266 expect(data.find(v => v.uuid === video3UUID)).to.be.undefined
294 } 267 }
295 268
296 { 269 {
297 const res = await getVideosList(servers[1].url) 270 const { data } = await servers[1].videos.list()
298 expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined 271 expect(data.find(v => v.uuid === video3UUID)).to.not.be.undefined
299 } 272 }
300 }) 273 })
301 274
302 it('Should unfederate the video', async function () { 275 it('Should unfederate the video', async function () {
303 this.timeout(10000) 276 this.timeout(10000)
304 277
305 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video4UUID, 'super reason', true) 278 await command.add({ videoId: video4UUID, reason: 'super reason', unfederate: true })
306 279
307 await waitJobs(servers) 280 await waitJobs(servers)
308 281
309 for (const server of servers) { 282 for (const server of servers) {
310 const res = await getVideosList(server.url) 283 const { data } = await server.videos.list()
311 expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined 284 expect(data.find(v => v.uuid === video4UUID)).to.be.undefined
312 } 285 }
313 }) 286 })
314 287
315 it('Should have the video unfederated even after an Update AP message', async function () { 288 it('Should have the video unfederated even after an Update AP message', async function () {
316 this.timeout(10000) 289 this.timeout(10000)
317 290
318 await updateVideo(servers[0].url, servers[0].accessToken, video4UUID, { description: 'super description' }) 291 await servers[0].videos.update({ id: video4UUID, attributes: { description: 'super description' } })
319 292
320 await waitJobs(servers) 293 await waitJobs(servers)
321 294
322 for (const server of servers) { 295 for (const server of servers) {
323 const res = await getVideosList(server.url) 296 const { data } = await server.videos.list()
324 expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined 297 expect(data.find(v => v.uuid === video4UUID)).to.be.undefined
325 } 298 }
326 }) 299 })
327 300
328 it('Should have the correct video blacklist unfederate attribute', async function () { 301 it('Should have the correct video blacklist unfederate attribute', async function () {
329 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' }) 302 const body = await command.list({ sort: 'createdAt' })
330 303
331 const blacklistedVideos: VideoBlacklist[] = res.body.data 304 const blacklistedVideos = body.data
332 const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) 305 const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID)
333 const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID) 306 const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID)
334 307
@@ -339,13 +312,13 @@ describe('Test video blacklist', function () {
339 it('Should remove the video from blacklist and refederate the video', async function () { 312 it('Should remove the video from blacklist and refederate the video', async function () {
340 this.timeout(10000) 313 this.timeout(10000)
341 314
342 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video4UUID) 315 await command.remove({ videoId: video4UUID })
343 316
344 await waitJobs(servers) 317 await waitJobs(servers)
345 318
346 for (const server of servers) { 319 for (const server of servers) {
347 const res = await getVideosList(server.url) 320 const { data } = await server.videos.list()
348 expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined 321 expect(data.find(v => v.uuid === video4UUID)).to.not.be.undefined
349 } 322 }
350 }) 323 })
351 324
@@ -359,7 +332,7 @@ describe('Test video blacklist', function () {
359 before(async function () { 332 before(async function () {
360 this.timeout(20000) 333 this.timeout(20000)
361 334
362 killallServers([ servers[0] ]) 335 await killallServers([ servers[0] ])
363 336
364 const config = { 337 const config = {
365 auto_blacklist: { 338 auto_blacklist: {
@@ -370,106 +343,79 @@ describe('Test video blacklist', function () {
370 } 343 }
371 } 344 }
372 } 345 }
373 await reRunServer(servers[0], config) 346 await servers[0].run(config)
374 347
375 { 348 {
376 const user = { username: 'user_without_flag', password: 'password' } 349 const user = { username: 'user_without_flag', password: 'password' }
377 await createUser({ 350 await servers[0].users.create({
378 url: servers[0].url,
379 accessToken: servers[0].accessToken,
380 username: user.username, 351 username: user.username,
381 adminFlags: UserAdminFlag.NONE, 352 adminFlags: UserAdminFlag.NONE,
382 password: user.password, 353 password: user.password,
383 role: UserRole.USER 354 role: UserRole.USER
384 }) 355 })
385 356
386 userWithoutFlag = await userLogin(servers[0], user) 357 userWithoutFlag = await servers[0].login.getAccessToken(user)
387 358
388 const res = await getMyUserInformation(servers[0].url, userWithoutFlag) 359 const { videoChannels } = await servers[0].users.getMyInfo({ token: userWithoutFlag })
389 const body: User = res.body 360 channelOfUserWithoutFlag = videoChannels[0].id
390 channelOfUserWithoutFlag = body.videoChannels[0].id
391 } 361 }
392 362
393 { 363 {
394 const user = { username: 'user_with_flag', password: 'password' } 364 const user = { username: 'user_with_flag', password: 'password' }
395 await createUser({ 365 await servers[0].users.create({
396 url: servers[0].url,
397 accessToken: servers[0].accessToken,
398 username: user.username, 366 username: user.username,
399 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST, 367 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST,
400 password: user.password, 368 password: user.password,
401 role: UserRole.USER 369 role: UserRole.USER
402 }) 370 })
403 371
404 userWithFlag = await userLogin(servers[0], user) 372 userWithFlag = await servers[0].login.getAccessToken(user)
405 } 373 }
406 374
407 await waitJobs(servers) 375 await waitJobs(servers)
408 }) 376 })
409 377
410 it('Should auto blacklist a video on upload', async function () { 378 it('Should auto blacklist a video on upload', async function () {
411 await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) 379 await servers[0].videos.upload({ token: userWithoutFlag, attributes: { name: 'blacklisted' } })
412
413 const res = await getBlacklistedVideosList({
414 url: servers[0].url,
415 token: servers[0].accessToken,
416 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
417 })
418 380
419 expect(res.body.total).to.equal(1) 381 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
420 expect(res.body.data[0].video.name).to.equal('blacklisted') 382 expect(body.total).to.equal(1)
383 expect(body.data[0].video.name).to.equal('blacklisted')
421 }) 384 })
422 385
423 it('Should auto blacklist a video on URL import', async function () { 386 it('Should auto blacklist a video on URL import', async function () {
424 this.timeout(15000) 387 this.timeout(15000)
425 388
426 const attributes = { 389 const attributes = {
427 targetUrl: getGoodVideoUrl(), 390 targetUrl: FIXTURE_URLS.goodVideo,
428 name: 'URL import', 391 name: 'URL import',
429 channelId: channelOfUserWithoutFlag 392 channelId: channelOfUserWithoutFlag
430 } 393 }
431 await importVideo(servers[0].url, userWithoutFlag, attributes) 394 await servers[0].imports.importVideo({ token: userWithoutFlag, attributes })
432 395
433 const res = await getBlacklistedVideosList({ 396 const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
434 url: servers[0].url, 397 expect(body.total).to.equal(2)
435 token: servers[0].accessToken, 398 expect(body.data[1].video.name).to.equal('URL import')
436 sort: 'createdAt',
437 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
438 })
439
440 expect(res.body.total).to.equal(2)
441 expect(res.body.data[1].video.name).to.equal('URL import')
442 }) 399 })
443 400
444 it('Should auto blacklist a video on torrent import', async function () { 401 it('Should auto blacklist a video on torrent import', async function () {
445 const attributes = { 402 const attributes = {
446 magnetUri: getMagnetURI(), 403 magnetUri: FIXTURE_URLS.magnet,
447 name: 'Torrent import', 404 name: 'Torrent import',
448 channelId: channelOfUserWithoutFlag 405 channelId: channelOfUserWithoutFlag
449 } 406 }
450 await importVideo(servers[0].url, userWithoutFlag, attributes) 407 await servers[0].imports.importVideo({ token: userWithoutFlag, attributes })
451
452 const res = await getBlacklistedVideosList({
453 url: servers[0].url,
454 token: servers[0].accessToken,
455 sort: 'createdAt',
456 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
457 })
458 408
459 expect(res.body.total).to.equal(3) 409 const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
460 expect(res.body.data[2].video.name).to.equal('Torrent import') 410 expect(body.total).to.equal(3)
411 expect(body.data[2].video.name).to.equal('Torrent import')
461 }) 412 })
462 413
463 it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { 414 it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () {
464 await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) 415 await servers[0].videos.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } })
465
466 const res = await getBlacklistedVideosList({
467 url: servers[0].url,
468 token: servers[0].accessToken,
469 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
470 })
471 416
472 expect(res.body.total).to.equal(3) 417 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
418 expect(body.total).to.equal(3)
473 }) 419 })
474 }) 420 })
475 421