1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
7 addAccountToServerBlocklist,
8 addServerToServerBlocklist,
14 flushAndRunMultipleServers,
15 generateUserAccessToken,
16 getVideoCommentThreads,
19 removeAccountFromServerBlocklist,
20 removeServerFromServerBlocklist,
24 setAccessTokensToServers,
29 } from '@shared/extra-utils'
30 import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, Account, AdminAbuse, UserAbuse, VideoComment } from '@shared/models'
32 const expect = chai.expect
34 describe('Test abuses', function () {
35 let servers: ServerInfo[] = []
36 let abuseServer1: AdminAbuse
37 let abuseServer2: AdminAbuse
38 let commands: AbusesCommand[]
40 before(async function () {
44 servers = await flushAndRunMultipleServers(2)
46 // Get the access tokens
47 await setAccessTokensToServers(servers)
49 // Server 1 and server 2 follow each other
50 await doubleFollow(servers[0], servers[1])
52 commands = servers.map(s => s.abusesCommand)
55 describe('Video abuses', function () {
57 before(async function () {
60 // Upload some videos on each servers
61 const video1Attributes = {
62 name: 'my super name for server 1',
63 description: 'my super description for server 1'
65 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
67 const video2Attributes = {
68 name: 'my super name for server 2',
69 description: 'my super description for server 2'
71 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
73 // Wait videos propagation, server 2 has transcoding enabled
74 await waitJobs(servers)
76 const res = await getVideosList(servers[0].url)
77 const videos = res.body.data
79 expect(videos.length).to.equal(2)
81 servers[0].video = videos.find(video => video.name === 'my super name for server 1')
82 servers[1].video = videos.find(video => video.name === 'my super name for server 2')
85 it('Should not have abuses', async function () {
86 const body = await commands[0].getAdminList()
88 expect(body.total).to.equal(0)
89 expect(body.data).to.be.an('array')
90 expect(body.data.length).to.equal(0)
93 it('Should report abuse on a local video', async function () {
96 const reason = 'my super bad reason'
97 await commands[0].report({ videoId: servers[0].video.id, reason })
99 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
100 await waitJobs(servers)
103 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
105 const body = await commands[0].getAdminList()
107 expect(body.total).to.equal(1)
108 expect(body.data).to.be.an('array')
109 expect(body.data.length).to.equal(1)
111 const abuse = body.data[0]
112 expect(abuse.reason).to.equal('my super bad reason')
114 expect(abuse.reporterAccount.name).to.equal('root')
115 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
117 expect(abuse.video.id).to.equal(servers[0].video.id)
118 expect(abuse.video.channel).to.exist
120 expect(abuse.comment).to.be.null
122 expect(abuse.flaggedAccount.name).to.equal('root')
123 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
125 expect(abuse.video.countReports).to.equal(1)
126 expect(abuse.video.nthReport).to.equal(1)
128 expect(abuse.countReportsForReporter).to.equal(1)
129 expect(abuse.countReportsForReportee).to.equal(1)
133 const body = await commands[1].getAdminList()
134 expect(body.total).to.equal(0)
135 expect(body.data).to.be.an('array')
136 expect(body.data.length).to.equal(0)
140 it('Should report abuse on a remote video', async function () {
143 const reason = 'my super bad reason 2'
144 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
145 await commands[0].report({ videoId, reason })
147 // We wait requests propagation
148 await waitJobs(servers)
151 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
153 const body = await commands[0].getAdminList()
155 expect(body.total).to.equal(2)
156 expect(body.data.length).to.equal(2)
158 const abuse1 = body.data[0]
159 expect(abuse1.reason).to.equal('my super bad reason')
160 expect(abuse1.reporterAccount.name).to.equal('root')
161 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
163 expect(abuse1.video.id).to.equal(servers[0].video.id)
164 expect(abuse1.video.countReports).to.equal(1)
165 expect(abuse1.video.nthReport).to.equal(1)
167 expect(abuse1.comment).to.be.null
169 expect(abuse1.flaggedAccount.name).to.equal('root')
170 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
172 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
173 expect(abuse1.state.label).to.equal('Pending')
174 expect(abuse1.moderationComment).to.be.null
176 const abuse2 = body.data[1]
177 expect(abuse2.reason).to.equal('my super bad reason 2')
179 expect(abuse2.reporterAccount.name).to.equal('root')
180 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
182 expect(abuse2.video.id).to.equal(servers[1].video.id)
184 expect(abuse2.comment).to.be.null
186 expect(abuse2.flaggedAccount.name).to.equal('root')
187 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
189 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
190 expect(abuse2.state.label).to.equal('Pending')
191 expect(abuse2.moderationComment).to.be.null
195 const body = await commands[1].getAdminList()
196 expect(body.total).to.equal(1)
197 expect(body.data.length).to.equal(1)
199 abuseServer2 = body.data[0]
200 expect(abuseServer2.reason).to.equal('my super bad reason 2')
201 expect(abuseServer2.reporterAccount.name).to.equal('root')
202 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
204 expect(abuseServer2.flaggedAccount.name).to.equal('root')
205 expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host)
207 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
208 expect(abuseServer2.state.label).to.equal('Pending')
209 expect(abuseServer2.moderationComment).to.be.null
213 it('Should hide video abuses from blocked accounts', async function () {
217 const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid)
218 await commands[1].report({ videoId, reason: 'will mute this' })
219 await waitJobs(servers)
221 const body = await commands[0].getAdminList()
222 expect(body.total).to.equal(3)
225 const accountToBlock = 'root@' + servers[1].host
228 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
230 const body = await commands[0].getAdminList()
231 expect(body.total).to.equal(2)
233 const abuse = body.data.find(a => a.reason === 'will mute this')
234 expect(abuse).to.be.undefined
238 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
240 const body = await commands[0].getAdminList()
241 expect(body.total).to.equal(3)
245 it('Should hide video abuses from blocked servers', async function () {
246 const serverToBlock = servers[1].host
249 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)
251 const body = await commands[0].getAdminList()
252 expect(body.total).to.equal(2)
254 const abuse = body.data.find(a => a.reason === 'will mute this')
255 expect(abuse).to.be.undefined
259 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock)
261 const body = await commands[0].getAdminList()
262 expect(body.total).to.equal(3)
266 it('Should keep the video abuse when deleting the video', async function () {
269 await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid)
271 await waitJobs(servers)
273 const body = await commands[1].getAdminList()
274 expect(body.total).to.equal(2, "wrong number of videos returned")
275 expect(body.data).to.have.lengthOf(2, "wrong number of videos returned")
277 const abuse = body.data[0]
278 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video")
279 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
280 expect(abuse.video.channel).to.exist
281 expect(abuse.video.deleted).to.be.true
284 it('Should include counts of reports from reporter and reportee', async function () {
287 // register a second user to have two reporters/reportees
288 const user = { username: 'user2', password: 'password' }
289 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user })
290 const userAccessToken = await userLogin(servers[0], user)
292 // upload a third video via this user
293 const video3Attributes = {
294 name: 'my second super name for server 1',
295 description: 'my second super description for server 1'
297 const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes)
298 const video3Id = resUpload.body.video.id
300 // resume with the test
301 const reason3 = 'my super bad reason 3'
302 await commands[0].report({ videoId: video3Id, reason: reason3 })
304 const reason4 = 'my super bad reason 4'
305 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: reason4 })
308 const body = await commands[0].getAdminList()
309 const abuses = body.data
311 const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
312 expect(abuseVideo3).to.not.be.undefined
313 expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3")
314 expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3")
315 expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse")
316 expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse")
318 const abuseServer1 = abuses.find(a => a.video.id === servers[0].video.id)
319 expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse")
323 it('Should list predefined reasons as well as timestamps for the reported video', async function () {
326 const reason5 = 'my super bad reason 5'
327 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
328 const createRes = await commands[0].report({
329 videoId: servers[0].video.id,
331 predefinedReasons: predefinedReasons5,
336 const body = await commands[0].getAdminList()
339 const abuse = body.data.find(a => a.id === createRes.abuse.id)
340 expect(abuse.reason).to.equals(reason5)
341 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")
343 expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
347 it('Should delete the video abuse', async function () {
350 await commands[1].delete({ abuseId: abuseServer2.id })
352 await waitJobs(servers)
355 const body = await commands[1].getAdminList()
356 expect(body.total).to.equal(1)
357 expect(body.data.length).to.equal(1)
358 expect(body.data[0].id).to.not.equal(abuseServer2.id)
362 const body = await commands[0].getAdminList()
363 expect(body.total).to.equal(6)
367 it('Should list and filter video abuses', async function () {
370 async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) {
371 const body = await commands[0].getAdminList(query)
376 expect(await list({ id: 56 })).to.have.lengthOf(0)
377 expect(await list({ id: 1 })).to.have.lengthOf(1)
379 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4)
380 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
382 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
384 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4)
385 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
387 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
388 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5)
390 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5)
391 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
393 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
394 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
396 expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0)
397 expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6)
399 expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1)
400 expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0)
404 describe('Comment abuses', function () {
406 async function getComment (url: string, videoIdArg: number | string) {
407 const videoId = typeof videoIdArg === 'string'
408 ? await getVideoIdFromUUID(url, videoIdArg)
411 const res = await getVideoCommentThreads(url, videoId, 0, 5)
413 return res.body.data[0] as VideoComment
416 before(async function () {
419 servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })
420 servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })
422 await addVideoCommentThread(servers[0].url, servers[0].accessToken, servers[0].video.id, 'comment server 1')
423 await addVideoCommentThread(servers[1].url, servers[1].accessToken, servers[1].video.id, 'comment server 2')
425 await waitJobs(servers)
428 it('Should report abuse on a comment', async function () {
431 const comment = await getComment(servers[0].url, servers[0].video.id)
433 const reason = 'it is a bad comment'
434 await commands[0].report({ commentId: comment.id, reason })
436 await waitJobs(servers)
439 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
441 const comment = await getComment(servers[0].url, servers[0].video.id)
442 const body = await commands[0].getAdminList({ filter: 'comment' })
444 expect(body.total).to.equal(1)
445 expect(body.data).to.have.lengthOf(1)
447 const abuse = body.data[0]
448 expect(abuse.reason).to.equal('it is a bad comment')
450 expect(abuse.reporterAccount.name).to.equal('root')
451 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
453 expect(abuse.video).to.be.null
455 expect(abuse.comment.deleted).to.be.false
456 expect(abuse.comment.id).to.equal(comment.id)
457 expect(abuse.comment.text).to.equal(comment.text)
458 expect(abuse.comment.video.name).to.equal('server 1')
459 expect(abuse.comment.video.id).to.equal(servers[0].video.id)
460 expect(abuse.comment.video.uuid).to.equal(servers[0].video.uuid)
462 expect(abuse.countReportsForReporter).to.equal(5)
463 expect(abuse.countReportsForReportee).to.equal(5)
467 const body = await commands[1].getAdminList({ filter: 'comment' })
468 expect(body.total).to.equal(0)
469 expect(body.data.length).to.equal(0)
473 it('Should report abuse on a remote comment', async function () {
476 const comment = await getComment(servers[0].url, servers[1].video.uuid)
478 const reason = 'it is a really bad comment'
479 await commands[0].report({ commentId: comment.id, reason })
481 await waitJobs(servers)
484 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
485 const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
488 const body = await commands[0].getAdminList({ filter: 'comment' })
489 expect(body.total).to.equal(2)
490 expect(body.data.length).to.equal(2)
492 const abuse = body.data[0]
493 expect(abuse.reason).to.equal('it is a bad comment')
494 expect(abuse.countReportsForReporter).to.equal(6)
495 expect(abuse.countReportsForReportee).to.equal(5)
497 const abuse2 = body.data[1]
499 expect(abuse2.reason).to.equal('it is a really bad comment')
501 expect(abuse2.reporterAccount.name).to.equal('root')
502 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
504 expect(abuse2.video).to.be.null
506 expect(abuse2.comment.deleted).to.be.false
507 expect(abuse2.comment.id).to.equal(commentServer2.id)
508 expect(abuse2.comment.text).to.equal(commentServer2.text)
509 expect(abuse2.comment.video.name).to.equal('server 2')
510 expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid)
512 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
513 expect(abuse2.state.label).to.equal('Pending')
515 expect(abuse2.moderationComment).to.be.null
517 expect(abuse2.countReportsForReporter).to.equal(6)
518 expect(abuse2.countReportsForReportee).to.equal(2)
522 const body = await commands[1].getAdminList({ filter: 'comment' })
523 expect(body.total).to.equal(1)
524 expect(body.data.length).to.equal(1)
526 abuseServer2 = body.data[0]
527 expect(abuseServer2.reason).to.equal('it is a really bad comment')
528 expect(abuseServer2.reporterAccount.name).to.equal('root')
529 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
531 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
532 expect(abuseServer2.state.label).to.equal('Pending')
534 expect(abuseServer2.moderationComment).to.be.null
536 expect(abuseServer2.countReportsForReporter).to.equal(1)
537 expect(abuseServer2.countReportsForReportee).to.equal(1)
541 it('Should keep the comment abuse when deleting the comment', async function () {
544 const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
546 await deleteVideoComment(servers[0].url, servers[0].accessToken, servers[1].video.uuid, commentServer2.id)
548 await waitJobs(servers)
550 const body = await commands[0].getAdminList({ filter: 'comment' })
551 expect(body.total).to.equal(2)
552 expect(body.data).to.have.lengthOf(2)
554 const abuse = body.data.find(a => a.comment?.id === commentServer2.id)
555 expect(abuse).to.not.be.undefined
557 expect(abuse.comment.text).to.be.empty
558 expect(abuse.comment.video.name).to.equal('server 2')
559 expect(abuse.comment.deleted).to.be.true
562 it('Should delete the comment abuse', async function () {
565 await commands[1].delete({ abuseId: abuseServer2.id })
567 await waitJobs(servers)
570 const body = await commands[1].getAdminList({ filter: 'comment' })
571 expect(body.total).to.equal(0)
572 expect(body.data.length).to.equal(0)
576 const body = await commands[0].getAdminList({ filter: 'comment' })
577 expect(body.total).to.equal(2)
581 it('Should list and filter video abuses', async function () {
583 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' })
584 expect(body.total).to.equal(0)
588 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' })
589 expect(body.total).to.equal(2)
593 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' })
594 expect(body.data).to.have.lengthOf(1)
595 expect(body.data[0].comment.text).to.be.empty
599 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' })
600 expect(body.data).to.have.lengthOf(1)
601 expect(body.data[0].comment.text).to.equal('comment server 1')
606 describe('Account abuses', function () {
608 function getAccountFromServer (server: ServerInfo, targetName: string, targetServer: ServerInfo) {
609 return server.accountsCommand.get({ accountName: targetName + '@' + targetServer.host })
612 before(async function () {
615 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' })
617 const token = await generateUserAccessToken(servers[1], 'user_2')
618 await uploadVideo(servers[1].url, token, { name: 'super video' })
620 await waitJobs(servers)
623 it('Should report abuse on an account', async function () {
626 const account = await getAccountFromServer(servers[0], 'user_1', servers[0])
628 const reason = 'it is a bad account'
629 await commands[0].report({ accountId: account.id, reason })
631 await waitJobs(servers)
634 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
636 const body = await commands[0].getAdminList({ filter: 'account' })
638 expect(body.total).to.equal(1)
639 expect(body.data).to.have.lengthOf(1)
641 const abuse = body.data[0]
642 expect(abuse.reason).to.equal('it is a bad account')
644 expect(abuse.reporterAccount.name).to.equal('root')
645 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
647 expect(abuse.video).to.be.null
648 expect(abuse.comment).to.be.null
650 expect(abuse.flaggedAccount.name).to.equal('user_1')
651 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
655 const body = await commands[1].getAdminList({ filter: 'comment' })
656 expect(body.total).to.equal(0)
657 expect(body.data.length).to.equal(0)
661 it('Should report abuse on a remote account', async function () {
664 const account = await getAccountFromServer(servers[0], 'user_2', servers[1])
666 const reason = 'it is a really bad account'
667 await commands[0].report({ accountId: account.id, reason })
669 await waitJobs(servers)
672 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
674 const body = await commands[0].getAdminList({ filter: 'account' })
675 expect(body.total).to.equal(2)
676 expect(body.data.length).to.equal(2)
678 const abuse: AdminAbuse = body.data[0]
679 expect(abuse.reason).to.equal('it is a bad account')
681 const abuse2: AdminAbuse = body.data[1]
682 expect(abuse2.reason).to.equal('it is a really bad account')
684 expect(abuse2.reporterAccount.name).to.equal('root')
685 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
687 expect(abuse2.video).to.be.null
688 expect(abuse2.comment).to.be.null
690 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
691 expect(abuse2.state.label).to.equal('Pending')
693 expect(abuse2.moderationComment).to.be.null
697 const body = await commands[1].getAdminList({ filter: 'account' })
698 expect(body.total).to.equal(1)
699 expect(body.data.length).to.equal(1)
701 abuseServer2 = body.data[0]
703 expect(abuseServer2.reason).to.equal('it is a really bad account')
705 expect(abuseServer2.reporterAccount.name).to.equal('root')
706 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
708 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
709 expect(abuseServer2.state.label).to.equal('Pending')
711 expect(abuseServer2.moderationComment).to.be.null
715 it('Should keep the account abuse when deleting the account', async function () {
718 const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
719 await removeUser(servers[1].url, account.userId, servers[1].accessToken)
721 await waitJobs(servers)
723 const body = await commands[0].getAdminList({ filter: 'account' })
724 expect(body.total).to.equal(2)
725 expect(body.data).to.have.lengthOf(2)
727 const abuse = body.data.find(a => a.reason === 'it is a really bad account')
728 expect(abuse).to.not.be.undefined
731 it('Should delete the account abuse', async function () {
734 await commands[1].delete({ abuseId: abuseServer2.id })
736 await waitJobs(servers)
739 const body = await commands[1].getAdminList({ filter: 'account' })
740 expect(body.total).to.equal(0)
741 expect(body.data.length).to.equal(0)
745 const body = await commands[0].getAdminList({ filter: 'account' })
746 expect(body.total).to.equal(2)
748 abuseServer1 = body.data[0]
753 describe('Common actions on abuses', function () {
755 it('Should update the state of an abuse', async function () {
756 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } })
758 const body = await commands[0].getAdminList({ id: abuseServer1.id })
759 expect(body.data[0].state.id).to.equal(AbuseState.REJECTED)
762 it('Should add a moderation comment', async function () {
763 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } })
765 const body = await commands[0].getAdminList({ id: abuseServer1.id })
766 expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
767 expect(body.data[0].moderationComment).to.equal('Valid')
771 describe('My abuses', async function () {
773 let userAccessToken: string
775 before(async function () {
776 userAccessToken = await generateUserAccessToken(servers[0], 'user_42')
778 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
780 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
781 await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
784 it('Should correctly list my abuses', async function () {
786 const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
787 expect(body.total).to.equal(2)
789 const abuses = body.data
790 expect(abuses[0].reason).to.equal('user reason 1')
791 expect(abuses[1].reason).to.equal('user reason 2')
793 abuseId1 = abuses[0].id
797 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
798 expect(body.total).to.equal(2)
800 const abuses: UserAbuse[] = body.data
801 expect(abuses[0].reason).to.equal('user reason 2')
805 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
806 expect(body.total).to.equal(2)
808 const abuses: UserAbuse[] = body.data
809 expect(abuses[0].reason).to.equal('user reason 1')
813 it('Should correctly filter my abuses by id', async function () {
814 const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 })
815 expect(body.total).to.equal(1)
817 const abuses: UserAbuse[] = body.data
818 expect(abuses[0].reason).to.equal('user reason 1')
821 it('Should correctly filter my abuses by search', async function () {
822 const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' })
823 expect(body.total).to.equal(1)
825 const abuses: UserAbuse[] = body.data
826 expect(abuses[0].reason).to.equal('user reason 2')
829 it('Should correctly filter my abuses by state', async function () {
830 await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } })
832 const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED })
833 expect(body.total).to.equal(1)
835 const abuses: UserAbuse[] = body.data
836 expect(abuses[0].reason).to.equal('user reason 1')
840 describe('Abuse messages', async function () {
842 let userToken: string
843 let abuseMessageUserId: number
844 let abuseMessageModerationId: number
846 before(async function () {
847 userToken = await generateUserAccessToken(servers[0], 'user_43')
849 const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' })
850 abuseId = body.abuse.id
853 it('Should create some messages on the abuse', async function () {
854 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' })
855 await commands[0].addMessage({ abuseId, message: 'message 2' })
856 await commands[0].addMessage({ abuseId, message: 'message 3' })
857 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' })
860 it('Should have the correct messages count when listing abuses', async function () {
861 const results = await Promise.all([
862 commands[0].getAdminList({ start: 0, count: 50 }),
863 commands[0].getUserList({ token: userToken, start: 0, count: 50 })
866 for (const body of results) {
867 const abuses = body.data
868 const abuse = abuses.find(a => a.id === abuseId)
869 expect(abuse.countMessages).to.equal(4)
873 it('Should correctly list messages of this abuse', async function () {
874 const results = await Promise.all([
875 commands[0].listMessages({ abuseId }),
876 commands[0].listMessages({ token: userToken, abuseId })
879 for (const body of results) {
880 expect(body.total).to.equal(4)
882 const abuseMessages: AbuseMessage[] = body.data
884 expect(abuseMessages[0].message).to.equal('message 1')
885 expect(abuseMessages[0].byModerator).to.be.false
886 expect(abuseMessages[0].account.name).to.equal('user_43')
888 abuseMessageUserId = abuseMessages[0].id
890 expect(abuseMessages[1].message).to.equal('message 2')
891 expect(abuseMessages[1].byModerator).to.be.true
892 expect(abuseMessages[1].account.name).to.equal('root')
894 expect(abuseMessages[2].message).to.equal('message 3')
895 expect(abuseMessages[2].byModerator).to.be.true
896 expect(abuseMessages[2].account.name).to.equal('root')
897 abuseMessageModerationId = abuseMessages[2].id
899 expect(abuseMessages[3].message).to.equal('message 4')
900 expect(abuseMessages[3].byModerator).to.be.false
901 expect(abuseMessages[3].account.name).to.equal('user_43')
905 it('Should delete messages', async function () {
906 await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId })
907 await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId })
909 const results = await Promise.all([
910 commands[0].listMessages({ abuseId }),
911 commands[0].listMessages({ token: userToken, abuseId })
914 for (const body of results) {
915 expect(body.total).to.equal(2)
917 const abuseMessages: AbuseMessage[] = body.data
918 expect(abuseMessages[0].message).to.equal('message 2')
919 expect(abuseMessages[1].message).to.equal('message 4')
924 after(async function () {
925 await cleanupTests(servers)