1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultAccountAvatar,
13 setDefaultChannelAvatar,
15 } from '@shared/server-commands'
17 describe('Test abuses', function () {
18 let servers: PeerTubeServer[] = []
19 let abuseServer1: AdminAbuse
20 let abuseServer2: AdminAbuse
21 let commands: AbusesCommand[]
23 before(async function () {
27 servers = await createMultipleServers(2)
29 await setAccessTokensToServers(servers)
30 await setDefaultChannelAvatar(servers)
31 await setDefaultAccountAvatar(servers)
33 // Server 1 and server 2 follow each other
34 await doubleFollow(servers[0], servers[1])
36 commands = servers.map(s => s.abuses)
39 describe('Video abuses', function () {
41 before(async function () {
44 // Upload some videos on each servers
47 name: 'my super name for server 1',
48 description: 'my super description for server 1'
50 await servers[0].videos.upload({ attributes })
55 name: 'my super name for server 2',
56 description: 'my super description for server 2'
58 await servers[1].videos.upload({ attributes })
61 // Wait videos propagation, server 2 has transcoding enabled
62 await waitJobs(servers)
64 const { data } = await servers[0].videos.list()
65 expect(data.length).to.equal(2)
67 servers[0].store.videoCreated = data.find(video => video.name === 'my super name for server 1')
68 servers[1].store.videoCreated = data.find(video => video.name === 'my super name for server 2')
71 it('Should not have abuses', async function () {
72 const body = await commands[0].getAdminList()
74 expect(body.total).to.equal(0)
75 expect(body.data).to.be.an('array')
76 expect(body.data.length).to.equal(0)
79 it('Should report abuse on a local video', async function () {
82 const reason = 'my super bad reason'
83 await commands[0].report({ videoId: servers[0].store.videoCreated.id, reason })
85 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
86 await waitJobs(servers)
89 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
91 const body = await commands[0].getAdminList()
93 expect(body.total).to.equal(1)
94 expect(body.data).to.be.an('array')
95 expect(body.data.length).to.equal(1)
97 const abuse = body.data[0]
98 expect(abuse.reason).to.equal('my super bad reason')
100 expect(abuse.reporterAccount.name).to.equal('root')
101 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
103 expect(abuse.video.id).to.equal(servers[0].store.videoCreated.id)
104 expect(abuse.video.channel).to.exist
106 expect(abuse.comment).to.be.null
108 expect(abuse.flaggedAccount.name).to.equal('root')
109 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
111 expect(abuse.video.countReports).to.equal(1)
112 expect(abuse.video.nthReport).to.equal(1)
114 expect(abuse.countReportsForReporter).to.equal(1)
115 expect(abuse.countReportsForReportee).to.equal(1)
119 const body = await commands[1].getAdminList()
120 expect(body.total).to.equal(0)
121 expect(body.data).to.be.an('array')
122 expect(body.data.length).to.equal(0)
126 it('Should report abuse on a remote video', async function () {
129 const reason = 'my super bad reason 2'
130 const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid })
131 await commands[0].report({ videoId, reason })
133 // We wait requests propagation
134 await waitJobs(servers)
137 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
139 const body = await commands[0].getAdminList()
141 expect(body.total).to.equal(2)
142 expect(body.data.length).to.equal(2)
144 const abuse1 = body.data[0]
145 expect(abuse1.reason).to.equal('my super bad reason')
146 expect(abuse1.reporterAccount.name).to.equal('root')
147 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
149 expect(abuse1.video.id).to.equal(servers[0].store.videoCreated.id)
150 expect(abuse1.video.countReports).to.equal(1)
151 expect(abuse1.video.nthReport).to.equal(1)
153 expect(abuse1.comment).to.be.null
155 expect(abuse1.flaggedAccount.name).to.equal('root')
156 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
158 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
159 expect(abuse1.state.label).to.equal('Pending')
160 expect(abuse1.moderationComment).to.be.null
162 const abuse2 = body.data[1]
163 expect(abuse2.reason).to.equal('my super bad reason 2')
165 expect(abuse2.reporterAccount.name).to.equal('root')
166 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
168 expect(abuse2.video.uuid).to.equal(servers[1].store.videoCreated.uuid)
170 expect(abuse2.comment).to.be.null
172 expect(abuse2.flaggedAccount.name).to.equal('root')
173 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
175 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
176 expect(abuse2.state.label).to.equal('Pending')
177 expect(abuse2.moderationComment).to.be.null
181 const body = await commands[1].getAdminList()
182 expect(body.total).to.equal(1)
183 expect(body.data.length).to.equal(1)
185 abuseServer2 = body.data[0]
186 expect(abuseServer2.reason).to.equal('my super bad reason 2')
187 expect(abuseServer2.reporterAccount.name).to.equal('root')
188 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
190 expect(abuseServer2.flaggedAccount.name).to.equal('root')
191 expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host)
193 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
194 expect(abuseServer2.state.label).to.equal('Pending')
195 expect(abuseServer2.moderationComment).to.be.null
199 it('Should hide video abuses from blocked accounts', async function () {
203 const videoId = await servers[1].videos.getId({ uuid: servers[0].store.videoCreated.uuid })
204 await commands[1].report({ videoId, reason: 'will mute this' })
205 await waitJobs(servers)
207 const body = await commands[0].getAdminList()
208 expect(body.total).to.equal(3)
211 const accountToBlock = 'root@' + servers[1].host
214 await servers[0].blocklist.addToServerBlocklist({ account: accountToBlock })
216 const body = await commands[0].getAdminList()
217 expect(body.total).to.equal(2)
219 const abuse = body.data.find(a => a.reason === 'will mute this')
220 expect(abuse).to.be.undefined
224 await servers[0].blocklist.removeFromServerBlocklist({ account: accountToBlock })
226 const body = await commands[0].getAdminList()
227 expect(body.total).to.equal(3)
231 it('Should hide video abuses from blocked servers', async function () {
232 const serverToBlock = servers[1].host
235 await servers[0].blocklist.addToServerBlocklist({ server: serverToBlock })
237 const body = await commands[0].getAdminList()
238 expect(body.total).to.equal(2)
240 const abuse = body.data.find(a => a.reason === 'will mute this')
241 expect(abuse).to.be.undefined
245 await servers[0].blocklist.removeFromServerBlocklist({ server: serverToBlock })
247 const body = await commands[0].getAdminList()
248 expect(body.total).to.equal(3)
252 it('Should keep the video abuse when deleting the video', async function () {
255 await servers[1].videos.remove({ id: abuseServer2.video.uuid })
257 await waitJobs(servers)
259 const body = await commands[1].getAdminList()
260 expect(body.total).to.equal(2, 'wrong number of videos returned')
261 expect(body.data).to.have.lengthOf(2, 'wrong number of videos returned')
263 const abuse = body.data[0]
264 expect(abuse.id).to.equal(abuseServer2.id, 'wrong origin server id for first video')
265 expect(abuse.video.id).to.equal(abuseServer2.video.id, 'wrong video id')
266 expect(abuse.video.channel).to.exist
267 expect(abuse.video.deleted).to.be.true
270 it('Should include counts of reports from reporter and reportee', async function () {
273 // register a second user to have two reporters/reportees
274 const user = { username: 'user2', password: 'password' }
275 await servers[0].users.create({ ...user })
276 const userAccessToken = await servers[0].login.getAccessToken(user)
278 // upload a third video via this user
280 name: 'my second super name for server 1',
281 description: 'my second super description for server 1'
283 const { id } = await servers[0].videos.upload({ token: userAccessToken, attributes })
286 // resume with the test
287 const reason3 = 'my super bad reason 3'
288 await commands[0].report({ videoId: video3Id, reason: reason3 })
290 const reason4 = 'my super bad reason 4'
291 await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: reason4 })
294 const body = await commands[0].getAdminList()
295 const abuses = body.data
297 const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
298 expect(abuseVideo3).to.not.be.undefined
299 expect(abuseVideo3.video.countReports).to.equal(1, 'wrong reports count for video 3')
300 expect(abuseVideo3.video.nthReport).to.equal(1, 'wrong report position in report list for video 3')
301 expect(abuseVideo3.countReportsForReportee).to.equal(1, 'wrong reports count for reporter on video 3 abuse')
302 expect(abuseVideo3.countReportsForReporter).to.equal(3, 'wrong reports count for reportee on video 3 abuse')
304 const abuseServer1 = abuses.find(a => a.video.id === servers[0].store.videoCreated.id)
305 expect(abuseServer1.countReportsForReportee).to.equal(3, 'wrong reports count for reporter on video 1 abuse')
309 it('Should list predefined reasons as well as timestamps for the reported video', async function () {
312 const reason5 = 'my super bad reason 5'
313 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
314 const createRes = await commands[0].report({
315 videoId: servers[0].store.videoCreated.id,
317 predefinedReasons: predefinedReasons5,
322 const body = await commands[0].getAdminList()
325 const abuse = body.data.find(a => a.id === createRes.abuse.id)
326 expect(abuse.reason).to.equals(reason5)
327 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, 'predefined reasons do not match the one reported')
328 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
329 expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
333 it('Should delete the video abuse', async function () {
336 await commands[1].delete({ abuseId: abuseServer2.id })
338 await waitJobs(servers)
341 const body = await commands[1].getAdminList()
342 expect(body.total).to.equal(1)
343 expect(body.data.length).to.equal(1)
344 expect(body.data[0].id).to.not.equal(abuseServer2.id)
348 const body = await commands[0].getAdminList()
349 expect(body.total).to.equal(6)
353 it('Should list and filter video abuses', async function () {
356 async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) {
357 const body = await commands[0].getAdminList(query)
362 expect(await list({ id: 56 })).to.have.lengthOf(0)
363 expect(await list({ id: 1 })).to.have.lengthOf(1)
365 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4)
366 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
368 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
370 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4)
371 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
373 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
374 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5)
376 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5)
377 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
379 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
380 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
382 expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0)
383 expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6)
385 expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1)
386 expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0)
390 describe('Comment abuses', function () {
392 async function getComment (server: PeerTubeServer, videoIdArg: number | string) {
393 const videoId = typeof videoIdArg === 'string'
394 ? await server.videos.getId({ uuid: videoIdArg })
397 const { data } = await server.comments.listThreads({ videoId })
402 before(async function () {
405 servers[0].store.videoCreated = await servers[0].videos.quickUpload({ name: 'server 1' })
406 servers[1].store.videoCreated = await servers[1].videos.quickUpload({ name: 'server 2' })
408 await servers[0].comments.createThread({ videoId: servers[0].store.videoCreated.id, text: 'comment server 1' })
409 await servers[1].comments.createThread({ videoId: servers[1].store.videoCreated.id, text: 'comment server 2' })
411 await waitJobs(servers)
414 it('Should report abuse on a comment', async function () {
417 const comment = await getComment(servers[0], servers[0].store.videoCreated.id)
419 const reason = 'it is a bad comment'
420 await commands[0].report({ commentId: comment.id, reason })
422 await waitJobs(servers)
425 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
427 const comment = await getComment(servers[0], servers[0].store.videoCreated.id)
428 const body = await commands[0].getAdminList({ filter: 'comment' })
430 expect(body.total).to.equal(1)
431 expect(body.data).to.have.lengthOf(1)
433 const abuse = body.data[0]
434 expect(abuse.reason).to.equal('it is a bad comment')
436 expect(abuse.reporterAccount.name).to.equal('root')
437 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
439 expect(abuse.video).to.be.null
441 expect(abuse.comment.deleted).to.be.false
442 expect(abuse.comment.id).to.equal(comment.id)
443 expect(abuse.comment.text).to.equal(comment.text)
444 expect(abuse.comment.video.name).to.equal('server 1')
445 expect(abuse.comment.video.id).to.equal(servers[0].store.videoCreated.id)
446 expect(abuse.comment.video.uuid).to.equal(servers[0].store.videoCreated.uuid)
448 expect(abuse.countReportsForReporter).to.equal(5)
449 expect(abuse.countReportsForReportee).to.equal(5)
453 const body = await commands[1].getAdminList({ filter: 'comment' })
454 expect(body.total).to.equal(0)
455 expect(body.data.length).to.equal(0)
459 it('Should report abuse on a remote comment', async function () {
462 const comment = await getComment(servers[0], servers[1].store.videoCreated.uuid)
464 const reason = 'it is a really bad comment'
465 await commands[0].report({ commentId: comment.id, reason })
467 await waitJobs(servers)
470 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
471 const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.shortUUID)
474 const body = await commands[0].getAdminList({ filter: 'comment' })
475 expect(body.total).to.equal(2)
476 expect(body.data.length).to.equal(2)
478 const abuse = body.data[0]
479 expect(abuse.reason).to.equal('it is a bad comment')
480 expect(abuse.countReportsForReporter).to.equal(6)
481 expect(abuse.countReportsForReportee).to.equal(5)
483 const abuse2 = body.data[1]
485 expect(abuse2.reason).to.equal('it is a really bad comment')
487 expect(abuse2.reporterAccount.name).to.equal('root')
488 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
490 expect(abuse2.video).to.be.null
492 expect(abuse2.comment.deleted).to.be.false
493 expect(abuse2.comment.id).to.equal(commentServer2.id)
494 expect(abuse2.comment.text).to.equal(commentServer2.text)
495 expect(abuse2.comment.video.name).to.equal('server 2')
496 expect(abuse2.comment.video.uuid).to.equal(servers[1].store.videoCreated.uuid)
498 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
499 expect(abuse2.state.label).to.equal('Pending')
501 expect(abuse2.moderationComment).to.be.null
503 expect(abuse2.countReportsForReporter).to.equal(6)
504 expect(abuse2.countReportsForReportee).to.equal(2)
508 const body = await commands[1].getAdminList({ filter: 'comment' })
509 expect(body.total).to.equal(1)
510 expect(body.data.length).to.equal(1)
512 abuseServer2 = body.data[0]
513 expect(abuseServer2.reason).to.equal('it is a really bad comment')
514 expect(abuseServer2.reporterAccount.name).to.equal('root')
515 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
517 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
518 expect(abuseServer2.state.label).to.equal('Pending')
520 expect(abuseServer2.moderationComment).to.be.null
522 expect(abuseServer2.countReportsForReporter).to.equal(1)
523 expect(abuseServer2.countReportsForReportee).to.equal(1)
527 it('Should keep the comment abuse when deleting the comment', async function () {
530 const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.uuid)
532 await servers[0].comments.delete({ videoId: servers[1].store.videoCreated.uuid, commentId: commentServer2.id })
534 await waitJobs(servers)
536 const body = await commands[0].getAdminList({ filter: 'comment' })
537 expect(body.total).to.equal(2)
538 expect(body.data).to.have.lengthOf(2)
540 const abuse = body.data.find(a => a.comment?.id === commentServer2.id)
541 expect(abuse).to.not.be.undefined
543 expect(abuse.comment.text).to.be.empty
544 expect(abuse.comment.video.name).to.equal('server 2')
545 expect(abuse.comment.deleted).to.be.true
548 it('Should delete the comment abuse', async function () {
551 await commands[1].delete({ abuseId: abuseServer2.id })
553 await waitJobs(servers)
556 const body = await commands[1].getAdminList({ filter: 'comment' })
557 expect(body.total).to.equal(0)
558 expect(body.data.length).to.equal(0)
562 const body = await commands[0].getAdminList({ filter: 'comment' })
563 expect(body.total).to.equal(2)
567 it('Should list and filter video abuses', async function () {
569 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' })
570 expect(body.total).to.equal(0)
574 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' })
575 expect(body.total).to.equal(2)
579 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' })
580 expect(body.data).to.have.lengthOf(1)
581 expect(body.data[0].comment.text).to.be.empty
585 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' })
586 expect(body.data).to.have.lengthOf(1)
587 expect(body.data[0].comment.text).to.equal('comment server 1')
592 describe('Account abuses', function () {
594 function getAccountFromServer (server: PeerTubeServer, targetName: string, targetServer: PeerTubeServer) {
595 return server.accounts.get({ accountName: targetName + '@' + targetServer.host })
598 before(async function () {
601 await servers[0].users.create({ username: 'user_1', password: 'donald' })
603 const token = await servers[1].users.generateUserAndToken('user_2')
604 await servers[1].videos.upload({ token, attributes: { name: 'super video' } })
606 await waitJobs(servers)
609 it('Should report abuse on an account', async function () {
612 const account = await getAccountFromServer(servers[0], 'user_1', servers[0])
614 const reason = 'it is a bad account'
615 await commands[0].report({ accountId: account.id, reason })
617 await waitJobs(servers)
620 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
622 const body = await commands[0].getAdminList({ filter: 'account' })
624 expect(body.total).to.equal(1)
625 expect(body.data).to.have.lengthOf(1)
627 const abuse = body.data[0]
628 expect(abuse.reason).to.equal('it is a bad account')
630 expect(abuse.reporterAccount.name).to.equal('root')
631 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
633 expect(abuse.video).to.be.null
634 expect(abuse.comment).to.be.null
636 expect(abuse.flaggedAccount.name).to.equal('user_1')
637 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
641 const body = await commands[1].getAdminList({ filter: 'comment' })
642 expect(body.total).to.equal(0)
643 expect(body.data.length).to.equal(0)
647 it('Should report abuse on a remote account', async function () {
650 const account = await getAccountFromServer(servers[0], 'user_2', servers[1])
652 const reason = 'it is a really bad account'
653 await commands[0].report({ accountId: account.id, reason })
655 await waitJobs(servers)
658 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
660 const body = await commands[0].getAdminList({ filter: 'account' })
661 expect(body.total).to.equal(2)
662 expect(body.data.length).to.equal(2)
664 const abuse: AdminAbuse = body.data[0]
665 expect(abuse.reason).to.equal('it is a bad account')
667 const abuse2: AdminAbuse = body.data[1]
668 expect(abuse2.reason).to.equal('it is a really bad account')
670 expect(abuse2.reporterAccount.name).to.equal('root')
671 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
673 expect(abuse2.video).to.be.null
674 expect(abuse2.comment).to.be.null
676 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
677 expect(abuse2.state.label).to.equal('Pending')
679 expect(abuse2.moderationComment).to.be.null
683 const body = await commands[1].getAdminList({ filter: 'account' })
684 expect(body.total).to.equal(1)
685 expect(body.data.length).to.equal(1)
687 abuseServer2 = body.data[0]
689 expect(abuseServer2.reason).to.equal('it is a really bad account')
691 expect(abuseServer2.reporterAccount.name).to.equal('root')
692 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
694 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
695 expect(abuseServer2.state.label).to.equal('Pending')
697 expect(abuseServer2.moderationComment).to.be.null
701 it('Should keep the account abuse when deleting the account', async function () {
704 const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
705 await servers[1].users.remove({ userId: account.userId })
707 await waitJobs(servers)
709 const body = await commands[0].getAdminList({ filter: 'account' })
710 expect(body.total).to.equal(2)
711 expect(body.data).to.have.lengthOf(2)
713 const abuse = body.data.find(a => a.reason === 'it is a really bad account')
714 expect(abuse).to.not.be.undefined
717 it('Should delete the account abuse', async function () {
720 await commands[1].delete({ abuseId: abuseServer2.id })
722 await waitJobs(servers)
725 const body = await commands[1].getAdminList({ filter: 'account' })
726 expect(body.total).to.equal(0)
727 expect(body.data.length).to.equal(0)
731 const body = await commands[0].getAdminList({ filter: 'account' })
732 expect(body.total).to.equal(2)
734 abuseServer1 = body.data[0]
739 describe('Common actions on abuses', function () {
741 it('Should update the state of an abuse', async function () {
742 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } })
744 const body = await commands[0].getAdminList({ id: abuseServer1.id })
745 expect(body.data[0].state.id).to.equal(AbuseState.REJECTED)
748 it('Should add a moderation comment', async function () {
749 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } })
751 const body = await commands[0].getAdminList({ id: abuseServer1.id })
752 expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
753 expect(body.data[0].moderationComment).to.equal('Valid')
757 describe('My abuses', async function () {
759 let userAccessToken: string
761 before(async function () {
762 userAccessToken = await servers[0].users.generateUserAndToken('user_42')
764 await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: 'user reason 1' })
766 const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid })
767 await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
770 it('Should correctly list my abuses', async function () {
772 const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
773 expect(body.total).to.equal(2)
775 const abuses = body.data
776 expect(abuses[0].reason).to.equal('user reason 1')
777 expect(abuses[1].reason).to.equal('user reason 2')
779 abuseId1 = abuses[0].id
783 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
784 expect(body.total).to.equal(2)
786 const abuses: UserAbuse[] = body.data
787 expect(abuses[0].reason).to.equal('user reason 2')
791 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
792 expect(body.total).to.equal(2)
794 const abuses: UserAbuse[] = body.data
795 expect(abuses[0].reason).to.equal('user reason 1')
799 it('Should correctly filter my abuses by id', async function () {
800 const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 })
801 expect(body.total).to.equal(1)
803 const abuses: UserAbuse[] = body.data
804 expect(abuses[0].reason).to.equal('user reason 1')
807 it('Should correctly filter my abuses by search', async function () {
808 const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' })
809 expect(body.total).to.equal(1)
811 const abuses: UserAbuse[] = body.data
812 expect(abuses[0].reason).to.equal('user reason 2')
815 it('Should correctly filter my abuses by state', async function () {
816 await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } })
818 const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED })
819 expect(body.total).to.equal(1)
821 const abuses: UserAbuse[] = body.data
822 expect(abuses[0].reason).to.equal('user reason 1')
826 describe('Abuse messages', async function () {
828 let userToken: string
829 let abuseMessageUserId: number
830 let abuseMessageModerationId: number
832 before(async function () {
833 userToken = await servers[0].users.generateUserAndToken('user_43')
835 const body = await commands[0].report({ token: userToken, videoId: servers[0].store.videoCreated.id, reason: 'user 43 reason 1' })
836 abuseId = body.abuse.id
839 it('Should create some messages on the abuse', async function () {
840 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' })
841 await commands[0].addMessage({ abuseId, message: 'message 2' })
842 await commands[0].addMessage({ abuseId, message: 'message 3' })
843 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' })
846 it('Should have the correct messages count when listing abuses', async function () {
847 const results = await Promise.all([
848 commands[0].getAdminList({ start: 0, count: 50 }),
849 commands[0].getUserList({ token: userToken, start: 0, count: 50 })
852 for (const body of results) {
853 const abuses = body.data
854 const abuse = abuses.find(a => a.id === abuseId)
855 expect(abuse.countMessages).to.equal(4)
859 it('Should correctly list messages of this abuse', async function () {
860 const results = await Promise.all([
861 commands[0].listMessages({ abuseId }),
862 commands[0].listMessages({ token: userToken, abuseId })
865 for (const body of results) {
866 expect(body.total).to.equal(4)
868 const abuseMessages: AbuseMessage[] = body.data
870 expect(abuseMessages[0].message).to.equal('message 1')
871 expect(abuseMessages[0].byModerator).to.be.false
872 expect(abuseMessages[0].account.name).to.equal('user_43')
874 abuseMessageUserId = abuseMessages[0].id
876 expect(abuseMessages[1].message).to.equal('message 2')
877 expect(abuseMessages[1].byModerator).to.be.true
878 expect(abuseMessages[1].account.name).to.equal('root')
880 expect(abuseMessages[2].message).to.equal('message 3')
881 expect(abuseMessages[2].byModerator).to.be.true
882 expect(abuseMessages[2].account.name).to.equal('root')
883 abuseMessageModerationId = abuseMessages[2].id
885 expect(abuseMessages[3].message).to.equal('message 4')
886 expect(abuseMessages[3].byModerator).to.be.false
887 expect(abuseMessages[3].account.name).to.equal('user_43')
891 it('Should delete messages', async function () {
892 await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId })
893 await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId })
895 const results = await Promise.all([
896 commands[0].listMessages({ abuseId }),
897 commands[0].listMessages({ token: userToken, abuseId })
900 for (const body of results) {
901 expect(body.total).to.equal(2)
903 const abuseMessages: AbuseMessage[] = body.data
904 expect(abuseMessages[0].message).to.equal('message 2')
905 expect(abuseMessages[1].message).to.equal('message 4')
910 after(async function () {
911 await cleanupTests(servers)