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,
17 getVideoCommentThreads,
20 removeAccountFromServerBlocklist,
21 removeServerFromServerBlocklist,
25 setAccessTokensToServers,
30 } from '@shared/extra-utils'
31 import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, Account, AdminAbuse, UserAbuse, VideoComment } from '@shared/models'
33 const expect = chai.expect
35 describe('Test abuses', function () {
36 let servers: ServerInfo[] = []
37 let abuseServer1: AdminAbuse
38 let abuseServer2: AdminAbuse
39 let commands: AbusesCommand[]
41 before(async function () {
45 servers = await flushAndRunMultipleServers(2)
47 // Get the access tokens
48 await setAccessTokensToServers(servers)
50 // Server 1 and server 2 follow each other
51 await doubleFollow(servers[0], servers[1])
53 commands = servers.map(s => s.abusesCommand)
56 describe('Video abuses', function () {
58 before(async function () {
61 // Upload some videos on each servers
62 const video1Attributes = {
63 name: 'my super name for server 1',
64 description: 'my super description for server 1'
66 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
68 const video2Attributes = {
69 name: 'my super name for server 2',
70 description: 'my super description for server 2'
72 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
74 // Wait videos propagation, server 2 has transcoding enabled
75 await waitJobs(servers)
77 const res = await getVideosList(servers[0].url)
78 const videos = res.body.data
80 expect(videos.length).to.equal(2)
82 servers[0].video = videos.find(video => video.name === 'my super name for server 1')
83 servers[1].video = videos.find(video => video.name === 'my super name for server 2')
86 it('Should not have abuses', async function () {
87 const body = await commands[0].getAdminList()
89 expect(body.total).to.equal(0)
90 expect(body.data).to.be.an('array')
91 expect(body.data.length).to.equal(0)
94 it('Should report abuse on a local video', async function () {
97 const reason = 'my super bad reason'
98 await commands[0].report({ videoId: servers[0].video.id, reason })
100 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
101 await waitJobs(servers)
104 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
106 const body = await commands[0].getAdminList()
108 expect(body.total).to.equal(1)
109 expect(body.data).to.be.an('array')
110 expect(body.data.length).to.equal(1)
112 const abuse = body.data[0]
113 expect(abuse.reason).to.equal('my super bad reason')
115 expect(abuse.reporterAccount.name).to.equal('root')
116 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
118 expect(abuse.video.id).to.equal(servers[0].video.id)
119 expect(abuse.video.channel).to.exist
121 expect(abuse.comment).to.be.null
123 expect(abuse.flaggedAccount.name).to.equal('root')
124 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
126 expect(abuse.video.countReports).to.equal(1)
127 expect(abuse.video.nthReport).to.equal(1)
129 expect(abuse.countReportsForReporter).to.equal(1)
130 expect(abuse.countReportsForReportee).to.equal(1)
134 const body = await commands[1].getAdminList()
135 expect(body.total).to.equal(0)
136 expect(body.data).to.be.an('array')
137 expect(body.data.length).to.equal(0)
141 it('Should report abuse on a remote video', async function () {
144 const reason = 'my super bad reason 2'
145 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
146 await commands[0].report({ videoId, reason })
148 // We wait requests propagation
149 await waitJobs(servers)
152 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
154 const body = await commands[0].getAdminList()
156 expect(body.total).to.equal(2)
157 expect(body.data.length).to.equal(2)
159 const abuse1 = body.data[0]
160 expect(abuse1.reason).to.equal('my super bad reason')
161 expect(abuse1.reporterAccount.name).to.equal('root')
162 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
164 expect(abuse1.video.id).to.equal(servers[0].video.id)
165 expect(abuse1.video.countReports).to.equal(1)
166 expect(abuse1.video.nthReport).to.equal(1)
168 expect(abuse1.comment).to.be.null
170 expect(abuse1.flaggedAccount.name).to.equal('root')
171 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
173 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
174 expect(abuse1.state.label).to.equal('Pending')
175 expect(abuse1.moderationComment).to.be.null
177 const abuse2 = body.data[1]
178 expect(abuse2.reason).to.equal('my super bad reason 2')
180 expect(abuse2.reporterAccount.name).to.equal('root')
181 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
183 expect(abuse2.video.id).to.equal(servers[1].video.id)
185 expect(abuse2.comment).to.be.null
187 expect(abuse2.flaggedAccount.name).to.equal('root')
188 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
190 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
191 expect(abuse2.state.label).to.equal('Pending')
192 expect(abuse2.moderationComment).to.be.null
196 const body = await commands[1].getAdminList()
197 expect(body.total).to.equal(1)
198 expect(body.data.length).to.equal(1)
200 abuseServer2 = body.data[0]
201 expect(abuseServer2.reason).to.equal('my super bad reason 2')
202 expect(abuseServer2.reporterAccount.name).to.equal('root')
203 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
205 expect(abuseServer2.flaggedAccount.name).to.equal('root')
206 expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host)
208 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
209 expect(abuseServer2.state.label).to.equal('Pending')
210 expect(abuseServer2.moderationComment).to.be.null
214 it('Should hide video abuses from blocked accounts', async function () {
218 const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid)
219 await commands[1].report({ videoId, reason: 'will mute this' })
220 await waitJobs(servers)
222 const body = await commands[0].getAdminList()
223 expect(body.total).to.equal(3)
226 const accountToBlock = 'root@' + servers[1].host
229 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
231 const body = await commands[0].getAdminList()
232 expect(body.total).to.equal(2)
234 const abuse = body.data.find(a => a.reason === 'will mute this')
235 expect(abuse).to.be.undefined
239 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
241 const body = await commands[0].getAdminList()
242 expect(body.total).to.equal(3)
246 it('Should hide video abuses from blocked servers', async function () {
247 const serverToBlock = servers[1].host
250 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)
252 const body = await commands[0].getAdminList()
253 expect(body.total).to.equal(2)
255 const abuse = body.data.find(a => a.reason === 'will mute this')
256 expect(abuse).to.be.undefined
260 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock)
262 const body = await commands[0].getAdminList()
263 expect(body.total).to.equal(3)
267 it('Should keep the video abuse when deleting the video', async function () {
270 await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid)
272 await waitJobs(servers)
274 const body = await commands[1].getAdminList()
275 expect(body.total).to.equal(2, "wrong number of videos returned")
276 expect(body.data).to.have.lengthOf(2, "wrong number of videos returned")
278 const abuse = body.data[0]
279 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video")
280 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
281 expect(abuse.video.channel).to.exist
282 expect(abuse.video.deleted).to.be.true
285 it('Should include counts of reports from reporter and reportee', async function () {
288 // register a second user to have two reporters/reportees
289 const user = { username: 'user2', password: 'password' }
290 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user })
291 const userAccessToken = await userLogin(servers[0], user)
293 // upload a third video via this user
294 const video3Attributes = {
295 name: 'my second super name for server 1',
296 description: 'my second super description for server 1'
298 const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes)
299 const video3Id = resUpload.body.video.id
301 // resume with the test
302 const reason3 = 'my super bad reason 3'
303 await commands[0].report({ videoId: video3Id, reason: reason3 })
305 const reason4 = 'my super bad reason 4'
306 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: reason4 })
309 const body = await commands[0].getAdminList()
310 const abuses = body.data
312 const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
313 expect(abuseVideo3).to.not.be.undefined
314 expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3")
315 expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3")
316 expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse")
317 expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse")
319 const abuseServer1 = abuses.find(a => a.video.id === servers[0].video.id)
320 expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse")
324 it('Should list predefined reasons as well as timestamps for the reported video', async function () {
327 const reason5 = 'my super bad reason 5'
328 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
329 const createRes = await commands[0].report({
330 videoId: servers[0].video.id,
332 predefinedReasons: predefinedReasons5,
337 const body = await commands[0].getAdminList()
340 const abuse = body.data.find(a => a.id === createRes.abuse.id)
341 expect(abuse.reason).to.equals(reason5)
342 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported")
343 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
344 expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
348 it('Should delete the video abuse', async function () {
351 await commands[1].delete({ abuseId: abuseServer2.id })
353 await waitJobs(servers)
356 const body = await commands[1].getAdminList()
357 expect(body.total).to.equal(1)
358 expect(body.data.length).to.equal(1)
359 expect(body.data[0].id).to.not.equal(abuseServer2.id)
363 const body = await commands[0].getAdminList()
364 expect(body.total).to.equal(6)
368 it('Should list and filter video abuses', async function () {
371 async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) {
372 const body = await commands[0].getAdminList(query)
377 expect(await list({ id: 56 })).to.have.lengthOf(0)
378 expect(await list({ id: 1 })).to.have.lengthOf(1)
380 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4)
381 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
383 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
385 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4)
386 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
388 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
389 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5)
391 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5)
392 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
394 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
395 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
397 expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0)
398 expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6)
400 expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1)
401 expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0)
405 describe('Comment abuses', function () {
407 async function getComment (url: string, videoIdArg: number | string) {
408 const videoId = typeof videoIdArg === 'string'
409 ? await getVideoIdFromUUID(url, videoIdArg)
412 const res = await getVideoCommentThreads(url, videoId, 0, 5)
414 return res.body.data[0] as VideoComment
417 before(async function () {
420 servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })
421 servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })
423 await addVideoCommentThread(servers[0].url, servers[0].accessToken, servers[0].video.id, 'comment server 1')
424 await addVideoCommentThread(servers[1].url, servers[1].accessToken, servers[1].video.id, 'comment server 2')
426 await waitJobs(servers)
429 it('Should report abuse on a comment', async function () {
432 const comment = await getComment(servers[0].url, servers[0].video.id)
434 const reason = 'it is a bad comment'
435 await commands[0].report({ commentId: comment.id, reason })
437 await waitJobs(servers)
440 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
442 const comment = await getComment(servers[0].url, servers[0].video.id)
443 const body = await commands[0].getAdminList({ filter: 'comment' })
445 expect(body.total).to.equal(1)
446 expect(body.data).to.have.lengthOf(1)
448 const abuse = body.data[0]
449 expect(abuse.reason).to.equal('it is a bad comment')
451 expect(abuse.reporterAccount.name).to.equal('root')
452 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
454 expect(abuse.video).to.be.null
456 expect(abuse.comment.deleted).to.be.false
457 expect(abuse.comment.id).to.equal(comment.id)
458 expect(abuse.comment.text).to.equal(comment.text)
459 expect(abuse.comment.video.name).to.equal('server 1')
460 expect(abuse.comment.video.id).to.equal(servers[0].video.id)
461 expect(abuse.comment.video.uuid).to.equal(servers[0].video.uuid)
463 expect(abuse.countReportsForReporter).to.equal(5)
464 expect(abuse.countReportsForReportee).to.equal(5)
468 const body = await commands[1].getAdminList({ filter: 'comment' })
469 expect(body.total).to.equal(0)
470 expect(body.data.length).to.equal(0)
474 it('Should report abuse on a remote comment', async function () {
477 const comment = await getComment(servers[0].url, servers[1].video.uuid)
479 const reason = 'it is a really bad comment'
480 await commands[0].report({ commentId: comment.id, reason })
482 await waitJobs(servers)
485 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
486 const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
489 const body = await commands[0].getAdminList({ filter: 'comment' })
490 expect(body.total).to.equal(2)
491 expect(body.data.length).to.equal(2)
493 const abuse = body.data[0]
494 expect(abuse.reason).to.equal('it is a bad comment')
495 expect(abuse.countReportsForReporter).to.equal(6)
496 expect(abuse.countReportsForReportee).to.equal(5)
498 const abuse2 = body.data[1]
500 expect(abuse2.reason).to.equal('it is a really bad comment')
502 expect(abuse2.reporterAccount.name).to.equal('root')
503 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
505 expect(abuse2.video).to.be.null
507 expect(abuse2.comment.deleted).to.be.false
508 expect(abuse2.comment.id).to.equal(commentServer2.id)
509 expect(abuse2.comment.text).to.equal(commentServer2.text)
510 expect(abuse2.comment.video.name).to.equal('server 2')
511 expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid)
513 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
514 expect(abuse2.state.label).to.equal('Pending')
516 expect(abuse2.moderationComment).to.be.null
518 expect(abuse2.countReportsForReporter).to.equal(6)
519 expect(abuse2.countReportsForReportee).to.equal(2)
523 const body = await commands[1].getAdminList({ filter: 'comment' })
524 expect(body.total).to.equal(1)
525 expect(body.data.length).to.equal(1)
527 abuseServer2 = body.data[0]
528 expect(abuseServer2.reason).to.equal('it is a really bad comment')
529 expect(abuseServer2.reporterAccount.name).to.equal('root')
530 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
532 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
533 expect(abuseServer2.state.label).to.equal('Pending')
535 expect(abuseServer2.moderationComment).to.be.null
537 expect(abuseServer2.countReportsForReporter).to.equal(1)
538 expect(abuseServer2.countReportsForReportee).to.equal(1)
542 it('Should keep the comment abuse when deleting the comment', async function () {
545 const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
547 await deleteVideoComment(servers[0].url, servers[0].accessToken, servers[1].video.uuid, commentServer2.id)
549 await waitJobs(servers)
551 const body = await commands[0].getAdminList({ filter: 'comment' })
552 expect(body.total).to.equal(2)
553 expect(body.data).to.have.lengthOf(2)
555 const abuse = body.data.find(a => a.comment?.id === commentServer2.id)
556 expect(abuse).to.not.be.undefined
558 expect(abuse.comment.text).to.be.empty
559 expect(abuse.comment.video.name).to.equal('server 2')
560 expect(abuse.comment.deleted).to.be.true
563 it('Should delete the comment abuse', async function () {
566 await commands[1].delete({ abuseId: abuseServer2.id })
568 await waitJobs(servers)
571 const body = await commands[1].getAdminList({ filter: 'comment' })
572 expect(body.total).to.equal(0)
573 expect(body.data.length).to.equal(0)
577 const body = await commands[0].getAdminList({ filter: 'comment' })
578 expect(body.total).to.equal(2)
582 it('Should list and filter video abuses', async function () {
584 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' })
585 expect(body.total).to.equal(0)
589 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' })
590 expect(body.total).to.equal(2)
594 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' })
595 expect(body.data).to.have.lengthOf(1)
596 expect(body.data[0].comment.text).to.be.empty
600 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' })
601 expect(body.data).to.have.lengthOf(1)
602 expect(body.data[0].comment.text).to.equal('comment server 1')
607 describe('Account abuses', function () {
609 async function getAccountFromServer (url: string, name: string, server: ServerInfo) {
610 const res = await getAccount(url, name + '@' + server.host)
612 return res.body as Account
615 before(async function () {
618 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' })
620 const token = await generateUserAccessToken(servers[1], 'user_2')
621 await uploadVideo(servers[1].url, token, { name: 'super video' })
623 await waitJobs(servers)
626 it('Should report abuse on an account', async function () {
629 const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0])
631 const reason = 'it is a bad account'
632 await commands[0].report({ accountId: account.id, reason })
634 await waitJobs(servers)
637 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
639 const body = await commands[0].getAdminList({ filter: 'account' })
641 expect(body.total).to.equal(1)
642 expect(body.data).to.have.lengthOf(1)
644 const abuse = body.data[0]
645 expect(abuse.reason).to.equal('it is a bad account')
647 expect(abuse.reporterAccount.name).to.equal('root')
648 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
650 expect(abuse.video).to.be.null
651 expect(abuse.comment).to.be.null
653 expect(abuse.flaggedAccount.name).to.equal('user_1')
654 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
658 const body = await commands[1].getAdminList({ filter: 'comment' })
659 expect(body.total).to.equal(0)
660 expect(body.data.length).to.equal(0)
664 it('Should report abuse on a remote account', async function () {
667 const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1])
669 const reason = 'it is a really bad account'
670 await commands[0].report({ accountId: account.id, reason })
672 await waitJobs(servers)
675 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
677 const body = await commands[0].getAdminList({ filter: 'account' })
678 expect(body.total).to.equal(2)
679 expect(body.data.length).to.equal(2)
681 const abuse: AdminAbuse = body.data[0]
682 expect(abuse.reason).to.equal('it is a bad account')
684 const abuse2: AdminAbuse = body.data[1]
685 expect(abuse2.reason).to.equal('it is a really bad account')
687 expect(abuse2.reporterAccount.name).to.equal('root')
688 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
690 expect(abuse2.video).to.be.null
691 expect(abuse2.comment).to.be.null
693 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
694 expect(abuse2.state.label).to.equal('Pending')
696 expect(abuse2.moderationComment).to.be.null
700 const body = await commands[1].getAdminList({ filter: 'account' })
701 expect(body.total).to.equal(1)
702 expect(body.data.length).to.equal(1)
704 abuseServer2 = body.data[0]
706 expect(abuseServer2.reason).to.equal('it is a really bad account')
708 expect(abuseServer2.reporterAccount.name).to.equal('root')
709 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
711 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
712 expect(abuseServer2.state.label).to.equal('Pending')
714 expect(abuseServer2.moderationComment).to.be.null
718 it('Should keep the account abuse when deleting the account', async function () {
721 const account = await getAccountFromServer(servers[1].url, 'user_2', servers[1])
722 await removeUser(servers[1].url, account.userId, servers[1].accessToken)
724 await waitJobs(servers)
726 const body = await commands[0].getAdminList({ filter: 'account' })
727 expect(body.total).to.equal(2)
728 expect(body.data).to.have.lengthOf(2)
730 const abuse = body.data.find(a => a.reason === 'it is a really bad account')
731 expect(abuse).to.not.be.undefined
734 it('Should delete the account abuse', async function () {
737 await commands[1].delete({ abuseId: abuseServer2.id })
739 await waitJobs(servers)
742 const body = await commands[1].getAdminList({ filter: 'account' })
743 expect(body.total).to.equal(0)
744 expect(body.data.length).to.equal(0)
748 const body = await commands[0].getAdminList({ filter: 'account' })
749 expect(body.total).to.equal(2)
751 abuseServer1 = body.data[0]
756 describe('Common actions on abuses', function () {
758 it('Should update the state of an abuse', async function () {
759 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } })
761 const body = await commands[0].getAdminList({ id: abuseServer1.id })
762 expect(body.data[0].state.id).to.equal(AbuseState.REJECTED)
765 it('Should add a moderation comment', async function () {
766 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } })
768 const body = await commands[0].getAdminList({ id: abuseServer1.id })
769 expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
770 expect(body.data[0].moderationComment).to.equal('Valid')
774 describe('My abuses', async function () {
776 let userAccessToken: string
778 before(async function () {
779 userAccessToken = await generateUserAccessToken(servers[0], 'user_42')
781 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
783 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
784 await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
787 it('Should correctly list my abuses', async function () {
789 const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
790 expect(body.total).to.equal(2)
792 const abuses = body.data
793 expect(abuses[0].reason).to.equal('user reason 1')
794 expect(abuses[1].reason).to.equal('user reason 2')
796 abuseId1 = abuses[0].id
800 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
801 expect(body.total).to.equal(2)
803 const abuses: UserAbuse[] = body.data
804 expect(abuses[0].reason).to.equal('user reason 2')
808 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
809 expect(body.total).to.equal(2)
811 const abuses: UserAbuse[] = body.data
812 expect(abuses[0].reason).to.equal('user reason 1')
816 it('Should correctly filter my abuses by id', async function () {
817 const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 })
818 expect(body.total).to.equal(1)
820 const abuses: UserAbuse[] = body.data
821 expect(abuses[0].reason).to.equal('user reason 1')
824 it('Should correctly filter my abuses by search', async function () {
825 const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' })
826 expect(body.total).to.equal(1)
828 const abuses: UserAbuse[] = body.data
829 expect(abuses[0].reason).to.equal('user reason 2')
832 it('Should correctly filter my abuses by state', async function () {
833 await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } })
835 const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED })
836 expect(body.total).to.equal(1)
838 const abuses: UserAbuse[] = body.data
839 expect(abuses[0].reason).to.equal('user reason 1')
843 describe('Abuse messages', async function () {
845 let userToken: string
846 let abuseMessageUserId: number
847 let abuseMessageModerationId: number
849 before(async function () {
850 userToken = await generateUserAccessToken(servers[0], 'user_43')
852 const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' })
853 abuseId = body.abuse.id
856 it('Should create some messages on the abuse', async function () {
857 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' })
858 await commands[0].addMessage({ abuseId, message: 'message 2' })
859 await commands[0].addMessage({ abuseId, message: 'message 3' })
860 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' })
863 it('Should have the correct messages count when listing abuses', async function () {
864 const results = await Promise.all([
865 commands[0].getAdminList({ start: 0, count: 50 }),
866 commands[0].getUserList({ token: userToken, start: 0, count: 50 })
869 for (const body of results) {
870 const abuses = body.data
871 const abuse = abuses.find(a => a.id === abuseId)
872 expect(abuse.countMessages).to.equal(4)
876 it('Should correctly list messages of this abuse', async function () {
877 const results = await Promise.all([
878 commands[0].listMessages({ abuseId }),
879 commands[0].listMessages({ token: userToken, abuseId })
882 for (const body of results) {
883 expect(body.total).to.equal(4)
885 const abuseMessages: AbuseMessage[] = body.data
887 expect(abuseMessages[0].message).to.equal('message 1')
888 expect(abuseMessages[0].byModerator).to.be.false
889 expect(abuseMessages[0].account.name).to.equal('user_43')
891 abuseMessageUserId = abuseMessages[0].id
893 expect(abuseMessages[1].message).to.equal('message 2')
894 expect(abuseMessages[1].byModerator).to.be.true
895 expect(abuseMessages[1].account.name).to.equal('root')
897 expect(abuseMessages[2].message).to.equal('message 3')
898 expect(abuseMessages[2].byModerator).to.be.true
899 expect(abuseMessages[2].account.name).to.equal('root')
900 abuseMessageModerationId = abuseMessages[2].id
902 expect(abuseMessages[3].message).to.equal('message 4')
903 expect(abuseMessages[3].byModerator).to.be.false
904 expect(abuseMessages[3].account.name).to.equal('user_43')
908 it('Should delete messages', async function () {
909 await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId })
910 await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId })
912 const results = await Promise.all([
913 commands[0].listMessages({ abuseId }),
914 commands[0].listMessages({ token: userToken, abuseId })
917 for (const body of results) {
918 expect(body.total).to.equal(2)
920 const abuseMessages: AbuseMessage[] = body.data
921 expect(abuseMessages[0].message).to.equal('message 2')
922 expect(abuseMessages[1].message).to.equal('message 4')
927 after(async function () {
928 await cleanupTests(servers)