1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
10 flushAndRunMultipleServers,
11 generateUserAccessToken,
17 setAccessTokensToServers,
21 } from '@shared/extra-utils'
22 import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
24 const expect = chai.expect
26 describe('Test abuses', function () {
27 let servers: ServerInfo[] = []
28 let abuseServer1: AdminAbuse
29 let abuseServer2: AdminAbuse
30 let commands: AbusesCommand[]
32 before(async function () {
36 servers = await flushAndRunMultipleServers(2)
38 // Get the access tokens
39 await setAccessTokensToServers(servers)
41 // Server 1 and server 2 follow each other
42 await doubleFollow(servers[0], servers[1])
44 commands = servers.map(s => s.abusesCommand)
47 describe('Video abuses', function () {
49 before(async function () {
52 // Upload some videos on each servers
53 const video1Attributes = {
54 name: 'my super name for server 1',
55 description: 'my super description for server 1'
57 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
59 const video2Attributes = {
60 name: 'my super name for server 2',
61 description: 'my super description for server 2'
63 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
65 // Wait videos propagation, server 2 has transcoding enabled
66 await waitJobs(servers)
68 const res = await getVideosList(servers[0].url)
69 const videos = res.body.data
71 expect(videos.length).to.equal(2)
73 servers[0].video = videos.find(video => video.name === 'my super name for server 1')
74 servers[1].video = videos.find(video => video.name === 'my super name for server 2')
77 it('Should not have abuses', async function () {
78 const body = await commands[0].getAdminList()
80 expect(body.total).to.equal(0)
81 expect(body.data).to.be.an('array')
82 expect(body.data.length).to.equal(0)
85 it('Should report abuse on a local video', async function () {
88 const reason = 'my super bad reason'
89 await commands[0].report({ videoId: servers[0].video.id, reason })
91 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
92 await waitJobs(servers)
95 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
97 const body = await commands[0].getAdminList()
99 expect(body.total).to.equal(1)
100 expect(body.data).to.be.an('array')
101 expect(body.data.length).to.equal(1)
103 const abuse = body.data[0]
104 expect(abuse.reason).to.equal('my super bad reason')
106 expect(abuse.reporterAccount.name).to.equal('root')
107 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
109 expect(abuse.video.id).to.equal(servers[0].video.id)
110 expect(abuse.video.channel).to.exist
112 expect(abuse.comment).to.be.null
114 expect(abuse.flaggedAccount.name).to.equal('root')
115 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
117 expect(abuse.video.countReports).to.equal(1)
118 expect(abuse.video.nthReport).to.equal(1)
120 expect(abuse.countReportsForReporter).to.equal(1)
121 expect(abuse.countReportsForReportee).to.equal(1)
125 const body = await commands[1].getAdminList()
126 expect(body.total).to.equal(0)
127 expect(body.data).to.be.an('array')
128 expect(body.data.length).to.equal(0)
132 it('Should report abuse on a remote video', async function () {
135 const reason = 'my super bad reason 2'
136 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
137 await commands[0].report({ videoId, reason })
139 // We wait requests propagation
140 await waitJobs(servers)
143 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
145 const body = await commands[0].getAdminList()
147 expect(body.total).to.equal(2)
148 expect(body.data.length).to.equal(2)
150 const abuse1 = body.data[0]
151 expect(abuse1.reason).to.equal('my super bad reason')
152 expect(abuse1.reporterAccount.name).to.equal('root')
153 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
155 expect(abuse1.video.id).to.equal(servers[0].video.id)
156 expect(abuse1.video.countReports).to.equal(1)
157 expect(abuse1.video.nthReport).to.equal(1)
159 expect(abuse1.comment).to.be.null
161 expect(abuse1.flaggedAccount.name).to.equal('root')
162 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
164 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
165 expect(abuse1.state.label).to.equal('Pending')
166 expect(abuse1.moderationComment).to.be.null
168 const abuse2 = body.data[1]
169 expect(abuse2.reason).to.equal('my super bad reason 2')
171 expect(abuse2.reporterAccount.name).to.equal('root')
172 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
174 expect(abuse2.video.id).to.equal(servers[1].video.id)
176 expect(abuse2.comment).to.be.null
178 expect(abuse2.flaggedAccount.name).to.equal('root')
179 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
181 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
182 expect(abuse2.state.label).to.equal('Pending')
183 expect(abuse2.moderationComment).to.be.null
187 const body = await commands[1].getAdminList()
188 expect(body.total).to.equal(1)
189 expect(body.data.length).to.equal(1)
191 abuseServer2 = body.data[0]
192 expect(abuseServer2.reason).to.equal('my super bad reason 2')
193 expect(abuseServer2.reporterAccount.name).to.equal('root')
194 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
196 expect(abuseServer2.flaggedAccount.name).to.equal('root')
197 expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host)
199 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
200 expect(abuseServer2.state.label).to.equal('Pending')
201 expect(abuseServer2.moderationComment).to.be.null
205 it('Should hide video abuses from blocked accounts', async function () {
209 const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid)
210 await commands[1].report({ videoId, reason: 'will mute this' })
211 await waitJobs(servers)
213 const body = await commands[0].getAdminList()
214 expect(body.total).to.equal(3)
217 const accountToBlock = 'root@' + servers[1].host
220 await servers[0].blocklistCommand.addToServerBlocklist({ account: accountToBlock })
222 const body = await commands[0].getAdminList()
223 expect(body.total).to.equal(2)
225 const abuse = body.data.find(a => a.reason === 'will mute this')
226 expect(abuse).to.be.undefined
230 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: accountToBlock })
232 const body = await commands[0].getAdminList()
233 expect(body.total).to.equal(3)
237 it('Should hide video abuses from blocked servers', async function () {
238 const serverToBlock = servers[1].host
241 await servers[0].blocklistCommand.addToServerBlocklist({ server: serverToBlock })
243 const body = await commands[0].getAdminList()
244 expect(body.total).to.equal(2)
246 const abuse = body.data.find(a => a.reason === 'will mute this')
247 expect(abuse).to.be.undefined
251 await servers[0].blocklistCommand.removeFromServerBlocklist({ server: serverToBlock })
253 const body = await commands[0].getAdminList()
254 expect(body.total).to.equal(3)
258 it('Should keep the video abuse when deleting the video', async function () {
261 await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid)
263 await waitJobs(servers)
265 const body = await commands[1].getAdminList()
266 expect(body.total).to.equal(2, "wrong number of videos returned")
267 expect(body.data).to.have.lengthOf(2, "wrong number of videos returned")
269 const abuse = body.data[0]
270 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video")
271 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
272 expect(abuse.video.channel).to.exist
273 expect(abuse.video.deleted).to.be.true
276 it('Should include counts of reports from reporter and reportee', async function () {
279 // register a second user to have two reporters/reportees
280 const user = { username: 'user2', password: 'password' }
281 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user })
282 const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
284 // upload a third video via this user
285 const video3Attributes = {
286 name: 'my second super name for server 1',
287 description: 'my second super description for server 1'
289 const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes)
290 const video3Id = resUpload.body.video.id
292 // resume with the test
293 const reason3 = 'my super bad reason 3'
294 await commands[0].report({ videoId: video3Id, reason: reason3 })
296 const reason4 = 'my super bad reason 4'
297 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: reason4 })
300 const body = await commands[0].getAdminList()
301 const abuses = body.data
303 const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
304 expect(abuseVideo3).to.not.be.undefined
305 expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3")
306 expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3")
307 expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse")
308 expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse")
310 const abuseServer1 = abuses.find(a => a.video.id === servers[0].video.id)
311 expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse")
315 it('Should list predefined reasons as well as timestamps for the reported video', async function () {
318 const reason5 = 'my super bad reason 5'
319 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
320 const createRes = await commands[0].report({
321 videoId: servers[0].video.id,
323 predefinedReasons: predefinedReasons5,
328 const body = await commands[0].getAdminList()
331 const abuse = body.data.find(a => a.id === createRes.abuse.id)
332 expect(abuse.reason).to.equals(reason5)
333 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported")
334 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
335 expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
339 it('Should delete the video abuse', async function () {
342 await commands[1].delete({ abuseId: abuseServer2.id })
344 await waitJobs(servers)
347 const body = await commands[1].getAdminList()
348 expect(body.total).to.equal(1)
349 expect(body.data.length).to.equal(1)
350 expect(body.data[0].id).to.not.equal(abuseServer2.id)
354 const body = await commands[0].getAdminList()
355 expect(body.total).to.equal(6)
359 it('Should list and filter video abuses', async function () {
362 async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) {
363 const body = await commands[0].getAdminList(query)
368 expect(await list({ id: 56 })).to.have.lengthOf(0)
369 expect(await list({ id: 1 })).to.have.lengthOf(1)
371 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4)
372 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
374 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
376 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4)
377 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
379 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
380 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5)
382 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5)
383 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
385 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
386 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
388 expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0)
389 expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6)
391 expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1)
392 expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0)
396 describe('Comment abuses', function () {
398 async function getComment (server: ServerInfo, videoIdArg: number | string) {
399 const videoId = typeof videoIdArg === 'string'
400 ? await getVideoIdFromUUID(server.url, videoIdArg)
403 const { data } = await server.commentsCommand.listThreads({ videoId })
408 before(async function () {
411 servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })
412 servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })
414 await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' })
415 await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' })
417 await waitJobs(servers)
420 it('Should report abuse on a comment', async function () {
423 const comment = await getComment(servers[0], servers[0].video.id)
425 const reason = 'it is a bad comment'
426 await commands[0].report({ commentId: comment.id, reason })
428 await waitJobs(servers)
431 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
433 const comment = await getComment(servers[0], servers[0].video.id)
434 const body = await commands[0].getAdminList({ filter: 'comment' })
436 expect(body.total).to.equal(1)
437 expect(body.data).to.have.lengthOf(1)
439 const abuse = body.data[0]
440 expect(abuse.reason).to.equal('it is a bad comment')
442 expect(abuse.reporterAccount.name).to.equal('root')
443 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
445 expect(abuse.video).to.be.null
447 expect(abuse.comment.deleted).to.be.false
448 expect(abuse.comment.id).to.equal(comment.id)
449 expect(abuse.comment.text).to.equal(comment.text)
450 expect(abuse.comment.video.name).to.equal('server 1')
451 expect(abuse.comment.video.id).to.equal(servers[0].video.id)
452 expect(abuse.comment.video.uuid).to.equal(servers[0].video.uuid)
454 expect(abuse.countReportsForReporter).to.equal(5)
455 expect(abuse.countReportsForReportee).to.equal(5)
459 const body = await commands[1].getAdminList({ filter: 'comment' })
460 expect(body.total).to.equal(0)
461 expect(body.data.length).to.equal(0)
465 it('Should report abuse on a remote comment', async function () {
468 const comment = await getComment(servers[0], servers[1].video.uuid)
470 const reason = 'it is a really bad comment'
471 await commands[0].report({ commentId: comment.id, reason })
473 await waitJobs(servers)
476 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
477 const commentServer2 = await getComment(servers[0], servers[1].video.id)
480 const body = await commands[0].getAdminList({ filter: 'comment' })
481 expect(body.total).to.equal(2)
482 expect(body.data.length).to.equal(2)
484 const abuse = body.data[0]
485 expect(abuse.reason).to.equal('it is a bad comment')
486 expect(abuse.countReportsForReporter).to.equal(6)
487 expect(abuse.countReportsForReportee).to.equal(5)
489 const abuse2 = body.data[1]
491 expect(abuse2.reason).to.equal('it is a really bad comment')
493 expect(abuse2.reporterAccount.name).to.equal('root')
494 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
496 expect(abuse2.video).to.be.null
498 expect(abuse2.comment.deleted).to.be.false
499 expect(abuse2.comment.id).to.equal(commentServer2.id)
500 expect(abuse2.comment.text).to.equal(commentServer2.text)
501 expect(abuse2.comment.video.name).to.equal('server 2')
502 expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid)
504 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
505 expect(abuse2.state.label).to.equal('Pending')
507 expect(abuse2.moderationComment).to.be.null
509 expect(abuse2.countReportsForReporter).to.equal(6)
510 expect(abuse2.countReportsForReportee).to.equal(2)
514 const body = await commands[1].getAdminList({ filter: 'comment' })
515 expect(body.total).to.equal(1)
516 expect(body.data.length).to.equal(1)
518 abuseServer2 = body.data[0]
519 expect(abuseServer2.reason).to.equal('it is a really bad comment')
520 expect(abuseServer2.reporterAccount.name).to.equal('root')
521 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
523 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
524 expect(abuseServer2.state.label).to.equal('Pending')
526 expect(abuseServer2.moderationComment).to.be.null
528 expect(abuseServer2.countReportsForReporter).to.equal(1)
529 expect(abuseServer2.countReportsForReportee).to.equal(1)
533 it('Should keep the comment abuse when deleting the comment', async function () {
536 const commentServer2 = await getComment(servers[0], servers[1].video.id)
538 await servers[0].commentsCommand.delete({ videoId: servers[1].video.uuid, commentId: commentServer2.id })
540 await waitJobs(servers)
542 const body = await commands[0].getAdminList({ filter: 'comment' })
543 expect(body.total).to.equal(2)
544 expect(body.data).to.have.lengthOf(2)
546 const abuse = body.data.find(a => a.comment?.id === commentServer2.id)
547 expect(abuse).to.not.be.undefined
549 expect(abuse.comment.text).to.be.empty
550 expect(abuse.comment.video.name).to.equal('server 2')
551 expect(abuse.comment.deleted).to.be.true
554 it('Should delete the comment abuse', async function () {
557 await commands[1].delete({ abuseId: abuseServer2.id })
559 await waitJobs(servers)
562 const body = await commands[1].getAdminList({ filter: 'comment' })
563 expect(body.total).to.equal(0)
564 expect(body.data.length).to.equal(0)
568 const body = await commands[0].getAdminList({ filter: 'comment' })
569 expect(body.total).to.equal(2)
573 it('Should list and filter video abuses', async function () {
575 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' })
576 expect(body.total).to.equal(0)
580 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' })
581 expect(body.total).to.equal(2)
585 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' })
586 expect(body.data).to.have.lengthOf(1)
587 expect(body.data[0].comment.text).to.be.empty
591 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' })
592 expect(body.data).to.have.lengthOf(1)
593 expect(body.data[0].comment.text).to.equal('comment server 1')
598 describe('Account abuses', function () {
600 function getAccountFromServer (server: ServerInfo, targetName: string, targetServer: ServerInfo) {
601 return server.accountsCommand.get({ accountName: targetName + '@' + targetServer.host })
604 before(async function () {
607 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' })
609 const token = await generateUserAccessToken(servers[1], 'user_2')
610 await uploadVideo(servers[1].url, token, { name: 'super video' })
612 await waitJobs(servers)
615 it('Should report abuse on an account', async function () {
618 const account = await getAccountFromServer(servers[0], 'user_1', servers[0])
620 const reason = 'it is a bad account'
621 await commands[0].report({ accountId: account.id, reason })
623 await waitJobs(servers)
626 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
628 const body = await commands[0].getAdminList({ filter: 'account' })
630 expect(body.total).to.equal(1)
631 expect(body.data).to.have.lengthOf(1)
633 const abuse = body.data[0]
634 expect(abuse.reason).to.equal('it is a bad account')
636 expect(abuse.reporterAccount.name).to.equal('root')
637 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
639 expect(abuse.video).to.be.null
640 expect(abuse.comment).to.be.null
642 expect(abuse.flaggedAccount.name).to.equal('user_1')
643 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
647 const body = await commands[1].getAdminList({ filter: 'comment' })
648 expect(body.total).to.equal(0)
649 expect(body.data.length).to.equal(0)
653 it('Should report abuse on a remote account', async function () {
656 const account = await getAccountFromServer(servers[0], 'user_2', servers[1])
658 const reason = 'it is a really bad account'
659 await commands[0].report({ accountId: account.id, reason })
661 await waitJobs(servers)
664 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
666 const body = await commands[0].getAdminList({ filter: 'account' })
667 expect(body.total).to.equal(2)
668 expect(body.data.length).to.equal(2)
670 const abuse: AdminAbuse = body.data[0]
671 expect(abuse.reason).to.equal('it is a bad account')
673 const abuse2: AdminAbuse = body.data[1]
674 expect(abuse2.reason).to.equal('it is a really bad account')
676 expect(abuse2.reporterAccount.name).to.equal('root')
677 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
679 expect(abuse2.video).to.be.null
680 expect(abuse2.comment).to.be.null
682 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
683 expect(abuse2.state.label).to.equal('Pending')
685 expect(abuse2.moderationComment).to.be.null
689 const body = await commands[1].getAdminList({ filter: 'account' })
690 expect(body.total).to.equal(1)
691 expect(body.data.length).to.equal(1)
693 abuseServer2 = body.data[0]
695 expect(abuseServer2.reason).to.equal('it is a really bad account')
697 expect(abuseServer2.reporterAccount.name).to.equal('root')
698 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
700 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
701 expect(abuseServer2.state.label).to.equal('Pending')
703 expect(abuseServer2.moderationComment).to.be.null
707 it('Should keep the account abuse when deleting the account', async function () {
710 const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
711 await removeUser(servers[1].url, account.userId, servers[1].accessToken)
713 await waitJobs(servers)
715 const body = await commands[0].getAdminList({ filter: 'account' })
716 expect(body.total).to.equal(2)
717 expect(body.data).to.have.lengthOf(2)
719 const abuse = body.data.find(a => a.reason === 'it is a really bad account')
720 expect(abuse).to.not.be.undefined
723 it('Should delete the account abuse', async function () {
726 await commands[1].delete({ abuseId: abuseServer2.id })
728 await waitJobs(servers)
731 const body = await commands[1].getAdminList({ filter: 'account' })
732 expect(body.total).to.equal(0)
733 expect(body.data.length).to.equal(0)
737 const body = await commands[0].getAdminList({ filter: 'account' })
738 expect(body.total).to.equal(2)
740 abuseServer1 = body.data[0]
745 describe('Common actions on abuses', function () {
747 it('Should update the state of an abuse', async function () {
748 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } })
750 const body = await commands[0].getAdminList({ id: abuseServer1.id })
751 expect(body.data[0].state.id).to.equal(AbuseState.REJECTED)
754 it('Should add a moderation comment', async function () {
755 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } })
757 const body = await commands[0].getAdminList({ id: abuseServer1.id })
758 expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
759 expect(body.data[0].moderationComment).to.equal('Valid')
763 describe('My abuses', async function () {
765 let userAccessToken: string
767 before(async function () {
768 userAccessToken = await generateUserAccessToken(servers[0], 'user_42')
770 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
772 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
773 await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
776 it('Should correctly list my abuses', async function () {
778 const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
779 expect(body.total).to.equal(2)
781 const abuses = body.data
782 expect(abuses[0].reason).to.equal('user reason 1')
783 expect(abuses[1].reason).to.equal('user reason 2')
785 abuseId1 = abuses[0].id
789 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
790 expect(body.total).to.equal(2)
792 const abuses: UserAbuse[] = body.data
793 expect(abuses[0].reason).to.equal('user reason 2')
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 1')
805 it('Should correctly filter my abuses by id', async function () {
806 const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 })
807 expect(body.total).to.equal(1)
809 const abuses: UserAbuse[] = body.data
810 expect(abuses[0].reason).to.equal('user reason 1')
813 it('Should correctly filter my abuses by search', async function () {
814 const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' })
815 expect(body.total).to.equal(1)
817 const abuses: UserAbuse[] = body.data
818 expect(abuses[0].reason).to.equal('user reason 2')
821 it('Should correctly filter my abuses by state', async function () {
822 await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } })
824 const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED })
825 expect(body.total).to.equal(1)
827 const abuses: UserAbuse[] = body.data
828 expect(abuses[0].reason).to.equal('user reason 1')
832 describe('Abuse messages', async function () {
834 let userToken: string
835 let abuseMessageUserId: number
836 let abuseMessageModerationId: number
838 before(async function () {
839 userToken = await generateUserAccessToken(servers[0], 'user_43')
841 const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' })
842 abuseId = body.abuse.id
845 it('Should create some messages on the abuse', async function () {
846 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' })
847 await commands[0].addMessage({ abuseId, message: 'message 2' })
848 await commands[0].addMessage({ abuseId, message: 'message 3' })
849 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' })
852 it('Should have the correct messages count when listing abuses', async function () {
853 const results = await Promise.all([
854 commands[0].getAdminList({ start: 0, count: 50 }),
855 commands[0].getUserList({ token: userToken, start: 0, count: 50 })
858 for (const body of results) {
859 const abuses = body.data
860 const abuse = abuses.find(a => a.id === abuseId)
861 expect(abuse.countMessages).to.equal(4)
865 it('Should correctly list messages of this abuse', async function () {
866 const results = await Promise.all([
867 commands[0].listMessages({ abuseId }),
868 commands[0].listMessages({ token: userToken, abuseId })
871 for (const body of results) {
872 expect(body.total).to.equal(4)
874 const abuseMessages: AbuseMessage[] = body.data
876 expect(abuseMessages[0].message).to.equal('message 1')
877 expect(abuseMessages[0].byModerator).to.be.false
878 expect(abuseMessages[0].account.name).to.equal('user_43')
880 abuseMessageUserId = abuseMessages[0].id
882 expect(abuseMessages[1].message).to.equal('message 2')
883 expect(abuseMessages[1].byModerator).to.be.true
884 expect(abuseMessages[1].account.name).to.equal('root')
886 expect(abuseMessages[2].message).to.equal('message 3')
887 expect(abuseMessages[2].byModerator).to.be.true
888 expect(abuseMessages[2].account.name).to.equal('root')
889 abuseMessageModerationId = abuseMessages[2].id
891 expect(abuseMessages[3].message).to.equal('message 4')
892 expect(abuseMessages[3].byModerator).to.be.false
893 expect(abuseMessages[3].account.name).to.equal('user_43')
897 it('Should delete messages', async function () {
898 await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId })
899 await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId })
901 const results = await Promise.all([
902 commands[0].listMessages({ abuseId }),
903 commands[0].listMessages({ token: userToken, abuseId })
906 for (const body of results) {
907 expect(body.total).to.equal(2)
909 const abuseMessages: AbuseMessage[] = body.data
910 expect(abuseMessages[0].message).to.equal('message 2')
911 expect(abuseMessages[1].message).to.equal('message 4')
916 after(async function () {
917 await cleanupTests(servers)