aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/moderation/abuses.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-07-24 15:05:51 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-07-31 11:35:19 +0200
commitedbc9325462ddf4536775871ebc25e06f46612d1 (patch)
tree9671dd51303e75d48d4f4f9a1df7a1960e33780d /server/tests/api/moderation/abuses.ts
parent20516920d2b72c8a18bc24b9740f7176aa962da2 (diff)
downloadPeerTube-edbc9325462ddf4536775871ebc25e06f46612d1.tar.gz
PeerTube-edbc9325462ddf4536775871ebc25e06f46612d1.tar.zst
PeerTube-edbc9325462ddf4536775871ebc25e06f46612d1.zip
Add server API to abuse messages
Diffstat (limited to 'server/tests/api/moderation/abuses.ts')
-rw-r--r--server/tests/api/moderation/abuses.ts307
1 files changed, 247 insertions, 60 deletions
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts
index f186f7ea0..601125fdf 100644
--- a/server/tests/api/moderation/abuses.ts
+++ b/server/tests/api/moderation/abuses.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { Abuse, AbuseFilter, AbusePredefinedReasonsString, AbuseState, VideoComment, Account } from '@shared/models' 5import { AbuseFilter, AbusePredefinedReasonsString, AbuseState, Account, AdminAbuse, UserAbuse, VideoComment, AbuseMessage } from '@shared/models'
6import { 6import {
7 addVideoCommentThread, 7 addVideoCommentThread,
8 cleanupTests, 8 cleanupTests,
@@ -10,11 +10,15 @@ import {
10 deleteAbuse, 10 deleteAbuse,
11 deleteVideoComment, 11 deleteVideoComment,
12 flushAndRunMultipleServers, 12 flushAndRunMultipleServers,
13 getAbusesList, 13 generateUserAccessToken,
14 getAccount,
15 getAdminAbusesList,
16 getUserAbusesList,
14 getVideoCommentThreads, 17 getVideoCommentThreads,
15 getVideoIdFromUUID, 18 getVideoIdFromUUID,
16 getVideosList, 19 getVideosList,
17 immutableAssign, 20 immutableAssign,
21 removeUser,
18 removeVideo, 22 removeVideo,
19 reportAbuse, 23 reportAbuse,
20 ServerInfo, 24 ServerInfo,
@@ -23,9 +27,9 @@ import {
23 uploadVideo, 27 uploadVideo,
24 uploadVideoAndGetId, 28 uploadVideoAndGetId,
25 userLogin, 29 userLogin,
26 getAccount, 30 addAbuseMessage,
27 removeUser, 31 listAbuseMessages,
28 generateUserAccessToken 32 deleteAbuseMessage
29} from '../../../../shared/extra-utils/index' 33} from '../../../../shared/extra-utils/index'
30import { doubleFollow } from '../../../../shared/extra-utils/server/follows' 34import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
31import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 35import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
@@ -40,8 +44,8 @@ const expect = chai.expect
40 44
41describe('Test abuses', function () { 45describe('Test abuses', function () {
42 let servers: ServerInfo[] = [] 46 let servers: ServerInfo[] = []
43 let abuseServer1: Abuse 47 let abuseServer1: AdminAbuse
44 let abuseServer2: Abuse 48 let abuseServer2: AdminAbuse
45 49
46 before(async function () { 50 before(async function () {
47 this.timeout(50000) 51 this.timeout(50000)
@@ -87,7 +91,7 @@ describe('Test abuses', function () {
87 }) 91 })
88 92
89 it('Should not have abuses', async function () { 93 it('Should not have abuses', async function () {
90 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 94 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
91 95
92 expect(res.body.total).to.equal(0) 96 expect(res.body.total).to.equal(0)
93 expect(res.body.data).to.be.an('array') 97 expect(res.body.data).to.be.an('array')
@@ -105,13 +109,13 @@ describe('Test abuses', function () {
105 }) 109 })
106 110
107 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { 111 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
108 const res1 = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 112 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
109 113
110 expect(res1.body.total).to.equal(1) 114 expect(res1.body.total).to.equal(1)
111 expect(res1.body.data).to.be.an('array') 115 expect(res1.body.data).to.be.an('array')
112 expect(res1.body.data.length).to.equal(1) 116 expect(res1.body.data.length).to.equal(1)
113 117
114 const abuse: Abuse = res1.body.data[0] 118 const abuse: AdminAbuse = res1.body.data[0]
115 expect(abuse.reason).to.equal('my super bad reason') 119 expect(abuse.reason).to.equal('my super bad reason')
116 120
117 expect(abuse.reporterAccount.name).to.equal('root') 121 expect(abuse.reporterAccount.name).to.equal('root')
@@ -131,7 +135,7 @@ describe('Test abuses', function () {
131 expect(abuse.countReportsForReporter).to.equal(1) 135 expect(abuse.countReportsForReporter).to.equal(1)
132 expect(abuse.countReportsForReportee).to.equal(1) 136 expect(abuse.countReportsForReportee).to.equal(1)
133 137
134 const res2 = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 138 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken })
135 expect(res2.body.total).to.equal(0) 139 expect(res2.body.total).to.equal(0)
136 expect(res2.body.data).to.be.an('array') 140 expect(res2.body.data).to.be.an('array')
137 expect(res2.body.data.length).to.equal(0) 141 expect(res2.body.data.length).to.equal(0)
@@ -141,19 +145,20 @@ describe('Test abuses', function () {
141 this.timeout(10000) 145 this.timeout(10000)
142 146
143 const reason = 'my super bad reason 2' 147 const reason = 'my super bad reason 2'
144 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: servers[1].video.id, reason }) 148 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
149 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId, reason })
145 150
146 // We wait requests propagation 151 // We wait requests propagation
147 await waitJobs(servers) 152 await waitJobs(servers)
148 }) 153 })
149 154
150 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { 155 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
151 const res1 = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 156 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
152 157
153 expect(res1.body.total).to.equal(2) 158 expect(res1.body.total).to.equal(2)
154 expect(res1.body.data.length).to.equal(2) 159 expect(res1.body.data.length).to.equal(2)
155 160
156 const abuse1: Abuse = res1.body.data[0] 161 const abuse1: AdminAbuse = res1.body.data[0]
157 expect(abuse1.reason).to.equal('my super bad reason') 162 expect(abuse1.reason).to.equal('my super bad reason')
158 expect(abuse1.reporterAccount.name).to.equal('root') 163 expect(abuse1.reporterAccount.name).to.equal('root')
159 expect(abuse1.reporterAccount.host).to.equal(servers[0].host) 164 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
@@ -171,7 +176,7 @@ describe('Test abuses', function () {
171 expect(abuse1.state.label).to.equal('Pending') 176 expect(abuse1.state.label).to.equal('Pending')
172 expect(abuse1.moderationComment).to.be.null 177 expect(abuse1.moderationComment).to.be.null
173 178
174 const abuse2: Abuse = res1.body.data[1] 179 const abuse2: AdminAbuse = res1.body.data[1]
175 expect(abuse2.reason).to.equal('my super bad reason 2') 180 expect(abuse2.reason).to.equal('my super bad reason 2')
176 181
177 expect(abuse2.reporterAccount.name).to.equal('root') 182 expect(abuse2.reporterAccount.name).to.equal('root')
@@ -188,7 +193,7 @@ describe('Test abuses', function () {
188 expect(abuse2.state.label).to.equal('Pending') 193 expect(abuse2.state.label).to.equal('Pending')
189 expect(abuse2.moderationComment).to.be.null 194 expect(abuse2.moderationComment).to.be.null
190 195
191 const res2 = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 196 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken })
192 expect(res2.body.total).to.equal(1) 197 expect(res2.body.total).to.equal(1)
193 expect(res2.body.data.length).to.equal(1) 198 expect(res2.body.data.length).to.equal(1)
194 199
@@ -213,7 +218,7 @@ describe('Test abuses', function () {
213 await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'will mute this' }) 218 await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'will mute this' })
214 await waitJobs(servers) 219 await waitJobs(servers)
215 220
216 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 221 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
217 expect(res.body.total).to.equal(3) 222 expect(res.body.total).to.equal(3)
218 } 223 }
219 224
@@ -222,7 +227,7 @@ describe('Test abuses', function () {
222 { 227 {
223 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) 228 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
224 229
225 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 230 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
226 expect(res.body.total).to.equal(2) 231 expect(res.body.total).to.equal(2)
227 232
228 const abuse = res.body.data.find(a => a.reason === 'will mute this') 233 const abuse = res.body.data.find(a => a.reason === 'will mute this')
@@ -232,7 +237,7 @@ describe('Test abuses', function () {
232 { 237 {
233 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) 238 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
234 239
235 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 240 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
236 expect(res.body.total).to.equal(3) 241 expect(res.body.total).to.equal(3)
237 } 242 }
238 }) 243 })
@@ -243,7 +248,7 @@ describe('Test abuses', function () {
243 { 248 {
244 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) 249 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)
245 250
246 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 251 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
247 expect(res.body.total).to.equal(2) 252 expect(res.body.total).to.equal(2)
248 253
249 const abuse = res.body.data.find(a => a.reason === 'will mute this') 254 const abuse = res.body.data.find(a => a.reason === 'will mute this')
@@ -253,7 +258,7 @@ describe('Test abuses', function () {
253 { 258 {
254 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) 259 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock)
255 260
256 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 261 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
257 expect(res.body.total).to.equal(3) 262 expect(res.body.total).to.equal(3)
258 } 263 }
259 }) 264 })
@@ -265,11 +270,11 @@ describe('Test abuses', function () {
265 270
266 await waitJobs(servers) 271 await waitJobs(servers)
267 272
268 const res = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 273 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken })
269 expect(res.body.total).to.equal(2, "wrong number of videos returned") 274 expect(res.body.total).to.equal(2, "wrong number of videos returned")
270 expect(res.body.data).to.have.lengthOf(2, "wrong number of videos returned") 275 expect(res.body.data).to.have.lengthOf(2, "wrong number of videos returned")
271 276
272 const abuse: Abuse = res.body.data[0] 277 const abuse: AdminAbuse = res.body.data[0]
273 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video") 278 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video")
274 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id") 279 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
275 expect(abuse.video.channel).to.exist 280 expect(abuse.video.channel).to.exist
@@ -303,8 +308,8 @@ describe('Test abuses', function () {
303 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: reason4 }) 308 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: reason4 })
304 309
305 { 310 {
306 const res2 = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 311 const res2 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
307 const abuses = res2.body.data as Abuse[] 312 const abuses = res2.body.data as AdminAbuse[]
308 313
309 const abuseVideo3 = res2.body.data.find(a => a.video.id === video3.id) 314 const abuseVideo3 = res2.body.data.find(a => a.video.id === video3.id)
310 expect(abuseVideo3).to.not.be.undefined 315 expect(abuseVideo3).to.not.be.undefined
@@ -333,10 +338,10 @@ describe('Test abuses', function () {
333 endAt: 5 338 endAt: 5
334 })).body.abuse 339 })).body.abuse
335 340
336 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 341 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
337 342
338 { 343 {
339 const abuse = (res.body.data as Abuse[]).find(a => a.id === createdAbuse.id) 344 const abuse = (res.body.data as AdminAbuse[]).find(a => a.id === createdAbuse.id)
340 expect(abuse.reason).to.equals(reason5) 345 expect(abuse.reason).to.equals(reason5)
341 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported") 346 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported")
342 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported") 347 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
@@ -352,14 +357,14 @@ describe('Test abuses', function () {
352 await waitJobs(servers) 357 await waitJobs(servers)
353 358
354 { 359 {
355 const res = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken }) 360 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken })
356 expect(res.body.total).to.equal(1) 361 expect(res.body.total).to.equal(1)
357 expect(res.body.data.length).to.equal(1) 362 expect(res.body.data.length).to.equal(1)
358 expect(res.body.data[0].id).to.not.equal(abuseServer2.id) 363 expect(res.body.data[0].id).to.not.equal(abuseServer2.id)
359 } 364 }
360 365
361 { 366 {
362 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) 367 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
363 expect(res.body.total).to.equal(6) 368 expect(res.body.total).to.equal(6)
364 } 369 }
365 }) 370 })
@@ -367,7 +372,7 @@ describe('Test abuses', function () {
367 it('Should list and filter video abuses', async function () { 372 it('Should list and filter video abuses', async function () {
368 this.timeout(10000) 373 this.timeout(10000)
369 374
370 async function list (query: Omit<Parameters<typeof getAbusesList>[0], 'url' | 'token'>) { 375 async function list (query: Omit<Parameters<typeof getAdminAbusesList>[0], 'url' | 'token'>) {
371 const options = { 376 const options = {
372 url: servers[0].url, 377 url: servers[0].url,
373 token: servers[0].accessToken 378 token: servers[0].accessToken
@@ -375,9 +380,9 @@ describe('Test abuses', function () {
375 380
376 Object.assign(options, query) 381 Object.assign(options, query)
377 382
378 const res = await getAbusesList(options) 383 const res = await getAdminAbusesList(options)
379 384
380 return res.body.data as Abuse[] 385 return res.body.data as AdminAbuse[]
381 } 386 }
382 387
383 expect(await list({ id: 56 })).to.have.lengthOf(0) 388 expect(await list({ id: 56 })).to.have.lengthOf(0)
@@ -446,12 +451,12 @@ describe('Test abuses', function () {
446 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () { 451 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
447 { 452 {
448 const comment = await getComment(servers[0].url, servers[0].video.id) 453 const comment = await getComment(servers[0].url, servers[0].video.id)
449 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 454 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' })
450 455
451 expect(res.body.total).to.equal(1) 456 expect(res.body.total).to.equal(1)
452 expect(res.body.data).to.have.lengthOf(1) 457 expect(res.body.data).to.have.lengthOf(1)
453 458
454 const abuse: Abuse = res.body.data[0] 459 const abuse: AdminAbuse = res.body.data[0]
455 expect(abuse.reason).to.equal('it is a bad comment') 460 expect(abuse.reason).to.equal('it is a bad comment')
456 461
457 expect(abuse.reporterAccount.name).to.equal('root') 462 expect(abuse.reporterAccount.name).to.equal('root')
@@ -471,7 +476,7 @@ describe('Test abuses', function () {
471 } 476 }
472 477
473 { 478 {
474 const res = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 479 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' })
475 expect(res.body.total).to.equal(0) 480 expect(res.body.total).to.equal(0)
476 expect(res.body.data.length).to.equal(0) 481 expect(res.body.data.length).to.equal(0)
477 } 482 }
@@ -491,16 +496,16 @@ describe('Test abuses', function () {
491 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { 496 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
492 const commentServer2 = await getComment(servers[0].url, servers[1].video.id) 497 const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
493 498
494 const res1 = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 499 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' })
495 expect(res1.body.total).to.equal(2) 500 expect(res1.body.total).to.equal(2)
496 expect(res1.body.data.length).to.equal(2) 501 expect(res1.body.data.length).to.equal(2)
497 502
498 const abuse: Abuse = res1.body.data[0] 503 const abuse: AdminAbuse = res1.body.data[0]
499 expect(abuse.reason).to.equal('it is a bad comment') 504 expect(abuse.reason).to.equal('it is a bad comment')
500 expect(abuse.countReportsForReporter).to.equal(6) 505 expect(abuse.countReportsForReporter).to.equal(6)
501 expect(abuse.countReportsForReportee).to.equal(5) 506 expect(abuse.countReportsForReportee).to.equal(5)
502 507
503 const abuse2: Abuse = res1.body.data[1] 508 const abuse2: AdminAbuse = res1.body.data[1]
504 509
505 expect(abuse2.reason).to.equal('it is a really bad comment') 510 expect(abuse2.reason).to.equal('it is a really bad comment')
506 511
@@ -523,7 +528,7 @@ describe('Test abuses', function () {
523 expect(abuse2.countReportsForReporter).to.equal(6) 528 expect(abuse2.countReportsForReporter).to.equal(6)
524 expect(abuse2.countReportsForReportee).to.equal(2) 529 expect(abuse2.countReportsForReportee).to.equal(2)
525 530
526 const res2 = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 531 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' })
527 expect(res2.body.total).to.equal(1) 532 expect(res2.body.total).to.equal(1)
528 expect(res2.body.data.length).to.equal(1) 533 expect(res2.body.data.length).to.equal(1)
529 534
@@ -550,11 +555,11 @@ describe('Test abuses', function () {
550 555
551 await waitJobs(servers) 556 await waitJobs(servers)
552 557
553 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 558 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' })
554 expect(res.body.total).to.equal(2) 559 expect(res.body.total).to.equal(2)
555 expect(res.body.data).to.have.lengthOf(2) 560 expect(res.body.data).to.have.lengthOf(2)
556 561
557 const abuse = (res.body.data as Abuse[]).find(a => a.comment?.id === commentServer2.id) 562 const abuse = (res.body.data as AdminAbuse[]).find(a => a.comment?.id === commentServer2.id)
558 expect(abuse).to.not.be.undefined 563 expect(abuse).to.not.be.undefined
559 564
560 expect(abuse.comment.text).to.be.empty 565 expect(abuse.comment.text).to.be.empty
@@ -570,36 +575,46 @@ describe('Test abuses', function () {
570 await waitJobs(servers) 575 await waitJobs(servers)
571 576
572 { 577 {
573 const res = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 578 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' })
574 expect(res.body.total).to.equal(0) 579 expect(res.body.total).to.equal(0)
575 expect(res.body.data.length).to.equal(0) 580 expect(res.body.data.length).to.equal(0)
576 } 581 }
577 582
578 { 583 {
579 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) 584 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' })
580 expect(res.body.total).to.equal(2) 585 expect(res.body.total).to.equal(2)
581 } 586 }
582 }) 587 })
583 588
584 it('Should list and filter video abuses', async function () { 589 it('Should list and filter video abuses', async function () {
585 { 590 {
586 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment', searchReportee: 'foo' }) 591 const res = await getAdminAbusesList({
592 url: servers[0].url,
593 token: servers[0].accessToken,
594 filter: 'comment',
595 searchReportee: 'foo'
596 })
587 expect(res.body.total).to.equal(0) 597 expect(res.body.total).to.equal(0)
588 } 598 }
589 599
590 { 600 {
591 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment', searchReportee: 'ot' }) 601 const res = await getAdminAbusesList({
602 url: servers[0].url,
603 token: servers[0].accessToken,
604 filter: 'comment',
605 searchReportee: 'ot'
606 })
592 expect(res.body.total).to.equal(2) 607 expect(res.body.total).to.equal(2)
593 } 608 }
594 609
595 { 610 {
596 const baseParams = { url: servers[0].url, token: servers[0].accessToken, filter: 'comment' as AbuseFilter, start: 1, count: 1 } 611 const baseParams = { url: servers[0].url, token: servers[0].accessToken, filter: 'comment' as AbuseFilter, start: 1, count: 1 }
597 612
598 const res1 = await getAbusesList(immutableAssign(baseParams, { sort: 'createdAt' })) 613 const res1 = await getAdminAbusesList(immutableAssign(baseParams, { sort: 'createdAt' }))
599 expect(res1.body.data).to.have.lengthOf(1) 614 expect(res1.body.data).to.have.lengthOf(1)
600 expect(res1.body.data[0].comment.text).to.be.empty 615 expect(res1.body.data[0].comment.text).to.be.empty
601 616
602 const res2 = await getAbusesList(immutableAssign(baseParams, { sort: '-createdAt' })) 617 const res2 = await getAdminAbusesList(immutableAssign(baseParams, { sort: '-createdAt' }))
603 expect(res2.body.data).to.have.lengthOf(1) 618 expect(res2.body.data).to.have.lengthOf(1)
604 expect(res2.body.data[0].comment.text).to.equal('comment server 1') 619 expect(res2.body.data[0].comment.text).to.equal('comment server 1')
605 } 620 }
@@ -638,12 +653,12 @@ describe('Test abuses', function () {
638 653
639 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () { 654 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
640 { 655 {
641 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) 656 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' })
642 657
643 expect(res.body.total).to.equal(1) 658 expect(res.body.total).to.equal(1)
644 expect(res.body.data).to.have.lengthOf(1) 659 expect(res.body.data).to.have.lengthOf(1)
645 660
646 const abuse: Abuse = res.body.data[0] 661 const abuse: AdminAbuse = res.body.data[0]
647 expect(abuse.reason).to.equal('it is a bad account') 662 expect(abuse.reason).to.equal('it is a bad account')
648 663
649 expect(abuse.reporterAccount.name).to.equal('root') 664 expect(abuse.reporterAccount.name).to.equal('root')
@@ -657,7 +672,7 @@ describe('Test abuses', function () {
657 } 672 }
658 673
659 { 674 {
660 const res = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) 675 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' })
661 expect(res.body.total).to.equal(0) 676 expect(res.body.total).to.equal(0)
662 expect(res.body.data.length).to.equal(0) 677 expect(res.body.data.length).to.equal(0)
663 } 678 }
@@ -675,14 +690,14 @@ describe('Test abuses', function () {
675 }) 690 })
676 691
677 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { 692 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
678 const res1 = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) 693 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' })
679 expect(res1.body.total).to.equal(2) 694 expect(res1.body.total).to.equal(2)
680 expect(res1.body.data.length).to.equal(2) 695 expect(res1.body.data.length).to.equal(2)
681 696
682 const abuse: Abuse = res1.body.data[0] 697 const abuse: AdminAbuse = res1.body.data[0]
683 expect(abuse.reason).to.equal('it is a bad account') 698 expect(abuse.reason).to.equal('it is a bad account')
684 699
685 const abuse2: Abuse = res1.body.data[1] 700 const abuse2: AdminAbuse = res1.body.data[1]
686 expect(abuse2.reason).to.equal('it is a really bad account') 701 expect(abuse2.reason).to.equal('it is a really bad account')
687 702
688 expect(abuse2.reporterAccount.name).to.equal('root') 703 expect(abuse2.reporterAccount.name).to.equal('root')
@@ -696,7 +711,7 @@ describe('Test abuses', function () {
696 711
697 expect(abuse2.moderationComment).to.be.null 712 expect(abuse2.moderationComment).to.be.null
698 713
699 const res2 = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) 714 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' })
700 expect(res2.body.total).to.equal(1) 715 expect(res2.body.total).to.equal(1)
701 expect(res2.body.data.length).to.equal(1) 716 expect(res2.body.data.length).to.equal(1)
702 717
@@ -721,11 +736,11 @@ describe('Test abuses', function () {
721 736
722 await waitJobs(servers) 737 await waitJobs(servers)
723 738
724 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) 739 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' })
725 expect(res.body.total).to.equal(2) 740 expect(res.body.total).to.equal(2)
726 expect(res.body.data).to.have.lengthOf(2) 741 expect(res.body.data).to.have.lengthOf(2)
727 742
728 const abuse = (res.body.data as Abuse[]).find(a => a.reason === 'it is a really bad account') 743 const abuse = (res.body.data as AdminAbuse[]).find(a => a.reason === 'it is a really bad account')
729 expect(abuse).to.not.be.undefined 744 expect(abuse).to.not.be.undefined
730 }) 745 })
731 746
@@ -737,13 +752,13 @@ describe('Test abuses', function () {
737 await waitJobs(servers) 752 await waitJobs(servers)
738 753
739 { 754 {
740 const res = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) 755 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' })
741 expect(res.body.total).to.equal(0) 756 expect(res.body.total).to.equal(0)
742 expect(res.body.data.length).to.equal(0) 757 expect(res.body.data.length).to.equal(0)
743 } 758 }
744 759
745 { 760 {
746 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) 761 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' })
747 expect(res.body.total).to.equal(2) 762 expect(res.body.total).to.equal(2)
748 763
749 abuseServer1 = res.body.data[0] 764 abuseServer1 = res.body.data[0]
@@ -757,7 +772,7 @@ describe('Test abuses', function () {
757 const body = { state: AbuseState.REJECTED } 772 const body = { state: AbuseState.REJECTED }
758 await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body) 773 await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body)
759 774
760 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) 775 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id })
761 expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED) 776 expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED)
762 }) 777 })
763 778
@@ -765,12 +780,184 @@ describe('Test abuses', function () {
765 const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' } 780 const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' }
766 await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body) 781 await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body)
767 782
768 const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) 783 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id })
769 expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED) 784 expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
770 expect(res.body.data[0].moderationComment).to.equal('It is valid') 785 expect(res.body.data[0].moderationComment).to.equal('It is valid')
771 }) 786 })
772 }) 787 })
773 788
789 describe('My abuses', async function () {
790 let abuseId1: number
791 let userAccessToken: string
792
793 before(async function () {
794 userAccessToken = await generateUserAccessToken(servers[0], 'user_42')
795
796 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
797
798 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
799 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId, reason: 'user reason 2' })
800 })
801
802 it('Should correctly list my abuses', async function () {
803 {
804 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
805 expect(res.body.total).to.equal(2)
806
807 const abuses: UserAbuse[] = res.body.data
808 expect(abuses[0].reason).to.equal('user reason 1')
809 expect(abuses[1].reason).to.equal('user reason 2')
810
811 abuseId1 = abuses[0].id
812 }
813
814 {
815 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
816 expect(res.body.total).to.equal(2)
817
818 const abuses: UserAbuse[] = res.body.data
819 expect(abuses[0].reason).to.equal('user reason 2')
820 }
821
822 {
823 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
824 expect(res.body.total).to.equal(2)
825
826 const abuses: UserAbuse[] = res.body.data
827 expect(abuses[0].reason).to.equal('user reason 1')
828 }
829 })
830
831 it('Should correctly filter my abuses by id', async function () {
832 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, id: abuseId1 })
833
834 expect(res.body.total).to.equal(1)
835
836 const abuses: UserAbuse[] = res.body.data
837 expect(abuses[0].reason).to.equal('user reason 1')
838 })
839
840 it('Should correctly filter my abuses by search', async function () {
841 const res = await getUserAbusesList({
842 url: servers[0].url,
843 token: userAccessToken,
844 search: 'server 2'
845 })
846
847 expect(res.body.total).to.equal(1)
848
849 const abuses: UserAbuse[] = res.body.data
850 expect(abuses[0].reason).to.equal('user reason 2')
851 })
852
853 it('Should correctly filter my abuses by state', async function () {
854 const body = { state: AbuseState.REJECTED }
855 await updateAbuse(servers[0].url, servers[0].accessToken, abuseId1, body)
856
857 const res = await getUserAbusesList({
858 url: servers[0].url,
859 token: userAccessToken,
860 state: AbuseState.REJECTED
861 })
862
863 expect(res.body.total).to.equal(1)
864
865 const abuses: UserAbuse[] = res.body.data
866 expect(abuses[0].reason).to.equal('user reason 1')
867 })
868 })
869
870 describe('Abuse messages', async function () {
871 let abuseId: number
872 let userAccessToken: string
873 let abuseMessageUserId: number
874 let abuseMessageModerationId: number
875
876 before(async function () {
877 userAccessToken = await generateUserAccessToken(servers[0], 'user_43')
878
879 const res = await reportAbuse({
880 url: servers[0].url,
881 token: userAccessToken,
882 videoId: servers[0].video.id,
883 reason: 'user 43 reason 1'
884 })
885
886 abuseId = res.body.abuse.id
887 })
888
889 it('Should create some messages on the abuse', async function () {
890 await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 1')
891 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 2')
892 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 3')
893 await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 4')
894 })
895
896 it('Should have the correct messages count when listing abuses', async function () {
897 const results = await Promise.all([
898 getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, start: 0, count: 50 }),
899 getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 50 })
900 ])
901
902 for (const res of results) {
903 const abuses: AdminAbuse[] = res.body.data
904 const abuse = abuses.find(a => a.id === abuseId)
905 expect(abuse.countMessages).to.equal(4)
906 }
907 })
908
909 it('Should correctly list messages of this abuse', async function () {
910 const results = await Promise.all([
911 listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId),
912 listAbuseMessages(servers[0].url, userAccessToken, abuseId)
913 ])
914
915 for (const res of results) {
916 expect(res.body.total).to.equal(4)
917
918 const abuseMessages: AbuseMessage[] = res.body.data
919
920 expect(abuseMessages[0].message).to.equal('message 1')
921 expect(abuseMessages[0].byModerator).to.be.false
922 expect(abuseMessages[0].account.name).to.equal('user_43')
923
924 abuseMessageUserId = abuseMessages[0].id
925
926 expect(abuseMessages[1].message).to.equal('message 2')
927 expect(abuseMessages[1].byModerator).to.be.true
928 expect(abuseMessages[1].account.name).to.equal('root')
929
930 expect(abuseMessages[2].message).to.equal('message 3')
931 expect(abuseMessages[2].byModerator).to.be.true
932 expect(abuseMessages[2].account.name).to.equal('root')
933 abuseMessageModerationId = abuseMessages[2].id
934
935 expect(abuseMessages[3].message).to.equal('message 4')
936 expect(abuseMessages[3].byModerator).to.be.false
937 expect(abuseMessages[3].account.name).to.equal('user_43')
938 }
939 })
940
941 it('Should delete messages', async function () {
942 await deleteAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, abuseMessageModerationId)
943 await deleteAbuseMessage(servers[0].url, userAccessToken, abuseId, abuseMessageUserId)
944
945 const results = await Promise.all([
946 listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId),
947 listAbuseMessages(servers[0].url, userAccessToken, abuseId)
948 ])
949
950 for (const res of results) {
951 expect(res.body.total).to.equal(2)
952
953 const abuseMessages: AbuseMessage[] = res.body.data
954
955 expect(abuseMessages[0].message).to.equal('message 2')
956 expect(abuseMessages[1].message).to.equal('message 4')
957 }
958 })
959 })
960
774 after(async function () { 961 after(async function () {
775 await cleanupTests(servers) 962 await cleanupTests(servers)
776 }) 963 })