1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
12 flushAndRunMultipleServers,
13 generateUserAccessToken,
14 getVideoCommentThreads,
20 setAccessTokensToServers,
25 } from '@shared/extra-utils'
26 import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse, VideoComment } from '@shared/models'
28 const expect = chai.expect
30 describe('Test abuses', function () {
31 let servers: ServerInfo[] = []
32 let abuseServer1: AdminAbuse
33 let abuseServer2: AdminAbuse
34 let commands: AbusesCommand[]
36 before(async function () {
40 servers = await flushAndRunMultipleServers(2)
42 // Get the access tokens
43 await setAccessTokensToServers(servers)
45 // Server 1 and server 2 follow each other
46 await doubleFollow(servers[0], servers[1])
48 commands = servers.map(s => s.abusesCommand)
51 describe('Video abuses', function () {
53 before(async function () {
56 // Upload some videos on each servers
57 const video1Attributes = {
58 name: 'my super name for server 1',
59 description: 'my super description for server 1'
61 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
63 const video2Attributes = {
64 name: 'my super name for server 2',
65 description: 'my super description for server 2'
67 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
69 // Wait videos propagation, server 2 has transcoding enabled
70 await waitJobs(servers)
72 const res = await getVideosList(servers[0].url)
73 const videos = res.body.data
75 expect(videos.length).to.equal(2)
77 servers[0].video = videos.find(video => video.name === 'my super name for server 1')
78 servers[1].video = videos.find(video => video.name === 'my super name for server 2')
81 it('Should not have abuses', async function () {
82 const body = await commands[0].getAdminList()
84 expect(body.total).to.equal(0)
85 expect(body.data).to.be.an('array')
86 expect(body.data.length).to.equal(0)
89 it('Should report abuse on a local video', async function () {
92 const reason = 'my super bad reason'
93 await commands[0].report({ videoId: servers[0].video.id, reason })
95 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
96 await waitJobs(servers)
99 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
101 const body = await commands[0].getAdminList()
103 expect(body.total).to.equal(1)
104 expect(body.data).to.be.an('array')
105 expect(body.data.length).to.equal(1)
107 const abuse = body.data[0]
108 expect(abuse.reason).to.equal('my super bad reason')
110 expect(abuse.reporterAccount.name).to.equal('root')
111 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
113 expect(abuse.video.id).to.equal(servers[0].video.id)
114 expect(abuse.video.channel).to.exist
116 expect(abuse.comment).to.be.null
118 expect(abuse.flaggedAccount.name).to.equal('root')
119 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
121 expect(abuse.video.countReports).to.equal(1)
122 expect(abuse.video.nthReport).to.equal(1)
124 expect(abuse.countReportsForReporter).to.equal(1)
125 expect(abuse.countReportsForReportee).to.equal(1)
129 const body = await commands[1].getAdminList()
130 expect(body.total).to.equal(0)
131 expect(body.data).to.be.an('array')
132 expect(body.data.length).to.equal(0)
136 it('Should report abuse on a remote video', async function () {
139 const reason = 'my super bad reason 2'
140 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
141 await commands[0].report({ videoId, reason })
143 // We wait requests propagation
144 await waitJobs(servers)
147 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
149 const body = await commands[0].getAdminList()
151 expect(body.total).to.equal(2)
152 expect(body.data.length).to.equal(2)
154 const abuse1 = body.data[0]
155 expect(abuse1.reason).to.equal('my super bad reason')
156 expect(abuse1.reporterAccount.name).to.equal('root')
157 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
159 expect(abuse1.video.id).to.equal(servers[0].video.id)
160 expect(abuse1.video.countReports).to.equal(1)
161 expect(abuse1.video.nthReport).to.equal(1)
163 expect(abuse1.comment).to.be.null
165 expect(abuse1.flaggedAccount.name).to.equal('root')
166 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
168 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
169 expect(abuse1.state.label).to.equal('Pending')
170 expect(abuse1.moderationComment).to.be.null
172 const abuse2 = body.data[1]
173 expect(abuse2.reason).to.equal('my super bad reason 2')
175 expect(abuse2.reporterAccount.name).to.equal('root')
176 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
178 expect(abuse2.video.id).to.equal(servers[1].video.id)
180 expect(abuse2.comment).to.be.null
182 expect(abuse2.flaggedAccount.name).to.equal('root')
183 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
185 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
186 expect(abuse2.state.label).to.equal('Pending')
187 expect(abuse2.moderationComment).to.be.null
191 const body = await commands[1].getAdminList()
192 expect(body.total).to.equal(1)
193 expect(body.data.length).to.equal(1)
195 abuseServer2 = body.data[0]
196 expect(abuseServer2.reason).to.equal('my super bad reason 2')
197 expect(abuseServer2.reporterAccount.name).to.equal('root')
198 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
200 expect(abuseServer2.flaggedAccount.name).to.equal('root')
201 expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host)
203 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
204 expect(abuseServer2.state.label).to.equal('Pending')
205 expect(abuseServer2.moderationComment).to.be.null
209 it('Should hide video abuses from blocked accounts', async function () {
213 const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid)
214 await commands[1].report({ videoId, reason: 'will mute this' })
215 await waitJobs(servers)
217 const body = await commands[0].getAdminList()
218 expect(body.total).to.equal(3)
221 const accountToBlock = 'root@' + servers[1].host
224 await servers[0].blocklistCommand.addToServerBlocklist({ account: accountToBlock })
226 const body = await commands[0].getAdminList()
227 expect(body.total).to.equal(2)
229 const abuse = body.data.find(a => a.reason === 'will mute this')
230 expect(abuse).to.be.undefined
234 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: accountToBlock })
236 const body = await commands[0].getAdminList()
237 expect(body.total).to.equal(3)
241 it('Should hide video abuses from blocked servers', async function () {
242 const serverToBlock = servers[1].host
245 await servers[0].blocklistCommand.addToServerBlocklist({ server: serverToBlock })
247 const body = await commands[0].getAdminList()
248 expect(body.total).to.equal(2)
250 const abuse = body.data.find(a => a.reason === 'will mute this')
251 expect(abuse).to.be.undefined
255 await servers[0].blocklistCommand.removeFromServerBlocklist({ server: serverToBlock })
257 const body = await commands[0].getAdminList()
258 expect(body.total).to.equal(3)
262 it('Should keep the video abuse when deleting the video', async function () {
265 await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid)
267 await waitJobs(servers)
269 const body = await commands[1].getAdminList()
270 expect(body.total).to.equal(2, "wrong number of videos returned")
271 expect(body.data).to.have.lengthOf(2, "wrong number of videos returned")
273 const abuse = body.data[0]
274 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video")
275 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
276 expect(abuse.video.channel).to.exist
277 expect(abuse.video.deleted).to.be.true
280 it('Should include counts of reports from reporter and reportee', async function () {
283 // register a second user to have two reporters/reportees
284 const user = { username: 'user2', password: 'password' }
285 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user })
286 const userAccessToken = await userLogin(servers[0], user)
288 // upload a third video via this user
289 const video3Attributes = {
290 name: 'my second super name for server 1',
291 description: 'my second super description for server 1'
293 const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes)
294 const video3Id = resUpload.body.video.id
296 // resume with the test
297 const reason3 = 'my super bad reason 3'
298 await commands[0].report({ videoId: video3Id, reason: reason3 })
300 const reason4 = 'my super bad reason 4'
301 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: reason4 })
304 const body = await commands[0].getAdminList()
305 const abuses = body.data
307 const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
308 expect(abuseVideo3).to.not.be.undefined
309 expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3")
310 expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3")
311 expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse")
312 expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse")
314 const abuseServer1 = abuses.find(a => a.video.id === servers[0].video.id)
315 expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse")
319 it('Should list predefined reasons as well as timestamps for the reported video', async function () {
322 const reason5 = 'my super bad reason 5'
323 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
324 const createRes = await commands[0].report({
325 videoId: servers[0].video.id,
327 predefinedReasons: predefinedReasons5,
332 const body = await commands[0].getAdminList()
335 const abuse = body.data.find(a => a.id === createRes.abuse.id)
336 expect(abuse.reason).to.equals(reason5)
337 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported")
338 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
339 expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
343 it('Should delete the video abuse', async function () {
346 await commands[1].delete({ abuseId: abuseServer2.id })
348 await waitJobs(servers)
351 const body = await commands[1].getAdminList()
352 expect(body.total).to.equal(1)
353 expect(body.data.length).to.equal(1)
354 expect(body.data[0].id).to.not.equal(abuseServer2.id)
358 const body = await commands[0].getAdminList()
359 expect(body.total).to.equal(6)
363 it('Should list and filter video abuses', async function () {
366 async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) {
367 const body = await commands[0].getAdminList(query)
372 expect(await list({ id: 56 })).to.have.lengthOf(0)
373 expect(await list({ id: 1 })).to.have.lengthOf(1)
375 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4)
376 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
378 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
380 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4)
381 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
383 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
384 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5)
386 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5)
387 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
389 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
390 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
392 expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0)
393 expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6)
395 expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1)
396 expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0)
400 describe('Comment abuses', function () {
402 async function getComment (url: string, videoIdArg: number | string) {
403 const videoId = typeof videoIdArg === 'string'
404 ? await getVideoIdFromUUID(url, videoIdArg)
407 const res = await getVideoCommentThreads(url, videoId, 0, 5)
409 return res.body.data[0] as VideoComment
412 before(async function () {
415 servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })
416 servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })
418 await addVideoCommentThread(servers[0].url, servers[0].accessToken, servers[0].video.id, 'comment server 1')
419 await addVideoCommentThread(servers[1].url, servers[1].accessToken, servers[1].video.id, 'comment server 2')
421 await waitJobs(servers)
424 it('Should report abuse on a comment', async function () {
427 const comment = await getComment(servers[0].url, servers[0].video.id)
429 const reason = 'it is a bad comment'
430 await commands[0].report({ commentId: comment.id, reason })
432 await waitJobs(servers)
435 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
437 const comment = await getComment(servers[0].url, servers[0].video.id)
438 const body = await commands[0].getAdminList({ filter: 'comment' })
440 expect(body.total).to.equal(1)
441 expect(body.data).to.have.lengthOf(1)
443 const abuse = body.data[0]
444 expect(abuse.reason).to.equal('it is a bad comment')
446 expect(abuse.reporterAccount.name).to.equal('root')
447 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
449 expect(abuse.video).to.be.null
451 expect(abuse.comment.deleted).to.be.false
452 expect(abuse.comment.id).to.equal(comment.id)
453 expect(abuse.comment.text).to.equal(comment.text)
454 expect(abuse.comment.video.name).to.equal('server 1')
455 expect(abuse.comment.video.id).to.equal(servers[0].video.id)
456 expect(abuse.comment.video.uuid).to.equal(servers[0].video.uuid)
458 expect(abuse.countReportsForReporter).to.equal(5)
459 expect(abuse.countReportsForReportee).to.equal(5)
463 const body = await commands[1].getAdminList({ filter: 'comment' })
464 expect(body.total).to.equal(0)
465 expect(body.data.length).to.equal(0)
469 it('Should report abuse on a remote comment', async function () {
472 const comment = await getComment(servers[0].url, servers[1].video.uuid)
474 const reason = 'it is a really bad comment'
475 await commands[0].report({ commentId: comment.id, reason })
477 await waitJobs(servers)
480 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
481 const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
484 const body = await commands[0].getAdminList({ filter: 'comment' })
485 expect(body.total).to.equal(2)
486 expect(body.data.length).to.equal(2)
488 const abuse = body.data[0]
489 expect(abuse.reason).to.equal('it is a bad comment')
490 expect(abuse.countReportsForReporter).to.equal(6)
491 expect(abuse.countReportsForReportee).to.equal(5)
493 const abuse2 = body.data[1]
495 expect(abuse2.reason).to.equal('it is a really bad comment')
497 expect(abuse2.reporterAccount.name).to.equal('root')
498 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
500 expect(abuse2.video).to.be.null
502 expect(abuse2.comment.deleted).to.be.false
503 expect(abuse2.comment.id).to.equal(commentServer2.id)
504 expect(abuse2.comment.text).to.equal(commentServer2.text)
505 expect(abuse2.comment.video.name).to.equal('server 2')
506 expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid)
508 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
509 expect(abuse2.state.label).to.equal('Pending')
511 expect(abuse2.moderationComment).to.be.null
513 expect(abuse2.countReportsForReporter).to.equal(6)
514 expect(abuse2.countReportsForReportee).to.equal(2)
518 const body = await commands[1].getAdminList({ filter: 'comment' })
519 expect(body.total).to.equal(1)
520 expect(body.data.length).to.equal(1)
522 abuseServer2 = body.data[0]
523 expect(abuseServer2.reason).to.equal('it is a really bad comment')
524 expect(abuseServer2.reporterAccount.name).to.equal('root')
525 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
527 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
528 expect(abuseServer2.state.label).to.equal('Pending')
530 expect(abuseServer2.moderationComment).to.be.null
532 expect(abuseServer2.countReportsForReporter).to.equal(1)
533 expect(abuseServer2.countReportsForReportee).to.equal(1)
537 it('Should keep the comment abuse when deleting the comment', async function () {
540 const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
542 await deleteVideoComment(servers[0].url, servers[0].accessToken, servers[1].video.uuid, commentServer2.id)
544 await waitJobs(servers)
546 const body = await commands[0].getAdminList({ filter: 'comment' })
547 expect(body.total).to.equal(2)
548 expect(body.data).to.have.lengthOf(2)
550 const abuse = body.data.find(a => a.comment?.id === commentServer2.id)
551 expect(abuse).to.not.be.undefined
553 expect(abuse.comment.text).to.be.empty
554 expect(abuse.comment.video.name).to.equal('server 2')
555 expect(abuse.comment.deleted).to.be.true
558 it('Should delete the comment abuse', async function () {
561 await commands[1].delete({ abuseId: abuseServer2.id })
563 await waitJobs(servers)
566 const body = await commands[1].getAdminList({ filter: 'comment' })
567 expect(body.total).to.equal(0)
568 expect(body.data.length).to.equal(0)
572 const body = await commands[0].getAdminList({ filter: 'comment' })
573 expect(body.total).to.equal(2)
577 it('Should list and filter video abuses', async function () {
579 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' })
580 expect(body.total).to.equal(0)
584 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' })
585 expect(body.total).to.equal(2)
589 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' })
590 expect(body.data).to.have.lengthOf(1)
591 expect(body.data[0].comment.text).to.be.empty
595 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' })
596 expect(body.data).to.have.lengthOf(1)
597 expect(body.data[0].comment.text).to.equal('comment server 1')
602 describe('Account abuses', function () {
604 function getAccountFromServer (server: ServerInfo, targetName: string, targetServer: ServerInfo) {
605 return server.accountsCommand.get({ accountName: targetName + '@' + targetServer.host })
608 before(async function () {
611 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' })
613 const token = await generateUserAccessToken(servers[1], 'user_2')
614 await uploadVideo(servers[1].url, token, { name: 'super video' })
616 await waitJobs(servers)
619 it('Should report abuse on an account', async function () {
622 const account = await getAccountFromServer(servers[0], 'user_1', servers[0])
624 const reason = 'it is a bad account'
625 await commands[0].report({ accountId: account.id, reason })
627 await waitJobs(servers)
630 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
632 const body = await commands[0].getAdminList({ filter: 'account' })
634 expect(body.total).to.equal(1)
635 expect(body.data).to.have.lengthOf(1)
637 const abuse = body.data[0]
638 expect(abuse.reason).to.equal('it is a bad account')
640 expect(abuse.reporterAccount.name).to.equal('root')
641 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
643 expect(abuse.video).to.be.null
644 expect(abuse.comment).to.be.null
646 expect(abuse.flaggedAccount.name).to.equal('user_1')
647 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
651 const body = await commands[1].getAdminList({ filter: 'comment' })
652 expect(body.total).to.equal(0)
653 expect(body.data.length).to.equal(0)
657 it('Should report abuse on a remote account', async function () {
660 const account = await getAccountFromServer(servers[0], 'user_2', servers[1])
662 const reason = 'it is a really bad account'
663 await commands[0].report({ accountId: account.id, reason })
665 await waitJobs(servers)
668 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
670 const body = await commands[0].getAdminList({ filter: 'account' })
671 expect(body.total).to.equal(2)
672 expect(body.data.length).to.equal(2)
674 const abuse: AdminAbuse = body.data[0]
675 expect(abuse.reason).to.equal('it is a bad account')
677 const abuse2: AdminAbuse = body.data[1]
678 expect(abuse2.reason).to.equal('it is a really bad account')
680 expect(abuse2.reporterAccount.name).to.equal('root')
681 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
683 expect(abuse2.video).to.be.null
684 expect(abuse2.comment).to.be.null
686 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
687 expect(abuse2.state.label).to.equal('Pending')
689 expect(abuse2.moderationComment).to.be.null
693 const body = await commands[1].getAdminList({ filter: 'account' })
694 expect(body.total).to.equal(1)
695 expect(body.data.length).to.equal(1)
697 abuseServer2 = body.data[0]
699 expect(abuseServer2.reason).to.equal('it is a really bad account')
701 expect(abuseServer2.reporterAccount.name).to.equal('root')
702 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
704 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
705 expect(abuseServer2.state.label).to.equal('Pending')
707 expect(abuseServer2.moderationComment).to.be.null
711 it('Should keep the account abuse when deleting the account', async function () {
714 const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
715 await removeUser(servers[1].url, account.userId, servers[1].accessToken)
717 await waitJobs(servers)
719 const body = await commands[0].getAdminList({ filter: 'account' })
720 expect(body.total).to.equal(2)
721 expect(body.data).to.have.lengthOf(2)
723 const abuse = body.data.find(a => a.reason === 'it is a really bad account')
724 expect(abuse).to.not.be.undefined
727 it('Should delete the account abuse', async function () {
730 await commands[1].delete({ abuseId: abuseServer2.id })
732 await waitJobs(servers)
735 const body = await commands[1].getAdminList({ filter: 'account' })
736 expect(body.total).to.equal(0)
737 expect(body.data.length).to.equal(0)
741 const body = await commands[0].getAdminList({ filter: 'account' })
742 expect(body.total).to.equal(2)
744 abuseServer1 = body.data[0]
749 describe('Common actions on abuses', function () {
751 it('Should update the state of an abuse', async function () {
752 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } })
754 const body = await commands[0].getAdminList({ id: abuseServer1.id })
755 expect(body.data[0].state.id).to.equal(AbuseState.REJECTED)
758 it('Should add a moderation comment', async function () {
759 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } })
761 const body = await commands[0].getAdminList({ id: abuseServer1.id })
762 expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
763 expect(body.data[0].moderationComment).to.equal('Valid')
767 describe('My abuses', async function () {
769 let userAccessToken: string
771 before(async function () {
772 userAccessToken = await generateUserAccessToken(servers[0], 'user_42')
774 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
776 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
777 await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
780 it('Should correctly list my abuses', async function () {
782 const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
783 expect(body.total).to.equal(2)
785 const abuses = body.data
786 expect(abuses[0].reason).to.equal('user reason 1')
787 expect(abuses[1].reason).to.equal('user reason 2')
789 abuseId1 = abuses[0].id
793 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
794 expect(body.total).to.equal(2)
796 const abuses: UserAbuse[] = body.data
797 expect(abuses[0].reason).to.equal('user reason 2')
801 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
802 expect(body.total).to.equal(2)
804 const abuses: UserAbuse[] = body.data
805 expect(abuses[0].reason).to.equal('user reason 1')
809 it('Should correctly filter my abuses by id', async function () {
810 const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 })
811 expect(body.total).to.equal(1)
813 const abuses: UserAbuse[] = body.data
814 expect(abuses[0].reason).to.equal('user reason 1')
817 it('Should correctly filter my abuses by search', async function () {
818 const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' })
819 expect(body.total).to.equal(1)
821 const abuses: UserAbuse[] = body.data
822 expect(abuses[0].reason).to.equal('user reason 2')
825 it('Should correctly filter my abuses by state', async function () {
826 await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } })
828 const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED })
829 expect(body.total).to.equal(1)
831 const abuses: UserAbuse[] = body.data
832 expect(abuses[0].reason).to.equal('user reason 1')
836 describe('Abuse messages', async function () {
838 let userToken: string
839 let abuseMessageUserId: number
840 let abuseMessageModerationId: number
842 before(async function () {
843 userToken = await generateUserAccessToken(servers[0], 'user_43')
845 const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' })
846 abuseId = body.abuse.id
849 it('Should create some messages on the abuse', async function () {
850 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' })
851 await commands[0].addMessage({ abuseId, message: 'message 2' })
852 await commands[0].addMessage({ abuseId, message: 'message 3' })
853 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' })
856 it('Should have the correct messages count when listing abuses', async function () {
857 const results = await Promise.all([
858 commands[0].getAdminList({ start: 0, count: 50 }),
859 commands[0].getUserList({ token: userToken, start: 0, count: 50 })
862 for (const body of results) {
863 const abuses = body.data
864 const abuse = abuses.find(a => a.id === abuseId)
865 expect(abuse.countMessages).to.equal(4)
869 it('Should correctly list messages of this abuse', async function () {
870 const results = await Promise.all([
871 commands[0].listMessages({ abuseId }),
872 commands[0].listMessages({ token: userToken, abuseId })
875 for (const body of results) {
876 expect(body.total).to.equal(4)
878 const abuseMessages: AbuseMessage[] = body.data
880 expect(abuseMessages[0].message).to.equal('message 1')
881 expect(abuseMessages[0].byModerator).to.be.false
882 expect(abuseMessages[0].account.name).to.equal('user_43')
884 abuseMessageUserId = abuseMessages[0].id
886 expect(abuseMessages[1].message).to.equal('message 2')
887 expect(abuseMessages[1].byModerator).to.be.true
888 expect(abuseMessages[1].account.name).to.equal('root')
890 expect(abuseMessages[2].message).to.equal('message 3')
891 expect(abuseMessages[2].byModerator).to.be.true
892 expect(abuseMessages[2].account.name).to.equal('root')
893 abuseMessageModerationId = abuseMessages[2].id
895 expect(abuseMessages[3].message).to.equal('message 4')
896 expect(abuseMessages[3].byModerator).to.be.false
897 expect(abuseMessages[3].account.name).to.equal('user_43')
901 it('Should delete messages', async function () {
902 await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId })
903 await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId })
905 const results = await Promise.all([
906 commands[0].listMessages({ abuseId }),
907 commands[0].listMessages({ token: userToken, abuseId })
910 for (const body of results) {
911 expect(body.total).to.equal(2)
913 const abuseMessages: AbuseMessage[] = body.data
914 expect(abuseMessages[0].message).to.equal('message 2')
915 expect(abuseMessages[1].message).to.equal('message 4')
920 after(async function () {
921 await cleanupTests(servers)