aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/moderation/abuses.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/moderation/abuses.ts')
-rw-r--r--server/tests/api/moderation/abuses.ts631
1 files changed, 294 insertions, 337 deletions
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts
index fb765e7e3..a9f5332ce 100644
--- a/server/tests/api/moderation/abuses.ts
+++ b/server/tests/api/moderation/abuses.ts
@@ -3,51 +3,32 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 AbuseFilter, 6 AbusesCommand,
7 AbuseMessage, 7 addAccountToServerBlocklist,
8 AbusePredefinedReasonsString, 8 addServerToServerBlocklist,
9 AbuseState,
10 Account,
11 AdminAbuse,
12 UserAbuse,
13 VideoComment
14} from '@shared/models'
15import {
16 addAbuseMessage,
17 addVideoCommentThread, 9 addVideoCommentThread,
18 cleanupTests, 10 cleanupTests,
19 createUser, 11 createUser,
20 deleteAbuse,
21 deleteAbuseMessage,
22 deleteVideoComment, 12 deleteVideoComment,
13 doubleFollow,
23 flushAndRunMultipleServers, 14 flushAndRunMultipleServers,
24 generateUserAccessToken, 15 generateUserAccessToken,
25 getAccount, 16 getAccount,
26 getAdminAbusesList,
27 getUserAbusesList,
28 getVideoCommentThreads, 17 getVideoCommentThreads,
29 getVideoIdFromUUID, 18 getVideoIdFromUUID,
30 getVideosList, 19 getVideosList,
31 immutableAssign, 20 removeAccountFromServerBlocklist,
32 listAbuseMessages, 21 removeServerFromServerBlocklist,
33 removeUser, 22 removeUser,
34 removeVideo, 23 removeVideo,
35 reportAbuse,
36 ServerInfo, 24 ServerInfo,
37 setAccessTokensToServers, 25 setAccessTokensToServers,
38 updateAbuse,
39 uploadVideo, 26 uploadVideo,
40 uploadVideoAndGetId, 27 uploadVideoAndGetId,
41 userLogin 28 userLogin,
42} from '../../../../shared/extra-utils/index' 29 waitJobs
43import { doubleFollow } from '../../../../shared/extra-utils/server/follows' 30} from '@shared/extra-utils'
44import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 31import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, Account, AdminAbuse, UserAbuse, VideoComment } from '@shared/models'
45import {
46 addAccountToServerBlocklist,
47 addServerToServerBlocklist,
48 removeAccountFromServerBlocklist,
49 removeServerFromServerBlocklist
50} from '../../../../shared/extra-utils/users/blocklist'
51 32
52const expect = chai.expect 33const expect = chai.expect
53 34
@@ -55,6 +36,7 @@ describe('Test abuses', function () {
55 let servers: ServerInfo[] = [] 36 let servers: ServerInfo[] = []
56 let abuseServer1: AdminAbuse 37 let abuseServer1: AdminAbuse
57 let abuseServer2: AdminAbuse 38 let abuseServer2: AdminAbuse
39 let commands: AbusesCommand[]
58 40
59 before(async function () { 41 before(async function () {
60 this.timeout(50000) 42 this.timeout(50000)
@@ -67,6 +49,8 @@ describe('Test abuses', function () {
67 49
68 // Server 1 and server 2 follow each other 50 // Server 1 and server 2 follow each other
69 await doubleFollow(servers[0], servers[1]) 51 await doubleFollow(servers[0], servers[1])
52
53 commands = servers.map(s => s.abusesCommand)
70 }) 54 })
71 55
72 describe('Video abuses', function () { 56 describe('Video abuses', function () {
@@ -100,54 +84,58 @@ describe('Test abuses', function () {
100 }) 84 })
101 85
102 it('Should not have abuses', async function () { 86 it('Should not have abuses', async function () {
103 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 87 const body = await commands[0].getAdminList()
104 88
105 expect(res.body.total).to.equal(0) 89 expect(body.total).to.equal(0)
106 expect(res.body.data).to.be.an('array') 90 expect(body.data).to.be.an('array')
107 expect(res.body.data.length).to.equal(0) 91 expect(body.data.length).to.equal(0)
108 }) 92 })
109 93
110 it('Should report abuse on a local video', async function () { 94 it('Should report abuse on a local video', async function () {
111 this.timeout(15000) 95 this.timeout(15000)
112 96
113 const reason = 'my super bad reason' 97 const reason = 'my super bad reason'
114 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: servers[0].video.id, reason }) 98 await commands[0].report({ videoId: servers[0].video.id, reason })
115 99
116 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 100 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
117 await waitJobs(servers) 101 await waitJobs(servers)
118 }) 102 })
119 103
120 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { 104 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 }) 105 {
106 const body = await commands[0].getAdminList()
122 107
123 expect(res1.body.total).to.equal(1) 108 expect(body.total).to.equal(1)
124 expect(res1.body.data).to.be.an('array') 109 expect(body.data).to.be.an('array')
125 expect(res1.body.data.length).to.equal(1) 110 expect(body.data.length).to.equal(1)
126 111
127 const abuse: AdminAbuse = res1.body.data[0] 112 const abuse = body.data[0]
128 expect(abuse.reason).to.equal('my super bad reason') 113 expect(abuse.reason).to.equal('my super bad reason')
129 114
130 expect(abuse.reporterAccount.name).to.equal('root') 115 expect(abuse.reporterAccount.name).to.equal('root')
131 expect(abuse.reporterAccount.host).to.equal(servers[0].host) 116 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
132 117
133 expect(abuse.video.id).to.equal(servers[0].video.id) 118 expect(abuse.video.id).to.equal(servers[0].video.id)
134 expect(abuse.video.channel).to.exist 119 expect(abuse.video.channel).to.exist
135 120
136 expect(abuse.comment).to.be.null 121 expect(abuse.comment).to.be.null
137 122
138 expect(abuse.flaggedAccount.name).to.equal('root') 123 expect(abuse.flaggedAccount.name).to.equal('root')
139 expect(abuse.flaggedAccount.host).to.equal(servers[0].host) 124 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
140 125
141 expect(abuse.video.countReports).to.equal(1) 126 expect(abuse.video.countReports).to.equal(1)
142 expect(abuse.video.nthReport).to.equal(1) 127 expect(abuse.video.nthReport).to.equal(1)
143 128
144 expect(abuse.countReportsForReporter).to.equal(1) 129 expect(abuse.countReportsForReporter).to.equal(1)
145 expect(abuse.countReportsForReportee).to.equal(1) 130 expect(abuse.countReportsForReportee).to.equal(1)
131 }
146 132
147 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 133 {
148 expect(res2.body.total).to.equal(0) 134 const body = await commands[1].getAdminList()
149 expect(res2.body.data).to.be.an('array') 135 expect(body.total).to.equal(0)
150 expect(res2.body.data.length).to.equal(0) 136 expect(body.data).to.be.an('array')
137 expect(body.data.length).to.equal(0)
138 }
151 }) 139 })
152 140
153 it('Should report abuse on a remote video', async function () { 141 it('Should report abuse on a remote video', async function () {
@@ -155,68 +143,72 @@ describe('Test abuses', function () {
155 143
156 const reason = 'my super bad reason 2' 144 const reason = 'my super bad reason 2'
157 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) 145 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
158 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId, reason }) 146 await commands[0].report({ videoId, reason })
159 147
160 // We wait requests propagation 148 // We wait requests propagation
161 await waitJobs(servers) 149 await waitJobs(servers)
162 }) 150 })
163 151
164 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { 152 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 }) 153 {
154 const body = await commands[0].getAdminList()
166 155
167 expect(res1.body.total).to.equal(2) 156 expect(body.total).to.equal(2)
168 expect(res1.body.data.length).to.equal(2) 157 expect(body.data.length).to.equal(2)
169 158
170 const abuse1: AdminAbuse = res1.body.data[0] 159 const abuse1 = body.data[0]
171 expect(abuse1.reason).to.equal('my super bad reason') 160 expect(abuse1.reason).to.equal('my super bad reason')
172 expect(abuse1.reporterAccount.name).to.equal('root') 161 expect(abuse1.reporterAccount.name).to.equal('root')
173 expect(abuse1.reporterAccount.host).to.equal(servers[0].host) 162 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
174 163
175 expect(abuse1.video.id).to.equal(servers[0].video.id) 164 expect(abuse1.video.id).to.equal(servers[0].video.id)
176 expect(abuse1.video.countReports).to.equal(1) 165 expect(abuse1.video.countReports).to.equal(1)
177 expect(abuse1.video.nthReport).to.equal(1) 166 expect(abuse1.video.nthReport).to.equal(1)
178 167
179 expect(abuse1.comment).to.be.null 168 expect(abuse1.comment).to.be.null
180 169
181 expect(abuse1.flaggedAccount.name).to.equal('root') 170 expect(abuse1.flaggedAccount.name).to.equal('root')
182 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host) 171 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
183 172
184 expect(abuse1.state.id).to.equal(AbuseState.PENDING) 173 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
185 expect(abuse1.state.label).to.equal('Pending') 174 expect(abuse1.state.label).to.equal('Pending')
186 expect(abuse1.moderationComment).to.be.null 175 expect(abuse1.moderationComment).to.be.null
187 176
188 const abuse2: AdminAbuse = res1.body.data[1] 177 const abuse2 = body.data[1]
189 expect(abuse2.reason).to.equal('my super bad reason 2') 178 expect(abuse2.reason).to.equal('my super bad reason 2')
190 179
191 expect(abuse2.reporterAccount.name).to.equal('root') 180 expect(abuse2.reporterAccount.name).to.equal('root')
192 expect(abuse2.reporterAccount.host).to.equal(servers[0].host) 181 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
193 182
194 expect(abuse2.video.id).to.equal(servers[1].video.id) 183 expect(abuse2.video.id).to.equal(servers[1].video.id)
195 184
196 expect(abuse2.comment).to.be.null 185 expect(abuse2.comment).to.be.null
197 186
198 expect(abuse2.flaggedAccount.name).to.equal('root') 187 expect(abuse2.flaggedAccount.name).to.equal('root')
199 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) 188 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
200 189
201 expect(abuse2.state.id).to.equal(AbuseState.PENDING) 190 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
202 expect(abuse2.state.label).to.equal('Pending') 191 expect(abuse2.state.label).to.equal('Pending')
203 expect(abuse2.moderationComment).to.be.null 192 expect(abuse2.moderationComment).to.be.null
193 }
204 194
205 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 195 {
206 expect(res2.body.total).to.equal(1) 196 const body = await commands[1].getAdminList()
207 expect(res2.body.data.length).to.equal(1) 197 expect(body.total).to.equal(1)
198 expect(body.data.length).to.equal(1)
208 199
209 abuseServer2 = res2.body.data[0] 200 abuseServer2 = body.data[0]
210 expect(abuseServer2.reason).to.equal('my super bad reason 2') 201 expect(abuseServer2.reason).to.equal('my super bad reason 2')
211 expect(abuseServer2.reporterAccount.name).to.equal('root') 202 expect(abuseServer2.reporterAccount.name).to.equal('root')
212 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) 203 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
213 204
214 expect(abuse2.flaggedAccount.name).to.equal('root') 205 expect(abuseServer2.flaggedAccount.name).to.equal('root')
215 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) 206 expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host)
216 207
217 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) 208 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
218 expect(abuseServer2.state.label).to.equal('Pending') 209 expect(abuseServer2.state.label).to.equal('Pending')
219 expect(abuseServer2.moderationComment).to.be.null 210 expect(abuseServer2.moderationComment).to.be.null
211 }
220 }) 212 })
221 213
222 it('Should hide video abuses from blocked accounts', async function () { 214 it('Should hide video abuses from blocked accounts', async function () {
@@ -224,11 +216,11 @@ describe('Test abuses', function () {
224 216
225 { 217 {
226 const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid) 218 const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid)
227 await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'will mute this' }) 219 await commands[1].report({ videoId, reason: 'will mute this' })
228 await waitJobs(servers) 220 await waitJobs(servers)
229 221
230 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 222 const body = await commands[0].getAdminList()
231 expect(res.body.total).to.equal(3) 223 expect(body.total).to.equal(3)
232 } 224 }
233 225
234 const accountToBlock = 'root@' + servers[1].host 226 const accountToBlock = 'root@' + servers[1].host
@@ -236,18 +228,18 @@ describe('Test abuses', function () {
236 { 228 {
237 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) 229 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
238 230
239 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 231 const body = await commands[0].getAdminList()
240 expect(res.body.total).to.equal(2) 232 expect(body.total).to.equal(2)
241 233
242 const abuse = res.body.data.find(a => a.reason === 'will mute this') 234 const abuse = body.data.find(a => a.reason === 'will mute this')
243 expect(abuse).to.be.undefined 235 expect(abuse).to.be.undefined
244 } 236 }
245 237
246 { 238 {
247 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) 239 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
248 240
249 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 241 const body = await commands[0].getAdminList()
250 expect(res.body.total).to.equal(3) 242 expect(body.total).to.equal(3)
251 } 243 }
252 }) 244 })
253 245
@@ -257,18 +249,18 @@ describe('Test abuses', function () {
257 { 249 {
258 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) 250 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)
259 251
260 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 252 const body = await commands[0].getAdminList()
261 expect(res.body.total).to.equal(2) 253 expect(body.total).to.equal(2)
262 254
263 const abuse = res.body.data.find(a => a.reason === 'will mute this') 255 const abuse = body.data.find(a => a.reason === 'will mute this')
264 expect(abuse).to.be.undefined 256 expect(abuse).to.be.undefined
265 } 257 }
266 258
267 { 259 {
268 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) 260 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock)
269 261
270 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 262 const body = await commands[0].getAdminList()
271 expect(res.body.total).to.equal(3) 263 expect(body.total).to.equal(3)
272 } 264 }
273 }) 265 })
274 266
@@ -279,11 +271,11 @@ describe('Test abuses', function () {
279 271
280 await waitJobs(servers) 272 await waitJobs(servers)
281 273
282 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 274 const body = await commands[1].getAdminList()
283 expect(res.body.total).to.equal(2, "wrong number of videos returned") 275 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") 276 expect(body.data).to.have.lengthOf(2, "wrong number of videos returned")
285 277
286 const abuse: AdminAbuse = res.body.data[0] 278 const abuse = body.data[0]
287 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video") 279 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") 280 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
289 expect(abuse.video.channel).to.exist 281 expect(abuse.video.channel).to.exist
@@ -303,24 +295,21 @@ describe('Test abuses', function () {
303 name: 'my second super name for server 1', 295 name: 'my second super name for server 1',
304 description: 'my second super description for server 1' 296 description: 'my second super description for server 1'
305 } 297 }
306 await uploadVideo(servers[0].url, userAccessToken, video3Attributes) 298 const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes)
307 299 const video3Id = resUpload.body.video.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 300
312 // resume with the test 301 // resume with the test
313 const reason3 = 'my super bad reason 3' 302 const reason3 = 'my super bad reason 3'
314 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video3.id, reason: reason3 }) 303 await commands[0].report({ videoId: video3Id, reason: reason3 })
315 304
316 const reason4 = 'my super bad reason 4' 305 const reason4 = 'my super bad reason 4'
317 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: reason4 }) 306 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: reason4 })
318 307
319 { 308 {
320 const res2 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 309 const body = await commands[0].getAdminList()
321 const abuses = res2.body.data as AdminAbuse[] 310 const abuses = body.data
322 311
323 const abuseVideo3 = res2.body.data.find(a => a.video.id === video3.id) 312 const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
324 expect(abuseVideo3).to.not.be.undefined 313 expect(abuseVideo3).to.not.be.undefined
325 expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3") 314 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") 315 expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3")
@@ -337,20 +326,18 @@ describe('Test abuses', function () {
337 326
338 const reason5 = 'my super bad reason 5' 327 const reason5 = 'my super bad reason 5'
339 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ] 328 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
340 const createdAbuse = (await reportAbuse({ 329 const createRes = await commands[0].report({
341 url: servers[0].url,
342 token: servers[0].accessToken,
343 videoId: servers[0].video.id, 330 videoId: servers[0].video.id,
344 reason: reason5, 331 reason: reason5,
345 predefinedReasons: predefinedReasons5, 332 predefinedReasons: predefinedReasons5,
346 startAt: 1, 333 startAt: 1,
347 endAt: 5 334 endAt: 5
348 })).body.abuse 335 })
349 336
350 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 337 const body = await commands[0].getAdminList()
351 338
352 { 339 {
353 const abuse = (res.body.data as AdminAbuse[]).find(a => a.id === createdAbuse.id) 340 const abuse = body.data.find(a => a.id === createRes.abuse.id)
354 expect(abuse.reason).to.equals(reason5) 341 expect(abuse.reason).to.equals(reason5)
355 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported") 342 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") 343 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
@@ -361,37 +348,30 @@ describe('Test abuses', function () {
361 it('Should delete the video abuse', async function () { 348 it('Should delete the video abuse', async function () {
362 this.timeout(10000) 349 this.timeout(10000)
363 350
364 await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) 351 await commands[1].delete({ abuseId: abuseServer2.id })
365 352
366 await waitJobs(servers) 353 await waitJobs(servers)
367 354
368 { 355 {
369 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 356 const body = await commands[1].getAdminList()
370 expect(res.body.total).to.equal(1) 357 expect(body.total).to.equal(1)
371 expect(res.body.data.length).to.equal(1) 358 expect(body.data.length).to.equal(1)
372 expect(res.body.data[0].id).to.not.equal(abuseServer2.id) 359 expect(body.data[0].id).to.not.equal(abuseServer2.id)
373 } 360 }
374 361
375 { 362 {
376 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 363 const body = await commands[0].getAdminList()
377 expect(res.body.total).to.equal(6) 364 expect(body.total).to.equal(6)
378 } 365 }
379 }) 366 })
380 367
381 it('Should list and filter video abuses', async function () { 368 it('Should list and filter video abuses', async function () {
382 this.timeout(10000) 369 this.timeout(10000)
383 370
384 async function list (query: Omit<Parameters<typeof getAdminAbusesList>[0], 'url' | 'token'>) { 371 async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) {
385 const options = { 372 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 373
392 const res = await getAdminAbusesList(options) 374 return body.data
393
394 return res.body.data as AdminAbuse[]
395 } 375 }
396 376
397 expect(await list({ id: 56 })).to.have.lengthOf(0) 377 expect(await list({ id: 56 })).to.have.lengthOf(0)
@@ -452,7 +432,7 @@ describe('Test abuses', function () {
452 const comment = await getComment(servers[0].url, servers[0].video.id) 432 const comment = await getComment(servers[0].url, servers[0].video.id)
453 433
454 const reason = 'it is a bad comment' 434 const reason = 'it is a bad comment'
455 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason }) 435 await commands[0].report({ commentId: comment.id, reason })
456 436
457 await waitJobs(servers) 437 await waitJobs(servers)
458 }) 438 })
@@ -460,12 +440,12 @@ describe('Test abuses', function () {
460 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () { 440 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
461 { 441 {
462 const comment = await getComment(servers[0].url, servers[0].video.id) 442 const comment = await getComment(servers[0].url, servers[0].video.id)
463 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 443 const body = await commands[0].getAdminList({ filter: 'comment' })
464 444
465 expect(res.body.total).to.equal(1) 445 expect(body.total).to.equal(1)
466 expect(res.body.data).to.have.lengthOf(1) 446 expect(body.data).to.have.lengthOf(1)
467 447
468 const abuse: AdminAbuse = res.body.data[0] 448 const abuse = body.data[0]
469 expect(abuse.reason).to.equal('it is a bad comment') 449 expect(abuse.reason).to.equal('it is a bad comment')
470 450
471 expect(abuse.reporterAccount.name).to.equal('root') 451 expect(abuse.reporterAccount.name).to.equal('root')
@@ -485,9 +465,9 @@ describe('Test abuses', function () {
485 } 465 }
486 466
487 { 467 {
488 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 468 const body = await commands[1].getAdminList({ filter: 'comment' })
489 expect(res.body.total).to.equal(0) 469 expect(body.total).to.equal(0)
490 expect(res.body.data.length).to.equal(0) 470 expect(body.data.length).to.equal(0)
491 } 471 }
492 }) 472 })
493 473
@@ -497,7 +477,7 @@ describe('Test abuses', function () {
497 const comment = await getComment(servers[0].url, servers[1].video.uuid) 477 const comment = await getComment(servers[0].url, servers[1].video.uuid)
498 478
499 const reason = 'it is a really bad comment' 479 const reason = 'it is a really bad comment'
500 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason }) 480 await commands[0].report({ commentId: comment.id, reason })
501 481
502 await waitJobs(servers) 482 await waitJobs(servers)
503 }) 483 })
@@ -505,54 +485,58 @@ describe('Test abuses', function () {
505 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { 485 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) 486 const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
507 487
508 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 488 {
509 expect(res1.body.total).to.equal(2) 489 const body = await commands[0].getAdminList({ filter: 'comment' })
510 expect(res1.body.data.length).to.equal(2) 490 expect(body.total).to.equal(2)
491 expect(body.data.length).to.equal(2)
511 492
512 const abuse: AdminAbuse = res1.body.data[0] 493 const abuse = body.data[0]
513 expect(abuse.reason).to.equal('it is a bad comment') 494 expect(abuse.reason).to.equal('it is a bad comment')
514 expect(abuse.countReportsForReporter).to.equal(6) 495 expect(abuse.countReportsForReporter).to.equal(6)
515 expect(abuse.countReportsForReportee).to.equal(5) 496 expect(abuse.countReportsForReportee).to.equal(5)
516 497
517 const abuse2: AdminAbuse = res1.body.data[1] 498 const abuse2 = body.data[1]
518 499
519 expect(abuse2.reason).to.equal('it is a really bad comment') 500 expect(abuse2.reason).to.equal('it is a really bad comment')
520 501
521 expect(abuse2.reporterAccount.name).to.equal('root') 502 expect(abuse2.reporterAccount.name).to.equal('root')
522 expect(abuse2.reporterAccount.host).to.equal(servers[0].host) 503 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
523 504
524 expect(abuse2.video).to.be.null 505 expect(abuse2.video).to.be.null
525 506
526 expect(abuse2.comment.deleted).to.be.false 507 expect(abuse2.comment.deleted).to.be.false
527 expect(abuse2.comment.id).to.equal(commentServer2.id) 508 expect(abuse2.comment.id).to.equal(commentServer2.id)
528 expect(abuse2.comment.text).to.equal(commentServer2.text) 509 expect(abuse2.comment.text).to.equal(commentServer2.text)
529 expect(abuse2.comment.video.name).to.equal('server 2') 510 expect(abuse2.comment.video.name).to.equal('server 2')
530 expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid) 511 expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid)
531 512
532 expect(abuse2.state.id).to.equal(AbuseState.PENDING) 513 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
533 expect(abuse2.state.label).to.equal('Pending') 514 expect(abuse2.state.label).to.equal('Pending')
534 515
535 expect(abuse2.moderationComment).to.be.null 516 expect(abuse2.moderationComment).to.be.null
536 517
537 expect(abuse2.countReportsForReporter).to.equal(6) 518 expect(abuse2.countReportsForReporter).to.equal(6)
538 expect(abuse2.countReportsForReportee).to.equal(2) 519 expect(abuse2.countReportsForReportee).to.equal(2)
520 }
539 521
540 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 522 {
541 expect(res2.body.total).to.equal(1) 523 const body = await commands[1].getAdminList({ filter: 'comment' })
542 expect(res2.body.data.length).to.equal(1) 524 expect(body.total).to.equal(1)
525 expect(body.data.length).to.equal(1)
543 526
544 abuseServer2 = res2.body.data[0] 527 abuseServer2 = body.data[0]
545 expect(abuseServer2.reason).to.equal('it is a really bad comment') 528 expect(abuseServer2.reason).to.equal('it is a really bad comment')
546 expect(abuseServer2.reporterAccount.name).to.equal('root') 529 expect(abuseServer2.reporterAccount.name).to.equal('root')
547 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) 530 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
548 531
549 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) 532 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
550 expect(abuseServer2.state.label).to.equal('Pending') 533 expect(abuseServer2.state.label).to.equal('Pending')
551 534
552 expect(abuseServer2.moderationComment).to.be.null 535 expect(abuseServer2.moderationComment).to.be.null
553 536
554 expect(abuseServer2.countReportsForReporter).to.equal(1) 537 expect(abuseServer2.countReportsForReporter).to.equal(1)
555 expect(abuseServer2.countReportsForReportee).to.equal(1) 538 expect(abuseServer2.countReportsForReportee).to.equal(1)
539 }
556 }) 540 })
557 541
558 it('Should keep the comment abuse when deleting the comment', async function () { 542 it('Should keep the comment abuse when deleting the comment', async function () {
@@ -564,11 +548,11 @@ describe('Test abuses', function () {
564 548
565 await waitJobs(servers) 549 await waitJobs(servers)
566 550
567 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 551 const body = await commands[0].getAdminList({ filter: 'comment' })
568 expect(res.body.total).to.equal(2) 552 expect(body.total).to.equal(2)
569 expect(res.body.data).to.have.lengthOf(2) 553 expect(body.data).to.have.lengthOf(2)
570 554
571 const abuse = (res.body.data as AdminAbuse[]).find(a => a.comment?.id === commentServer2.id) 555 const abuse = body.data.find(a => a.comment?.id === commentServer2.id)
572 expect(abuse).to.not.be.undefined 556 expect(abuse).to.not.be.undefined
573 557
574 expect(abuse.comment.text).to.be.empty 558 expect(abuse.comment.text).to.be.empty
@@ -579,53 +563,43 @@ describe('Test abuses', function () {
579 it('Should delete the comment abuse', async function () { 563 it('Should delete the comment abuse', async function () {
580 this.timeout(10000) 564 this.timeout(10000)
581 565
582 await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) 566 await commands[1].delete({ abuseId: abuseServer2.id })
583 567
584 await waitJobs(servers) 568 await waitJobs(servers)
585 569
586 { 570 {
587 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 571 const body = await commands[1].getAdminList({ filter: 'comment' })
588 expect(res.body.total).to.equal(0) 572 expect(body.total).to.equal(0)
589 expect(res.body.data.length).to.equal(0) 573 expect(body.data.length).to.equal(0)
590 } 574 }
591 575
592 { 576 {
593 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 577 const body = await commands[0].getAdminList({ filter: 'comment' })
594 expect(res.body.total).to.equal(2) 578 expect(body.total).to.equal(2)
595 } 579 }
596 }) 580 })
597 581
598 it('Should list and filter video abuses', async function () { 582 it('Should list and filter video abuses', async function () {
599 { 583 {
600 const res = await getAdminAbusesList({ 584 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' })
601 url: servers[0].url, 585 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 } 586 }
608 587
609 { 588 {
610 const res = await getAdminAbusesList({ 589 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' })
611 url: servers[0].url, 590 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 } 591 }
618 592
619 { 593 {
620 const baseParams = { url: servers[0].url, token: servers[0].accessToken, filter: 'comment' as AbuseFilter, start: 1, count: 1 } 594 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' })
621 595 expect(body.data).to.have.lengthOf(1)
622 const res1 = await getAdminAbusesList(immutableAssign(baseParams, { sort: 'createdAt' })) 596 expect(body.data[0].comment.text).to.be.empty
623 expect(res1.body.data).to.have.lengthOf(1) 597 }
624 expect(res1.body.data[0].comment.text).to.be.empty
625 598
626 const res2 = await getAdminAbusesList(immutableAssign(baseParams, { sort: '-createdAt' })) 599 {
627 expect(res2.body.data).to.have.lengthOf(1) 600 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') 601 expect(body.data).to.have.lengthOf(1)
602 expect(body.data[0].comment.text).to.equal('comment server 1')
629 } 603 }
630 }) 604 })
631 }) 605 })
@@ -655,19 +629,19 @@ describe('Test abuses', function () {
655 const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0]) 629 const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0])
656 630
657 const reason = 'it is a bad account' 631 const reason = 'it is a bad account'
658 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason }) 632 await commands[0].report({ accountId: account.id, reason })
659 633
660 await waitJobs(servers) 634 await waitJobs(servers)
661 }) 635 })
662 636
663 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () { 637 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
664 { 638 {
665 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) 639 const body = await commands[0].getAdminList({ filter: 'account' })
666 640
667 expect(res.body.total).to.equal(1) 641 expect(body.total).to.equal(1)
668 expect(res.body.data).to.have.lengthOf(1) 642 expect(body.data).to.have.lengthOf(1)
669 643
670 const abuse: AdminAbuse = res.body.data[0] 644 const abuse = body.data[0]
671 expect(abuse.reason).to.equal('it is a bad account') 645 expect(abuse.reason).to.equal('it is a bad account')
672 646
673 expect(abuse.reporterAccount.name).to.equal('root') 647 expect(abuse.reporterAccount.name).to.equal('root')
@@ -681,9 +655,9 @@ describe('Test abuses', function () {
681 } 655 }
682 656
683 { 657 {
684 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 658 const body = await commands[1].getAdminList({ filter: 'comment' })
685 expect(res.body.total).to.equal(0) 659 expect(body.total).to.equal(0)
686 expect(res.body.data.length).to.equal(0) 660 expect(body.data.length).to.equal(0)
687 } 661 }
688 }) 662 })
689 663
@@ -693,48 +667,52 @@ describe('Test abuses', function () {
693 const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1]) 667 const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1])
694 668
695 const reason = 'it is a really bad account' 669 const reason = 'it is a really bad account'
696 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason }) 670 await commands[0].report({ accountId: account.id, reason })
697 671
698 await waitJobs(servers) 672 await waitJobs(servers)
699 }) 673 })
700 674
701 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { 675 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' }) 676 {
703 expect(res1.body.total).to.equal(2) 677 const body = await commands[0].getAdminList({ filter: 'account' })
704 expect(res1.body.data.length).to.equal(2) 678 expect(body.total).to.equal(2)
679 expect(body.data.length).to.equal(2)
705 680
706 const abuse: AdminAbuse = res1.body.data[0] 681 const abuse: AdminAbuse = body.data[0]
707 expect(abuse.reason).to.equal('it is a bad account') 682 expect(abuse.reason).to.equal('it is a bad account')
708 683
709 const abuse2: AdminAbuse = res1.body.data[1] 684 const abuse2: AdminAbuse = body.data[1]
710 expect(abuse2.reason).to.equal('it is a really bad account') 685 expect(abuse2.reason).to.equal('it is a really bad account')
711 686
712 expect(abuse2.reporterAccount.name).to.equal('root') 687 expect(abuse2.reporterAccount.name).to.equal('root')
713 expect(abuse2.reporterAccount.host).to.equal(servers[0].host) 688 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
714 689
715 expect(abuse2.video).to.be.null 690 expect(abuse2.video).to.be.null
716 expect(abuse2.comment).to.be.null 691 expect(abuse2.comment).to.be.null
717 692
718 expect(abuse2.state.id).to.equal(AbuseState.PENDING) 693 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
719 expect(abuse2.state.label).to.equal('Pending') 694 expect(abuse2.state.label).to.equal('Pending')
720 695
721 expect(abuse2.moderationComment).to.be.null 696 expect(abuse2.moderationComment).to.be.null
697 }
722 698
723 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) 699 {
724 expect(res2.body.total).to.equal(1) 700 const body = await commands[1].getAdminList({ filter: 'account' })
725 expect(res2.body.data.length).to.equal(1) 701 expect(body.total).to.equal(1)
702 expect(body.data.length).to.equal(1)
726 703
727 abuseServer2 = res2.body.data[0] 704 abuseServer2 = body.data[0]
728 705
729 expect(abuseServer2.reason).to.equal('it is a really bad account') 706 expect(abuseServer2.reason).to.equal('it is a really bad account')
730 707
731 expect(abuseServer2.reporterAccount.name).to.equal('root') 708 expect(abuseServer2.reporterAccount.name).to.equal('root')
732 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) 709 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
733 710
734 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) 711 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
735 expect(abuseServer2.state.label).to.equal('Pending') 712 expect(abuseServer2.state.label).to.equal('Pending')
736 713
737 expect(abuseServer2.moderationComment).to.be.null 714 expect(abuseServer2.moderationComment).to.be.null
715 }
738 }) 716 })
739 717
740 it('Should keep the account abuse when deleting the account', async function () { 718 it('Should keep the account abuse when deleting the account', async function () {
@@ -745,32 +723,32 @@ describe('Test abuses', function () {
745 723
746 await waitJobs(servers) 724 await waitJobs(servers)
747 725
748 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) 726 const body = await commands[0].getAdminList({ filter: 'account' })
749 expect(res.body.total).to.equal(2) 727 expect(body.total).to.equal(2)
750 expect(res.body.data).to.have.lengthOf(2) 728 expect(body.data).to.have.lengthOf(2)
751 729
752 const abuse = (res.body.data as AdminAbuse[]).find(a => a.reason === 'it is a really bad account') 730 const abuse = body.data.find(a => a.reason === 'it is a really bad account')
753 expect(abuse).to.not.be.undefined 731 expect(abuse).to.not.be.undefined
754 }) 732 })
755 733
756 it('Should delete the account abuse', async function () { 734 it('Should delete the account abuse', async function () {
757 this.timeout(10000) 735 this.timeout(10000)
758 736
759 await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) 737 await commands[1].delete({ abuseId: abuseServer2.id })
760 738
761 await waitJobs(servers) 739 await waitJobs(servers)
762 740
763 { 741 {
764 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) 742 const body = await commands[1].getAdminList({ filter: 'account' })
765 expect(res.body.total).to.equal(0) 743 expect(body.total).to.equal(0)
766 expect(res.body.data.length).to.equal(0) 744 expect(body.data.length).to.equal(0)
767 } 745 }
768 746
769 { 747 {
770 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) 748 const body = await commands[0].getAdminList({ filter: 'account' })
771 expect(res.body.total).to.equal(2) 749 expect(body.total).to.equal(2)
772 750
773 abuseServer1 = res.body.data[0] 751 abuseServer1 = body.data[0]
774 } 752 }
775 }) 753 })
776 }) 754 })
@@ -778,20 +756,18 @@ describe('Test abuses', function () {
778 describe('Common actions on abuses', function () { 756 describe('Common actions on abuses', function () {
779 757
780 it('Should update the state of an abuse', async function () { 758 it('Should update the state of an abuse', async function () {
781 const body = { state: AbuseState.REJECTED } 759 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } })
782 await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body)
783 760
784 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) 761 const body = await commands[0].getAdminList({ id: abuseServer1.id })
785 expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED) 762 expect(body.data[0].state.id).to.equal(AbuseState.REJECTED)
786 }) 763 })
787 764
788 it('Should add a moderation comment', async function () { 765 it('Should add a moderation comment', async function () {
789 const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' } 766 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 767
792 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) 768 const body = await commands[0].getAdminList({ id: abuseServer1.id })
793 expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED) 769 expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
794 expect(res.body.data[0].moderationComment).to.equal('It is valid') 770 expect(body.data[0].moderationComment).to.equal('Valid')
795 }) 771 })
796 }) 772 })
797 773
@@ -802,18 +778,18 @@ describe('Test abuses', function () {
802 before(async function () { 778 before(async function () {
803 userAccessToken = await generateUserAccessToken(servers[0], 'user_42') 779 userAccessToken = await generateUserAccessToken(servers[0], 'user_42')
804 780
805 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) 781 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
806 782
807 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) 783 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
808 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId, reason: 'user reason 2' }) 784 await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
809 }) 785 })
810 786
811 it('Should correctly list my abuses', async function () { 787 it('Should correctly list my abuses', async function () {
812 { 788 {
813 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 5, sort: 'createdAt' }) 789 const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
814 expect(res.body.total).to.equal(2) 790 expect(body.total).to.equal(2)
815 791
816 const abuses: UserAbuse[] = res.body.data 792 const abuses = body.data
817 expect(abuses[0].reason).to.equal('user reason 1') 793 expect(abuses[0].reason).to.equal('user reason 1')
818 expect(abuses[1].reason).to.equal('user reason 2') 794 expect(abuses[1].reason).to.equal('user reason 2')
819 795
@@ -821,95 +797,77 @@ describe('Test abuses', function () {
821 } 797 }
822 798
823 { 799 {
824 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: 'createdAt' }) 800 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
825 expect(res.body.total).to.equal(2) 801 expect(body.total).to.equal(2)
826 802
827 const abuses: UserAbuse[] = res.body.data 803 const abuses: UserAbuse[] = body.data
828 expect(abuses[0].reason).to.equal('user reason 2') 804 expect(abuses[0].reason).to.equal('user reason 2')
829 } 805 }
830 806
831 { 807 {
832 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: '-createdAt' }) 808 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
833 expect(res.body.total).to.equal(2) 809 expect(body.total).to.equal(2)
834 810
835 const abuses: UserAbuse[] = res.body.data 811 const abuses: UserAbuse[] = body.data
836 expect(abuses[0].reason).to.equal('user reason 1') 812 expect(abuses[0].reason).to.equal('user reason 1')
837 } 813 }
838 }) 814 })
839 815
840 it('Should correctly filter my abuses by id', async function () { 816 it('Should correctly filter my abuses by id', async function () {
841 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, id: abuseId1 }) 817 const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 })
842 818 expect(body.total).to.equal(1)
843 expect(res.body.total).to.equal(1)
844 819
845 const abuses: UserAbuse[] = res.body.data 820 const abuses: UserAbuse[] = body.data
846 expect(abuses[0].reason).to.equal('user reason 1') 821 expect(abuses[0].reason).to.equal('user reason 1')
847 }) 822 })
848 823
849 it('Should correctly filter my abuses by search', async function () { 824 it('Should correctly filter my abuses by search', async function () {
850 const res = await getUserAbusesList({ 825 const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' })
851 url: servers[0].url, 826 expect(body.total).to.equal(1)
852 token: userAccessToken,
853 search: 'server 2'
854 })
855
856 expect(res.body.total).to.equal(1)
857 827
858 const abuses: UserAbuse[] = res.body.data 828 const abuses: UserAbuse[] = body.data
859 expect(abuses[0].reason).to.equal('user reason 2') 829 expect(abuses[0].reason).to.equal('user reason 2')
860 }) 830 })
861 831
862 it('Should correctly filter my abuses by state', async function () { 832 it('Should correctly filter my abuses by state', async function () {
863 const body = { state: AbuseState.REJECTED } 833 await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } })
864 await updateAbuse(servers[0].url, servers[0].accessToken, abuseId1, body)
865
866 const res = await getUserAbusesList({
867 url: servers[0].url,
868 token: userAccessToken,
869 state: AbuseState.REJECTED
870 })
871 834
872 expect(res.body.total).to.equal(1) 835 const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED })
836 expect(body.total).to.equal(1)
873 837
874 const abuses: UserAbuse[] = res.body.data 838 const abuses: UserAbuse[] = body.data
875 expect(abuses[0].reason).to.equal('user reason 1') 839 expect(abuses[0].reason).to.equal('user reason 1')
876 }) 840 })
877 }) 841 })
878 842
879 describe('Abuse messages', async function () { 843 describe('Abuse messages', async function () {
880 let abuseId: number 844 let abuseId: number
881 let userAccessToken: string 845 let userToken: string
882 let abuseMessageUserId: number 846 let abuseMessageUserId: number
883 let abuseMessageModerationId: number 847 let abuseMessageModerationId: number
884 848
885 before(async function () { 849 before(async function () {
886 userAccessToken = await generateUserAccessToken(servers[0], 'user_43') 850 userToken = await generateUserAccessToken(servers[0], 'user_43')
887
888 const res = await reportAbuse({
889 url: servers[0].url,
890 token: userAccessToken,
891 videoId: servers[0].video.id,
892 reason: 'user 43 reason 1'
893 })
894 851
895 abuseId = res.body.abuse.id 852 const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' })
853 abuseId = body.abuse.id
896 }) 854 })
897 855
898 it('Should create some messages on the abuse', async function () { 856 it('Should create some messages on the abuse', async function () {
899 await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 1') 857 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' })
900 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 2') 858 await commands[0].addMessage({ abuseId, message: 'message 2' })
901 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 3') 859 await commands[0].addMessage({ abuseId, message: 'message 3' })
902 await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 4') 860 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' })
903 }) 861 })
904 862
905 it('Should have the correct messages count when listing abuses', async function () { 863 it('Should have the correct messages count when listing abuses', async function () {
906 const results = await Promise.all([ 864 const results = await Promise.all([
907 getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, start: 0, count: 50 }), 865 commands[0].getAdminList({ start: 0, count: 50 }),
908 getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 50 }) 866 commands[0].getUserList({ token: userToken, start: 0, count: 50 })
909 ]) 867 ])
910 868
911 for (const res of results) { 869 for (const body of results) {
912 const abuses: AdminAbuse[] = res.body.data 870 const abuses = body.data
913 const abuse = abuses.find(a => a.id === abuseId) 871 const abuse = abuses.find(a => a.id === abuseId)
914 expect(abuse.countMessages).to.equal(4) 872 expect(abuse.countMessages).to.equal(4)
915 } 873 }
@@ -917,14 +875,14 @@ describe('Test abuses', function () {
917 875
918 it('Should correctly list messages of this abuse', async function () { 876 it('Should correctly list messages of this abuse', async function () {
919 const results = await Promise.all([ 877 const results = await Promise.all([
920 listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId), 878 commands[0].listMessages({ abuseId }),
921 listAbuseMessages(servers[0].url, userAccessToken, abuseId) 879 commands[0].listMessages({ token: userToken, abuseId })
922 ]) 880 ])
923 881
924 for (const res of results) { 882 for (const body of results) {
925 expect(res.body.total).to.equal(4) 883 expect(body.total).to.equal(4)
926 884
927 const abuseMessages: AbuseMessage[] = res.body.data 885 const abuseMessages: AbuseMessage[] = body.data
928 886
929 expect(abuseMessages[0].message).to.equal('message 1') 887 expect(abuseMessages[0].message).to.equal('message 1')
930 expect(abuseMessages[0].byModerator).to.be.false 888 expect(abuseMessages[0].byModerator).to.be.false
@@ -948,19 +906,18 @@ describe('Test abuses', function () {
948 }) 906 })
949 907
950 it('Should delete messages', async function () { 908 it('Should delete messages', async function () {
951 await deleteAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, abuseMessageModerationId) 909 await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId })
952 await deleteAbuseMessage(servers[0].url, userAccessToken, abuseId, abuseMessageUserId) 910 await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId })
953 911
954 const results = await Promise.all([ 912 const results = await Promise.all([
955 listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId), 913 commands[0].listMessages({ abuseId }),
956 listAbuseMessages(servers[0].url, userAccessToken, abuseId) 914 commands[0].listMessages({ token: userToken, abuseId })
957 ]) 915 ])
958 916
959 for (const res of results) { 917 for (const body of results) {
960 expect(res.body.total).to.equal(2) 918 expect(body.total).to.equal(2)
961
962 const abuseMessages: AbuseMessage[] = res.body.data
963 919
920 const abuseMessages: AbuseMessage[] = body.data
964 expect(abuseMessages[0].message).to.equal('message 2') 921 expect(abuseMessages[0].message).to.equal('message 2')
965 expect(abuseMessages[1].message).to.equal('message 4') 922 expect(abuseMessages[1].message).to.equal('message 4')
966 } 923 }