1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
10 flushAndRunMultipleServers,
11 generateUserAccessToken,
17 setAccessTokensToServers,
22 } from '@shared/extra-utils'
23 import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
25 const expect = chai.expect
27 describe('Test abuses', function () {
28 let servers: ServerInfo[] = []
29 let abuseServer1: AdminAbuse
30 let abuseServer2: AdminAbuse
31 let commands: AbusesCommand[]
33 before(async function () {
37 servers = await flushAndRunMultipleServers(2)
39 // Get the access tokens
40 await setAccessTokensToServers(servers)
42 // Server 1 and server 2 follow each other
43 await doubleFollow(servers[0], servers[1])
45 commands = servers.map(s => s.abusesCommand)
48 describe('Video abuses', function () {
50 before(async function () {
53 // Upload some videos on each servers
54 const video1Attributes = {
55 name: 'my super name for server 1',
56 description: 'my super description for server 1'
58 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
60 const video2Attributes = {
61 name: 'my super name for server 2',
62 description: 'my super description for server 2'
64 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
66 // Wait videos propagation, server 2 has transcoding enabled
67 await waitJobs(servers)
69 const res = await getVideosList(servers[0].url)
70 const videos = res.body.data
72 expect(videos.length).to.equal(2)
74 servers[0].video = videos.find(video => video.name === 'my super name for server 1')
75 servers[1].video = videos.find(video => video.name === 'my super name for server 2')
78 it('Should not have abuses', async function () {
79 const body = await commands[0].getAdminList()
81 expect(body.total).to.equal(0)
82 expect(body.data).to.be.an('array')
83 expect(body.data.length).to.equal(0)
86 it('Should report abuse on a local video', async function () {
89 const reason = 'my super bad reason'
90 await commands[0].report({ videoId: servers[0].video.id, reason })
92 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
93 await waitJobs(servers)
96 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
98 const body = await commands[0].getAdminList()
100 expect(body.total).to.equal(1)
101 expect(body.data).to.be.an('array')
102 expect(body.data.length).to.equal(1)
104 const abuse = body.data[0]
105 expect(abuse.reason).to.equal('my super bad reason')
107 expect(abuse.reporterAccount.name).to.equal('root')
108 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
110 expect(abuse.video.id).to.equal(servers[0].video.id)
111 expect(abuse.video.channel).to.exist
113 expect(abuse.comment).to.be.null
115 expect(abuse.flaggedAccount.name).to.equal('root')
116 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
118 expect(abuse.video.countReports).to.equal(1)
119 expect(abuse.video.nthReport).to.equal(1)
121 expect(abuse.countReportsForReporter).to.equal(1)
122 expect(abuse.countReportsForReportee).to.equal(1)
126 const body = await commands[1].getAdminList()
127 expect(body.total).to.equal(0)
128 expect(body.data).to.be.an('array')
129 expect(body.data.length).to.equal(0)
133 it('Should report abuse on a remote video', async function () {
136 const reason = 'my super bad reason 2'
137 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
138 await commands[0].report({ videoId, reason })
140 // We wait requests propagation
141 await waitJobs(servers)
144 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
146 const body = await commands[0].getAdminList()
148 expect(body.total).to.equal(2)
149 expect(body.data.length).to.equal(2)
151 const abuse1 = body.data[0]
152 expect(abuse1.reason).to.equal('my super bad reason')
153 expect(abuse1.reporterAccount.name).to.equal('root')
154 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
156 expect(abuse1.video.id).to.equal(servers[0].video.id)
157 expect(abuse1.video.countReports).to.equal(1)
158 expect(abuse1.video.nthReport).to.equal(1)
160 expect(abuse1.comment).to.be.null
162 expect(abuse1.flaggedAccount.name).to.equal('root')
163 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
165 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
166 expect(abuse1.state.label).to.equal('Pending')
167 expect(abuse1.moderationComment).to.be.null
169 const abuse2 = body.data[1]
170 expect(abuse2.reason).to.equal('my super bad reason 2')
172 expect(abuse2.reporterAccount.name).to.equal('root')
173 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
175 expect(abuse2.video.id).to.equal(servers[1].video.id)
177 expect(abuse2.comment).to.be.null
179 expect(abuse2.flaggedAccount.name).to.equal('root')
180 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
182 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
183 expect(abuse2.state.label).to.equal('Pending')
184 expect(abuse2.moderationComment).to.be.null
188 const body = await commands[1].getAdminList()
189 expect(body.total).to.equal(1)
190 expect(body.data.length).to.equal(1)
192 abuseServer2 = body.data[0]
193 expect(abuseServer2.reason).to.equal('my super bad reason 2')
194 expect(abuseServer2.reporterAccount.name).to.equal('root')
195 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
197 expect(abuseServer2.flaggedAccount.name).to.equal('root')
198 expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host)
200 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
201 expect(abuseServer2.state.label).to.equal('Pending')
202 expect(abuseServer2.moderationComment).to.be.null
206 it('Should hide video abuses from blocked accounts', async function () {
210 const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid)
211 await commands[1].report({ videoId, reason: 'will mute this' })
212 await waitJobs(servers)
214 const body = await commands[0].getAdminList()
215 expect(body.total).to.equal(3)
218 const accountToBlock = 'root@' + servers[1].host
221 await servers[0].blocklistCommand.addToServerBlocklist({ account: accountToBlock })
223 const body = await commands[0].getAdminList()
224 expect(body.total).to.equal(2)
226 const abuse = body.data.find(a => a.reason === 'will mute this')
227 expect(abuse).to.be.undefined
231 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: accountToBlock })
233 const body = await commands[0].getAdminList()
234 expect(body.total).to.equal(3)
238 it('Should hide video abuses from blocked servers', async function () {
239 const serverToBlock = servers[1].host
242 await servers[0].blocklistCommand.addToServerBlocklist({ server: serverToBlock })
244 const body = await commands[0].getAdminList()
245 expect(body.total).to.equal(2)
247 const abuse = body.data.find(a => a.reason === 'will mute this')
248 expect(abuse).to.be.undefined
252 await servers[0].blocklistCommand.removeFromServerBlocklist({ server: serverToBlock })
254 const body = await commands[0].getAdminList()
255 expect(body.total).to.equal(3)
259 it('Should keep the video abuse when deleting the video', async function () {
262 await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid)
264 await waitJobs(servers)
266 const body = await commands[1].getAdminList()
267 expect(body.total).to.equal(2, "wrong number of videos returned")
268 expect(body.data).to.have.lengthOf(2, "wrong number of videos returned")
270 const abuse = body.data[0]
271 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video")
272 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
273 expect(abuse.video.channel).to.exist
274 expect(abuse.video.deleted).to.be.true
277 it('Should include counts of reports from reporter and reportee', async function () {
280 // register a second user to have two reporters/reportees
281 const user = { username: 'user2', password: 'password' }
282 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user })
283 const userAccessToken = await userLogin(servers[0], user)
285 // upload a third video via this user
286 const video3Attributes = {
287 name: 'my second super name for server 1',
288 description: 'my second super description for server 1'
290 const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes)
291 const video3Id = resUpload.body.video.id
293 // resume with the test
294 const reason3 = 'my super bad reason 3'
295 await commands[0].report({ videoId: video3Id, reason: reason3 })
297 const reason4 = 'my super bad reason 4'
298 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: reason4 })
301 const body = await commands[0].getAdminList()
302 const abuses = body.data
304 const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
305 expect(abuseVideo3).to.not.be.undefined
306 expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3")
307 expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3")
308 expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse")
309 expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse")
311 const abuseServer1 = abuses.find(a => a.video.id === servers[0].video.id)
312 expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse")
316 it('Should list predefined reasons as well as timestamps for the reported video', async function () {
319 const reason5 = 'my super bad reason 5'
320 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
321 const createRes = await commands[0].report({
322 videoId: servers[0].video.id,
324 predefinedReasons: predefinedReasons5,
329 const body = await commands[0].getAdminList()
332 const abuse = body.data.find(a => a.id === createRes.abuse.id)
333 expect(abuse.reason).to.equals(reason5)
334 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported")
335 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
336 expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
340 it('Should delete the video abuse', async function () {
343 await commands[1].delete({ abuseId: abuseServer2.id })
345 await waitJobs(servers)
348 const body = await commands[1].getAdminList()
349 expect(body.total).to.equal(1)
350 expect(body.data.length).to.equal(1)
351 expect(body.data[0].id).to.not.equal(abuseServer2.id)
355 const body = await commands[0].getAdminList()
356 expect(body.total).to.equal(6)
360 it('Should list and filter video abuses', async function () {
363 async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) {
364 const body = await commands[0].getAdminList(query)
369 expect(await list({ id: 56 })).to.have.lengthOf(0)
370 expect(await list({ id: 1 })).to.have.lengthOf(1)
372 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4)
373 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
375 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
377 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4)
378 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
380 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
381 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5)
383 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5)
384 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
386 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
387 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
389 expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0)
390 expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6)
392 expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1)
393 expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0)
397 describe('Comment abuses', function () {
399 async function getComment (server: ServerInfo, videoIdArg: number | string) {
400 const videoId = typeof videoIdArg === 'string'
401 ? await getVideoIdFromUUID(server.url, videoIdArg)
404 const { data } = await server.commentsCommand.listThreads({ videoId })
409 before(async function () {
412 servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })
413 servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })
415 await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' })
416 await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' })
418 await waitJobs(servers)
421 it('Should report abuse on a comment', async function () {
424 const comment = await getComment(servers[0], servers[0].video.id)
426 const reason = 'it is a bad comment'
427 await commands[0].report({ commentId: comment.id, reason })
429 await waitJobs(servers)
432 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
434 const comment = await getComment(servers[0], servers[0].video.id)
435 const body = await commands[0].getAdminList({ filter: 'comment' })
437 expect(body.total).to.equal(1)
438 expect(body.data).to.have.lengthOf(1)
440 const abuse = body.data[0]
441 expect(abuse.reason).to.equal('it is a bad comment')
443 expect(abuse.reporterAccount.name).to.equal('root')
444 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
446 expect(abuse.video).to.be.null
448 expect(abuse.comment.deleted).to.be.false
449 expect(abuse.comment.id).to.equal(comment.id)
450 expect(abuse.comment.text).to.equal(comment.text)
451 expect(abuse.comment.video.name).to.equal('server 1')
452 expect(abuse.comment.video.id).to.equal(servers[0].video.id)
453 expect(abuse.comment.video.uuid).to.equal(servers[0].video.uuid)
455 expect(abuse.countReportsForReporter).to.equal(5)
456 expect(abuse.countReportsForReportee).to.equal(5)
460 const body = await commands[1].getAdminList({ filter: 'comment' })
461 expect(body.total).to.equal(0)
462 expect(body.data.length).to.equal(0)
466 it('Should report abuse on a remote comment', async function () {
469 const comment = await getComment(servers[0], servers[1].video.uuid)
471 const reason = 'it is a really bad comment'
472 await commands[0].report({ commentId: comment.id, reason })
474 await waitJobs(servers)
477 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
478 const commentServer2 = await getComment(servers[0], servers[1].video.id)
481 const body = await commands[0].getAdminList({ filter: 'comment' })
482 expect(body.total).to.equal(2)
483 expect(body.data.length).to.equal(2)
485 const abuse = body.data[0]
486 expect(abuse.reason).to.equal('it is a bad comment')
487 expect(abuse.countReportsForReporter).to.equal(6)
488 expect(abuse.countReportsForReportee).to.equal(5)
490 const abuse2 = body.data[1]
492 expect(abuse2.reason).to.equal('it is a really bad comment')
494 expect(abuse2.reporterAccount.name).to.equal('root')
495 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
497 expect(abuse2.video).to.be.null
499 expect(abuse2.comment.deleted).to.be.false
500 expect(abuse2.comment.id).to.equal(commentServer2.id)
501 expect(abuse2.comment.text).to.equal(commentServer2.text)
502 expect(abuse2.comment.video.name).to.equal('server 2')
503 expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid)
505 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
506 expect(abuse2.state.label).to.equal('Pending')
508 expect(abuse2.moderationComment).to.be.null
510 expect(abuse2.countReportsForReporter).to.equal(6)
511 expect(abuse2.countReportsForReportee).to.equal(2)
515 const body = await commands[1].getAdminList({ filter: 'comment' })
516 expect(body.total).to.equal(1)
517 expect(body.data.length).to.equal(1)
519 abuseServer2 = body.data[0]
520 expect(abuseServer2.reason).to.equal('it is a really bad comment')
521 expect(abuseServer2.reporterAccount.name).to.equal('root')
522 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
524 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
525 expect(abuseServer2.state.label).to.equal('Pending')
527 expect(abuseServer2.moderationComment).to.be.null
529 expect(abuseServer2.countReportsForReporter).to.equal(1)
530 expect(abuseServer2.countReportsForReportee).to.equal(1)
534 it('Should keep the comment abuse when deleting the comment', async function () {
537 const commentServer2 = await getComment(servers[0], servers[1].video.id)
539 await servers[0].commentsCommand.delete({ videoId: servers[1].video.uuid, commentId: commentServer2.id })
541 await waitJobs(servers)
543 const body = await commands[0].getAdminList({ filter: 'comment' })
544 expect(body.total).to.equal(2)
545 expect(body.data).to.have.lengthOf(2)
547 const abuse = body.data.find(a => a.comment?.id === commentServer2.id)
548 expect(abuse).to.not.be.undefined
550 expect(abuse.comment.text).to.be.empty
551 expect(abuse.comment.video.name).to.equal('server 2')
552 expect(abuse.comment.deleted).to.be.true
555 it('Should delete the comment abuse', async function () {
558 await commands[1].delete({ abuseId: abuseServer2.id })
560 await waitJobs(servers)
563 const body = await commands[1].getAdminList({ filter: 'comment' })
564 expect(body.total).to.equal(0)
565 expect(body.data.length).to.equal(0)
569 const body = await commands[0].getAdminList({ filter: 'comment' })
570 expect(body.total).to.equal(2)
574 it('Should list and filter video abuses', async function () {
576 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' })
577 expect(body.total).to.equal(0)
581 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' })
582 expect(body.total).to.equal(2)
586 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' })
587 expect(body.data).to.have.lengthOf(1)
588 expect(body.data[0].comment.text).to.be.empty
592 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' })
593 expect(body.data).to.have.lengthOf(1)
594 expect(body.data[0].comment.text).to.equal('comment server 1')
599 describe('Account abuses', function () {
601 function getAccountFromServer (server: ServerInfo, targetName: string, targetServer: ServerInfo) {
602 return server.accountsCommand.get({ accountName: targetName + '@' + targetServer.host })
605 before(async function () {
608 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' })
610 const token = await generateUserAccessToken(servers[1], 'user_2')
611 await uploadVideo(servers[1].url, token, { name: 'super video' })
613 await waitJobs(servers)
616 it('Should report abuse on an account', async function () {
619 const account = await getAccountFromServer(servers[0], 'user_1', servers[0])
621 const reason = 'it is a bad account'
622 await commands[0].report({ accountId: account.id, reason })
624 await waitJobs(servers)
627 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
629 const body = await commands[0].getAdminList({ filter: 'account' })
631 expect(body.total).to.equal(1)
632 expect(body.data).to.have.lengthOf(1)
634 const abuse = body.data[0]
635 expect(abuse.reason).to.equal('it is a bad account')
637 expect(abuse.reporterAccount.name).to.equal('root')
638 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
640 expect(abuse.video).to.be.null
641 expect(abuse.comment).to.be.null
643 expect(abuse.flaggedAccount.name).to.equal('user_1')
644 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
648 const body = await commands[1].getAdminList({ filter: 'comment' })
649 expect(body.total).to.equal(0)
650 expect(body.data.length).to.equal(0)
654 it('Should report abuse on a remote account', async function () {
657 const account = await getAccountFromServer(servers[0], 'user_2', servers[1])
659 const reason = 'it is a really bad account'
660 await commands[0].report({ accountId: account.id, reason })
662 await waitJobs(servers)
665 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
667 const body = await commands[0].getAdminList({ filter: 'account' })
668 expect(body.total).to.equal(2)
669 expect(body.data.length).to.equal(2)
671 const abuse: AdminAbuse = body.data[0]
672 expect(abuse.reason).to.equal('it is a bad account')
674 const abuse2: AdminAbuse = body.data[1]
675 expect(abuse2.reason).to.equal('it is a really bad account')
677 expect(abuse2.reporterAccount.name).to.equal('root')
678 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
680 expect(abuse2.video).to.be.null
681 expect(abuse2.comment).to.be.null
683 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
684 expect(abuse2.state.label).to.equal('Pending')
686 expect(abuse2.moderationComment).to.be.null
690 const body = await commands[1].getAdminList({ filter: 'account' })
691 expect(body.total).to.equal(1)
692 expect(body.data.length).to.equal(1)
694 abuseServer2 = body.data[0]
696 expect(abuseServer2.reason).to.equal('it is a really bad account')
698 expect(abuseServer2.reporterAccount.name).to.equal('root')
699 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
701 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
702 expect(abuseServer2.state.label).to.equal('Pending')
704 expect(abuseServer2.moderationComment).to.be.null
708 it('Should keep the account abuse when deleting the account', async function () {
711 const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
712 await removeUser(servers[1].url, account.userId, servers[1].accessToken)
714 await waitJobs(servers)
716 const body = await commands[0].getAdminList({ filter: 'account' })
717 expect(body.total).to.equal(2)
718 expect(body.data).to.have.lengthOf(2)
720 const abuse = body.data.find(a => a.reason === 'it is a really bad account')
721 expect(abuse).to.not.be.undefined
724 it('Should delete the account abuse', async function () {
727 await commands[1].delete({ abuseId: abuseServer2.id })
729 await waitJobs(servers)
732 const body = await commands[1].getAdminList({ filter: 'account' })
733 expect(body.total).to.equal(0)
734 expect(body.data.length).to.equal(0)
738 const body = await commands[0].getAdminList({ filter: 'account' })
739 expect(body.total).to.equal(2)
741 abuseServer1 = body.data[0]
746 describe('Common actions on abuses', function () {
748 it('Should update the state of an abuse', async function () {
749 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } })
751 const body = await commands[0].getAdminList({ id: abuseServer1.id })
752 expect(body.data[0].state.id).to.equal(AbuseState.REJECTED)
755 it('Should add a moderation comment', async function () {
756 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } })
758 const body = await commands[0].getAdminList({ id: abuseServer1.id })
759 expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
760 expect(body.data[0].moderationComment).to.equal('Valid')
764 describe('My abuses', async function () {
766 let userAccessToken: string
768 before(async function () {
769 userAccessToken = await generateUserAccessToken(servers[0], 'user_42')
771 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
773 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
774 await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
777 it('Should correctly list my abuses', async function () {
779 const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
780 expect(body.total).to.equal(2)
782 const abuses = body.data
783 expect(abuses[0].reason).to.equal('user reason 1')
784 expect(abuses[1].reason).to.equal('user reason 2')
786 abuseId1 = abuses[0].id
790 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
791 expect(body.total).to.equal(2)
793 const abuses: UserAbuse[] = body.data
794 expect(abuses[0].reason).to.equal('user reason 2')
798 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
799 expect(body.total).to.equal(2)
801 const abuses: UserAbuse[] = body.data
802 expect(abuses[0].reason).to.equal('user reason 1')
806 it('Should correctly filter my abuses by id', async function () {
807 const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 })
808 expect(body.total).to.equal(1)
810 const abuses: UserAbuse[] = body.data
811 expect(abuses[0].reason).to.equal('user reason 1')
814 it('Should correctly filter my abuses by search', async function () {
815 const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' })
816 expect(body.total).to.equal(1)
818 const abuses: UserAbuse[] = body.data
819 expect(abuses[0].reason).to.equal('user reason 2')
822 it('Should correctly filter my abuses by state', async function () {
823 await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } })
825 const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED })
826 expect(body.total).to.equal(1)
828 const abuses: UserAbuse[] = body.data
829 expect(abuses[0].reason).to.equal('user reason 1')
833 describe('Abuse messages', async function () {
835 let userToken: string
836 let abuseMessageUserId: number
837 let abuseMessageModerationId: number
839 before(async function () {
840 userToken = await generateUserAccessToken(servers[0], 'user_43')
842 const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' })
843 abuseId = body.abuse.id
846 it('Should create some messages on the abuse', async function () {
847 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' })
848 await commands[0].addMessage({ abuseId, message: 'message 2' })
849 await commands[0].addMessage({ abuseId, message: 'message 3' })
850 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' })
853 it('Should have the correct messages count when listing abuses', async function () {
854 const results = await Promise.all([
855 commands[0].getAdminList({ start: 0, count: 50 }),
856 commands[0].getUserList({ token: userToken, start: 0, count: 50 })
859 for (const body of results) {
860 const abuses = body.data
861 const abuse = abuses.find(a => a.id === abuseId)
862 expect(abuse.countMessages).to.equal(4)
866 it('Should correctly list messages of this abuse', async function () {
867 const results = await Promise.all([
868 commands[0].listMessages({ abuseId }),
869 commands[0].listMessages({ token: userToken, abuseId })
872 for (const body of results) {
873 expect(body.total).to.equal(4)
875 const abuseMessages: AbuseMessage[] = body.data
877 expect(abuseMessages[0].message).to.equal('message 1')
878 expect(abuseMessages[0].byModerator).to.be.false
879 expect(abuseMessages[0].account.name).to.equal('user_43')
881 abuseMessageUserId = abuseMessages[0].id
883 expect(abuseMessages[1].message).to.equal('message 2')
884 expect(abuseMessages[1].byModerator).to.be.true
885 expect(abuseMessages[1].account.name).to.equal('root')
887 expect(abuseMessages[2].message).to.equal('message 3')
888 expect(abuseMessages[2].byModerator).to.be.true
889 expect(abuseMessages[2].account.name).to.equal('root')
890 abuseMessageModerationId = abuseMessages[2].id
892 expect(abuseMessages[3].message).to.equal('message 4')
893 expect(abuseMessages[3].byModerator).to.be.false
894 expect(abuseMessages[3].account.name).to.equal('user_43')
898 it('Should delete messages', async function () {
899 await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId })
900 await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId })
902 const results = await Promise.all([
903 commands[0].listMessages({ abuseId }),
904 commands[0].listMessages({ token: userToken, abuseId })
907 for (const body of results) {
908 expect(body.total).to.equal(2)
910 const abuseMessages: AbuseMessage[] = body.data
911 expect(abuseMessages[0].message).to.equal('message 2')
912 expect(abuseMessages[1].message).to.equal('message 4')
917 after(async function () {
918 await cleanupTests(servers)