1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultAccountAvatar,
14 setDefaultChannelAvatar,
16 } from '@shared/server-commands'
18 const expect = chai.expect
20 describe('Test abuses', function () {
21 let servers: PeerTubeServer[] = []
22 let abuseServer1: AdminAbuse
23 let abuseServer2: AdminAbuse
24 let commands: AbusesCommand[]
26 before(async function () {
30 servers = await createMultipleServers(2)
32 await setAccessTokensToServers(servers)
33 await setDefaultChannelAvatar(servers)
34 await setDefaultAccountAvatar(servers)
36 // Server 1 and server 2 follow each other
37 await doubleFollow(servers[0], servers[1])
39 commands = servers.map(s => s.abuses)
42 describe('Video abuses', function () {
44 before(async function () {
47 // Upload some videos on each servers
50 name: 'my super name for server 1',
51 description: 'my super description for server 1'
53 await servers[0].videos.upload({ attributes })
58 name: 'my super name for server 2',
59 description: 'my super description for server 2'
61 await servers[1].videos.upload({ attributes })
64 // Wait videos propagation, server 2 has transcoding enabled
65 await waitJobs(servers)
67 const { data } = await servers[0].videos.list()
68 expect(data.length).to.equal(2)
70 servers[0].store.videoCreated = data.find(video => video.name === 'my super name for server 1')
71 servers[1].store.videoCreated = data.find(video => video.name === 'my super name for server 2')
74 it('Should not have abuses', async function () {
75 const body = await commands[0].getAdminList()
77 expect(body.total).to.equal(0)
78 expect(body.data).to.be.an('array')
79 expect(body.data.length).to.equal(0)
82 it('Should report abuse on a local video', async function () {
85 const reason = 'my super bad reason'
86 await commands[0].report({ videoId: servers[0].store.videoCreated.id, reason })
88 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
89 await waitJobs(servers)
92 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
94 const body = await commands[0].getAdminList()
96 expect(body.total).to.equal(1)
97 expect(body.data).to.be.an('array')
98 expect(body.data.length).to.equal(1)
100 const abuse = body.data[0]
101 expect(abuse.reason).to.equal('my super bad reason')
103 expect(abuse.reporterAccount.name).to.equal('root')
104 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
106 expect(abuse.video.id).to.equal(servers[0].store.videoCreated.id)
107 expect(abuse.video.channel).to.exist
109 expect(abuse.comment).to.be.null
111 expect(abuse.flaggedAccount.name).to.equal('root')
112 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
114 expect(abuse.video.countReports).to.equal(1)
115 expect(abuse.video.nthReport).to.equal(1)
117 expect(abuse.countReportsForReporter).to.equal(1)
118 expect(abuse.countReportsForReportee).to.equal(1)
122 const body = await commands[1].getAdminList()
123 expect(body.total).to.equal(0)
124 expect(body.data).to.be.an('array')
125 expect(body.data.length).to.equal(0)
129 it('Should report abuse on a remote video', async function () {
132 const reason = 'my super bad reason 2'
133 const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid })
134 await commands[0].report({ videoId, reason })
136 // We wait requests propagation
137 await waitJobs(servers)
140 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
142 const body = await commands[0].getAdminList()
144 expect(body.total).to.equal(2)
145 expect(body.data.length).to.equal(2)
147 const abuse1 = body.data[0]
148 expect(abuse1.reason).to.equal('my super bad reason')
149 expect(abuse1.reporterAccount.name).to.equal('root')
150 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
152 expect(abuse1.video.id).to.equal(servers[0].store.videoCreated.id)
153 expect(abuse1.video.countReports).to.equal(1)
154 expect(abuse1.video.nthReport).to.equal(1)
156 expect(abuse1.comment).to.be.null
158 expect(abuse1.flaggedAccount.name).to.equal('root')
159 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
161 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
162 expect(abuse1.state.label).to.equal('Pending')
163 expect(abuse1.moderationComment).to.be.null
165 const abuse2 = body.data[1]
166 expect(abuse2.reason).to.equal('my super bad reason 2')
168 expect(abuse2.reporterAccount.name).to.equal('root')
169 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
171 expect(abuse2.video.id).to.equal(servers[1].store.videoCreated.id)
173 expect(abuse2.comment).to.be.null
175 expect(abuse2.flaggedAccount.name).to.equal('root')
176 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
178 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
179 expect(abuse2.state.label).to.equal('Pending')
180 expect(abuse2.moderationComment).to.be.null
184 const body = await commands[1].getAdminList()
185 expect(body.total).to.equal(1)
186 expect(body.data.length).to.equal(1)
188 abuseServer2 = body.data[0]
189 expect(abuseServer2.reason).to.equal('my super bad reason 2')
190 expect(abuseServer2.reporterAccount.name).to.equal('root')
191 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
193 expect(abuseServer2.flaggedAccount.name).to.equal('root')
194 expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host)
196 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
197 expect(abuseServer2.state.label).to.equal('Pending')
198 expect(abuseServer2.moderationComment).to.be.null
202 it('Should hide video abuses from blocked accounts', async function () {
206 const videoId = await servers[1].videos.getId({ uuid: servers[0].store.videoCreated.uuid })
207 await commands[1].report({ videoId, reason: 'will mute this' })
208 await waitJobs(servers)
210 const body = await commands[0].getAdminList()
211 expect(body.total).to.equal(3)
214 const accountToBlock = 'root@' + servers[1].host
217 await servers[0].blocklist.addToServerBlocklist({ account: accountToBlock })
219 const body = await commands[0].getAdminList()
220 expect(body.total).to.equal(2)
222 const abuse = body.data.find(a => a.reason === 'will mute this')
223 expect(abuse).to.be.undefined
227 await servers[0].blocklist.removeFromServerBlocklist({ account: accountToBlock })
229 const body = await commands[0].getAdminList()
230 expect(body.total).to.equal(3)
234 it('Should hide video abuses from blocked servers', async function () {
235 const serverToBlock = servers[1].host
238 await servers[0].blocklist.addToServerBlocklist({ server: serverToBlock })
240 const body = await commands[0].getAdminList()
241 expect(body.total).to.equal(2)
243 const abuse = body.data.find(a => a.reason === 'will mute this')
244 expect(abuse).to.be.undefined
248 await servers[0].blocklist.removeFromServerBlocklist({ server: serverToBlock })
250 const body = await commands[0].getAdminList()
251 expect(body.total).to.equal(3)
255 it('Should keep the video abuse when deleting the video', async function () {
258 await servers[1].videos.remove({ id: abuseServer2.video.uuid })
260 await waitJobs(servers)
262 const body = await commands[1].getAdminList()
263 expect(body.total).to.equal(2, "wrong number of videos returned")
264 expect(body.data).to.have.lengthOf(2, "wrong number of videos returned")
266 const abuse = body.data[0]
267 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video")
268 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
269 expect(abuse.video.channel).to.exist
270 expect(abuse.video.deleted).to.be.true
273 it('Should include counts of reports from reporter and reportee', async function () {
276 // register a second user to have two reporters/reportees
277 const user = { username: 'user2', password: 'password' }
278 await servers[0].users.create({ ...user })
279 const userAccessToken = await servers[0].login.getAccessToken(user)
281 // upload a third video via this user
283 name: 'my second super name for server 1',
284 description: 'my second super description for server 1'
286 const { id } = await servers[0].videos.upload({ token: userAccessToken, attributes })
289 // resume with the test
290 const reason3 = 'my super bad reason 3'
291 await commands[0].report({ videoId: video3Id, reason: reason3 })
293 const reason4 = 'my super bad reason 4'
294 await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: reason4 })
297 const body = await commands[0].getAdminList()
298 const abuses = body.data
300 const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
301 expect(abuseVideo3).to.not.be.undefined
302 expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3")
303 expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3")
304 expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse")
305 expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse")
307 const abuseServer1 = abuses.find(a => a.video.id === servers[0].store.videoCreated.id)
308 expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse")
312 it('Should list predefined reasons as well as timestamps for the reported video', async function () {
315 const reason5 = 'my super bad reason 5'
316 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
317 const createRes = await commands[0].report({
318 videoId: servers[0].store.videoCreated.id,
320 predefinedReasons: predefinedReasons5,
325 const body = await commands[0].getAdminList()
328 const abuse = body.data.find(a => a.id === createRes.abuse.id)
329 expect(abuse.reason).to.equals(reason5)
330 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported")
331 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
332 expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
336 it('Should delete the video abuse', async function () {
339 await commands[1].delete({ abuseId: abuseServer2.id })
341 await waitJobs(servers)
344 const body = await commands[1].getAdminList()
345 expect(body.total).to.equal(1)
346 expect(body.data.length).to.equal(1)
347 expect(body.data[0].id).to.not.equal(abuseServer2.id)
351 const body = await commands[0].getAdminList()
352 expect(body.total).to.equal(6)
356 it('Should list and filter video abuses', async function () {
359 async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) {
360 const body = await commands[0].getAdminList(query)
365 expect(await list({ id: 56 })).to.have.lengthOf(0)
366 expect(await list({ id: 1 })).to.have.lengthOf(1)
368 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4)
369 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
371 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
373 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4)
374 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
376 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
377 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5)
379 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5)
380 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
382 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
383 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
385 expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0)
386 expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6)
388 expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1)
389 expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0)
393 describe('Comment abuses', function () {
395 async function getComment (server: PeerTubeServer, videoIdArg: number | string) {
396 const videoId = typeof videoIdArg === 'string'
397 ? await server.videos.getId({ uuid: videoIdArg })
400 const { data } = await server.comments.listThreads({ videoId })
405 before(async function () {
408 servers[0].store.videoCreated = await servers[0].videos.quickUpload({ name: 'server 1' })
409 servers[1].store.videoCreated = await servers[1].videos.quickUpload({ name: 'server 2' })
411 await servers[0].comments.createThread({ videoId: servers[0].store.videoCreated.id, text: 'comment server 1' })
412 await servers[1].comments.createThread({ videoId: servers[1].store.videoCreated.id, text: 'comment server 2' })
414 await waitJobs(servers)
417 it('Should report abuse on a comment', async function () {
420 const comment = await getComment(servers[0], servers[0].store.videoCreated.id)
422 const reason = 'it is a bad comment'
423 await commands[0].report({ commentId: comment.id, reason })
425 await waitJobs(servers)
428 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
430 const comment = await getComment(servers[0], servers[0].store.videoCreated.id)
431 const body = await commands[0].getAdminList({ filter: 'comment' })
433 expect(body.total).to.equal(1)
434 expect(body.data).to.have.lengthOf(1)
436 const abuse = body.data[0]
437 expect(abuse.reason).to.equal('it is a bad comment')
439 expect(abuse.reporterAccount.name).to.equal('root')
440 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
442 expect(abuse.video).to.be.null
444 expect(abuse.comment.deleted).to.be.false
445 expect(abuse.comment.id).to.equal(comment.id)
446 expect(abuse.comment.text).to.equal(comment.text)
447 expect(abuse.comment.video.name).to.equal('server 1')
448 expect(abuse.comment.video.id).to.equal(servers[0].store.videoCreated.id)
449 expect(abuse.comment.video.uuid).to.equal(servers[0].store.videoCreated.uuid)
451 expect(abuse.countReportsForReporter).to.equal(5)
452 expect(abuse.countReportsForReportee).to.equal(5)
456 const body = await commands[1].getAdminList({ filter: 'comment' })
457 expect(body.total).to.equal(0)
458 expect(body.data.length).to.equal(0)
462 it('Should report abuse on a remote comment', async function () {
465 const comment = await getComment(servers[0], servers[1].store.videoCreated.uuid)
467 const reason = 'it is a really bad comment'
468 await commands[0].report({ commentId: comment.id, reason })
470 await waitJobs(servers)
473 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
474 const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.shortUUID)
477 const body = await commands[0].getAdminList({ filter: 'comment' })
478 expect(body.total).to.equal(2)
479 expect(body.data.length).to.equal(2)
481 const abuse = body.data[0]
482 expect(abuse.reason).to.equal('it is a bad comment')
483 expect(abuse.countReportsForReporter).to.equal(6)
484 expect(abuse.countReportsForReportee).to.equal(5)
486 const abuse2 = body.data[1]
488 expect(abuse2.reason).to.equal('it is a really bad comment')
490 expect(abuse2.reporterAccount.name).to.equal('root')
491 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
493 expect(abuse2.video).to.be.null
495 expect(abuse2.comment.deleted).to.be.false
496 expect(abuse2.comment.id).to.equal(commentServer2.id)
497 expect(abuse2.comment.text).to.equal(commentServer2.text)
498 expect(abuse2.comment.video.name).to.equal('server 2')
499 expect(abuse2.comment.video.uuid).to.equal(servers[1].store.videoCreated.uuid)
501 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
502 expect(abuse2.state.label).to.equal('Pending')
504 expect(abuse2.moderationComment).to.be.null
506 expect(abuse2.countReportsForReporter).to.equal(6)
507 expect(abuse2.countReportsForReportee).to.equal(2)
511 const body = await commands[1].getAdminList({ filter: 'comment' })
512 expect(body.total).to.equal(1)
513 expect(body.data.length).to.equal(1)
515 abuseServer2 = body.data[0]
516 expect(abuseServer2.reason).to.equal('it is a really bad comment')
517 expect(abuseServer2.reporterAccount.name).to.equal('root')
518 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
520 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
521 expect(abuseServer2.state.label).to.equal('Pending')
523 expect(abuseServer2.moderationComment).to.be.null
525 expect(abuseServer2.countReportsForReporter).to.equal(1)
526 expect(abuseServer2.countReportsForReportee).to.equal(1)
530 it('Should keep the comment abuse when deleting the comment', async function () {
533 const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.id)
535 await servers[0].comments.delete({ videoId: servers[1].store.videoCreated.uuid, commentId: commentServer2.id })
537 await waitJobs(servers)
539 const body = await commands[0].getAdminList({ filter: 'comment' })
540 expect(body.total).to.equal(2)
541 expect(body.data).to.have.lengthOf(2)
543 const abuse = body.data.find(a => a.comment?.id === commentServer2.id)
544 expect(abuse).to.not.be.undefined
546 expect(abuse.comment.text).to.be.empty
547 expect(abuse.comment.video.name).to.equal('server 2')
548 expect(abuse.comment.deleted).to.be.true
551 it('Should delete the comment abuse', async function () {
554 await commands[1].delete({ abuseId: abuseServer2.id })
556 await waitJobs(servers)
559 const body = await commands[1].getAdminList({ filter: 'comment' })
560 expect(body.total).to.equal(0)
561 expect(body.data.length).to.equal(0)
565 const body = await commands[0].getAdminList({ filter: 'comment' })
566 expect(body.total).to.equal(2)
570 it('Should list and filter video abuses', async function () {
572 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' })
573 expect(body.total).to.equal(0)
577 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' })
578 expect(body.total).to.equal(2)
582 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' })
583 expect(body.data).to.have.lengthOf(1)
584 expect(body.data[0].comment.text).to.be.empty
588 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' })
589 expect(body.data).to.have.lengthOf(1)
590 expect(body.data[0].comment.text).to.equal('comment server 1')
595 describe('Account abuses', function () {
597 function getAccountFromServer (server: PeerTubeServer, targetName: string, targetServer: PeerTubeServer) {
598 return server.accounts.get({ accountName: targetName + '@' + targetServer.host })
601 before(async function () {
604 await servers[0].users.create({ username: 'user_1', password: 'donald' })
606 const token = await servers[1].users.generateUserAndToken('user_2')
607 await servers[1].videos.upload({ token, attributes: { name: 'super video' } })
609 await waitJobs(servers)
612 it('Should report abuse on an account', async function () {
615 const account = await getAccountFromServer(servers[0], 'user_1', servers[0])
617 const reason = 'it is a bad account'
618 await commands[0].report({ accountId: account.id, reason })
620 await waitJobs(servers)
623 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
625 const body = await commands[0].getAdminList({ filter: 'account' })
627 expect(body.total).to.equal(1)
628 expect(body.data).to.have.lengthOf(1)
630 const abuse = body.data[0]
631 expect(abuse.reason).to.equal('it is a bad account')
633 expect(abuse.reporterAccount.name).to.equal('root')
634 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
636 expect(abuse.video).to.be.null
637 expect(abuse.comment).to.be.null
639 expect(abuse.flaggedAccount.name).to.equal('user_1')
640 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
644 const body = await commands[1].getAdminList({ filter: 'comment' })
645 expect(body.total).to.equal(0)
646 expect(body.data.length).to.equal(0)
650 it('Should report abuse on a remote account', async function () {
653 const account = await getAccountFromServer(servers[0], 'user_2', servers[1])
655 const reason = 'it is a really bad account'
656 await commands[0].report({ accountId: account.id, reason })
658 await waitJobs(servers)
661 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
663 const body = await commands[0].getAdminList({ filter: 'account' })
664 expect(body.total).to.equal(2)
665 expect(body.data.length).to.equal(2)
667 const abuse: AdminAbuse = body.data[0]
668 expect(abuse.reason).to.equal('it is a bad account')
670 const abuse2: AdminAbuse = body.data[1]
671 expect(abuse2.reason).to.equal('it is a really bad account')
673 expect(abuse2.reporterAccount.name).to.equal('root')
674 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
676 expect(abuse2.video).to.be.null
677 expect(abuse2.comment).to.be.null
679 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
680 expect(abuse2.state.label).to.equal('Pending')
682 expect(abuse2.moderationComment).to.be.null
686 const body = await commands[1].getAdminList({ filter: 'account' })
687 expect(body.total).to.equal(1)
688 expect(body.data.length).to.equal(1)
690 abuseServer2 = body.data[0]
692 expect(abuseServer2.reason).to.equal('it is a really bad account')
694 expect(abuseServer2.reporterAccount.name).to.equal('root')
695 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
697 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
698 expect(abuseServer2.state.label).to.equal('Pending')
700 expect(abuseServer2.moderationComment).to.be.null
704 it('Should keep the account abuse when deleting the account', async function () {
707 const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
708 await servers[1].users.remove({ userId: account.userId })
710 await waitJobs(servers)
712 const body = await commands[0].getAdminList({ filter: 'account' })
713 expect(body.total).to.equal(2)
714 expect(body.data).to.have.lengthOf(2)
716 const abuse = body.data.find(a => a.reason === 'it is a really bad account')
717 expect(abuse).to.not.be.undefined
720 it('Should delete the account abuse', async function () {
723 await commands[1].delete({ abuseId: abuseServer2.id })
725 await waitJobs(servers)
728 const body = await commands[1].getAdminList({ filter: 'account' })
729 expect(body.total).to.equal(0)
730 expect(body.data.length).to.equal(0)
734 const body = await commands[0].getAdminList({ filter: 'account' })
735 expect(body.total).to.equal(2)
737 abuseServer1 = body.data[0]
742 describe('Common actions on abuses', function () {
744 it('Should update the state of an abuse', async function () {
745 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } })
747 const body = await commands[0].getAdminList({ id: abuseServer1.id })
748 expect(body.data[0].state.id).to.equal(AbuseState.REJECTED)
751 it('Should add a moderation comment', async function () {
752 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } })
754 const body = await commands[0].getAdminList({ id: abuseServer1.id })
755 expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
756 expect(body.data[0].moderationComment).to.equal('Valid')
760 describe('My abuses', async function () {
762 let userAccessToken: string
764 before(async function () {
765 userAccessToken = await servers[0].users.generateUserAndToken('user_42')
767 await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: 'user reason 1' })
769 const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid })
770 await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
773 it('Should correctly list my abuses', async function () {
775 const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
776 expect(body.total).to.equal(2)
778 const abuses = body.data
779 expect(abuses[0].reason).to.equal('user reason 1')
780 expect(abuses[1].reason).to.equal('user reason 2')
782 abuseId1 = abuses[0].id
786 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
787 expect(body.total).to.equal(2)
789 const abuses: UserAbuse[] = body.data
790 expect(abuses[0].reason).to.equal('user reason 2')
794 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
795 expect(body.total).to.equal(2)
797 const abuses: UserAbuse[] = body.data
798 expect(abuses[0].reason).to.equal('user reason 1')
802 it('Should correctly filter my abuses by id', async function () {
803 const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 })
804 expect(body.total).to.equal(1)
806 const abuses: UserAbuse[] = body.data
807 expect(abuses[0].reason).to.equal('user reason 1')
810 it('Should correctly filter my abuses by search', async function () {
811 const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' })
812 expect(body.total).to.equal(1)
814 const abuses: UserAbuse[] = body.data
815 expect(abuses[0].reason).to.equal('user reason 2')
818 it('Should correctly filter my abuses by state', async function () {
819 await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } })
821 const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED })
822 expect(body.total).to.equal(1)
824 const abuses: UserAbuse[] = body.data
825 expect(abuses[0].reason).to.equal('user reason 1')
829 describe('Abuse messages', async function () {
831 let userToken: string
832 let abuseMessageUserId: number
833 let abuseMessageModerationId: number
835 before(async function () {
836 userToken = await servers[0].users.generateUserAndToken('user_43')
838 const body = await commands[0].report({ token: userToken, videoId: servers[0].store.videoCreated.id, reason: 'user 43 reason 1' })
839 abuseId = body.abuse.id
842 it('Should create some messages on the abuse', async function () {
843 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' })
844 await commands[0].addMessage({ abuseId, message: 'message 2' })
845 await commands[0].addMessage({ abuseId, message: 'message 3' })
846 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' })
849 it('Should have the correct messages count when listing abuses', async function () {
850 const results = await Promise.all([
851 commands[0].getAdminList({ start: 0, count: 50 }),
852 commands[0].getUserList({ token: userToken, start: 0, count: 50 })
855 for (const body of results) {
856 const abuses = body.data
857 const abuse = abuses.find(a => a.id === abuseId)
858 expect(abuse.countMessages).to.equal(4)
862 it('Should correctly list messages of this abuse', async function () {
863 const results = await Promise.all([
864 commands[0].listMessages({ abuseId }),
865 commands[0].listMessages({ token: userToken, abuseId })
868 for (const body of results) {
869 expect(body.total).to.equal(4)
871 const abuseMessages: AbuseMessage[] = body.data
873 expect(abuseMessages[0].message).to.equal('message 1')
874 expect(abuseMessages[0].byModerator).to.be.false
875 expect(abuseMessages[0].account.name).to.equal('user_43')
877 abuseMessageUserId = abuseMessages[0].id
879 expect(abuseMessages[1].message).to.equal('message 2')
880 expect(abuseMessages[1].byModerator).to.be.true
881 expect(abuseMessages[1].account.name).to.equal('root')
883 expect(abuseMessages[2].message).to.equal('message 3')
884 expect(abuseMessages[2].byModerator).to.be.true
885 expect(abuseMessages[2].account.name).to.equal('root')
886 abuseMessageModerationId = abuseMessages[2].id
888 expect(abuseMessages[3].message).to.equal('message 4')
889 expect(abuseMessages[3].byModerator).to.be.false
890 expect(abuseMessages[3].account.name).to.equal('user_43')
894 it('Should delete messages', async function () {
895 await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId })
896 await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId })
898 const results = await Promise.all([
899 commands[0].listMessages({ abuseId }),
900 commands[0].listMessages({ token: userToken, abuseId })
903 for (const body of results) {
904 expect(body.total).to.equal(2)
906 const abuseMessages: AbuseMessage[] = body.data
907 expect(abuseMessages[0].message).to.equal('message 2')
908 expect(abuseMessages[1].message).to.equal('message 4')
913 after(async function () {
914 await cleanupTests(servers)