1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultAccountAvatar,
13 setDefaultChannelAvatar,
15 } from '@shared/server-commands'
17 describe('Test abuses', function () {
18 let servers: PeerTubeServer[] = []
19 let abuseServer1: AdminAbuse
20 let abuseServer2: AdminAbuse
21 let commands: AbusesCommand[]
23 before(async function () {
27 servers = await createMultipleServers(2)
29 await setAccessTokensToServers(servers)
30 await setDefaultChannelAvatar(servers)
31 await setDefaultAccountAvatar(servers)
33 // Server 1 and server 2 follow each other
34 await doubleFollow(servers[0], servers[1])
36 commands = servers.map(s => s.abuses)
39 describe('Video abuses', function () {
41 before(async function () {
44 // Upload some videos on each servers
47 name: 'my super name for server 1',
48 description: 'my super description for server 1'
50 await servers[0].videos.upload({ attributes })
55 name: 'my super name for server 2',
56 description: 'my super description for server 2'
58 await servers[1].videos.upload({ attributes })
61 // Wait videos propagation, server 2 has transcoding enabled
62 await waitJobs(servers)
64 const { data } = await servers[0].videos.list()
65 expect(data.length).to.equal(2)
67 servers[0].store.videoCreated = data.find(video => video.name === 'my super name for server 1')
68 servers[1].store.videoCreated = data.find(video => video.name === 'my super name for server 2')
71 it('Should not have abuses', async function () {
72 const body = await commands[0].getAdminList()
74 expect(body.total).to.equal(0)
75 expect(body.data).to.be.an('array')
76 expect(body.data.length).to.equal(0)
79 it('Should report abuse on a local video', async function () {
82 const reason = 'my super bad reason'
83 await commands[0].report({ videoId: servers[0].store.videoCreated.id, reason })
85 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
86 await waitJobs(servers)
89 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
91 const body = await commands[0].getAdminList()
93 expect(body.total).to.equal(1)
94 expect(body.data).to.be.an('array')
95 expect(body.data.length).to.equal(1)
97 const abuse = body.data[0]
98 expect(abuse.reason).to.equal('my super bad reason')
100 expect(abuse.reporterAccount.name).to.equal('root')
101 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
103 expect(abuse.video.id).to.equal(servers[0].store.videoCreated.id)
104 expect(abuse.video.channel).to.exist
106 expect(abuse.comment).to.be.null
108 expect(abuse.flaggedAccount.name).to.equal('root')
109 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
111 expect(abuse.video.countReports).to.equal(1)
112 expect(abuse.video.nthReport).to.equal(1)
114 expect(abuse.countReportsForReporter).to.equal(1)
115 expect(abuse.countReportsForReportee).to.equal(1)
119 const body = await commands[1].getAdminList()
120 expect(body.total).to.equal(0)
121 expect(body.data).to.be.an('array')
122 expect(body.data.length).to.equal(0)
126 it('Should report abuse on a remote video', async function () {
127 const reason = 'my super bad reason 2'
128 const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid })
129 await commands[0].report({ videoId, reason })
131 // We wait requests propagation
132 await waitJobs(servers)
135 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
137 const body = await commands[0].getAdminList()
139 expect(body.total).to.equal(2)
140 expect(body.data.length).to.equal(2)
142 const abuse1 = body.data[0]
143 expect(abuse1.reason).to.equal('my super bad reason')
144 expect(abuse1.reporterAccount.name).to.equal('root')
145 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
147 expect(abuse1.video.id).to.equal(servers[0].store.videoCreated.id)
148 expect(abuse1.video.countReports).to.equal(1)
149 expect(abuse1.video.nthReport).to.equal(1)
151 expect(abuse1.comment).to.be.null
153 expect(abuse1.flaggedAccount.name).to.equal('root')
154 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
156 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
157 expect(abuse1.state.label).to.equal('Pending')
158 expect(abuse1.moderationComment).to.be.null
160 const abuse2 = body.data[1]
161 expect(abuse2.reason).to.equal('my super bad reason 2')
163 expect(abuse2.reporterAccount.name).to.equal('root')
164 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
166 expect(abuse2.video.uuid).to.equal(servers[1].store.videoCreated.uuid)
168 expect(abuse2.comment).to.be.null
170 expect(abuse2.flaggedAccount.name).to.equal('root')
171 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
173 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
174 expect(abuse2.state.label).to.equal('Pending')
175 expect(abuse2.moderationComment).to.be.null
179 const body = await commands[1].getAdminList()
180 expect(body.total).to.equal(1)
181 expect(body.data.length).to.equal(1)
183 abuseServer2 = body.data[0]
184 expect(abuseServer2.reason).to.equal('my super bad reason 2')
185 expect(abuseServer2.reporterAccount.name).to.equal('root')
186 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
188 expect(abuseServer2.flaggedAccount.name).to.equal('root')
189 expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host)
191 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
192 expect(abuseServer2.state.label).to.equal('Pending')
193 expect(abuseServer2.moderationComment).to.be.null
197 it('Should hide video abuses from blocked accounts', async function () {
199 const videoId = await servers[1].videos.getId({ uuid: servers[0].store.videoCreated.uuid })
200 await commands[1].report({ videoId, reason: 'will mute this' })
201 await waitJobs(servers)
203 const body = await commands[0].getAdminList()
204 expect(body.total).to.equal(3)
207 const accountToBlock = 'root@' + servers[1].host
210 await servers[0].blocklist.addToServerBlocklist({ account: accountToBlock })
212 const body = await commands[0].getAdminList()
213 expect(body.total).to.equal(2)
215 const abuse = body.data.find(a => a.reason === 'will mute this')
216 expect(abuse).to.be.undefined
220 await servers[0].blocklist.removeFromServerBlocklist({ account: accountToBlock })
222 const body = await commands[0].getAdminList()
223 expect(body.total).to.equal(3)
227 it('Should hide video abuses from blocked servers', async function () {
228 const serverToBlock = servers[1].host
231 await servers[0].blocklist.addToServerBlocklist({ server: serverToBlock })
233 const body = await commands[0].getAdminList()
234 expect(body.total).to.equal(2)
236 const abuse = body.data.find(a => a.reason === 'will mute this')
237 expect(abuse).to.be.undefined
241 await servers[0].blocklist.removeFromServerBlocklist({ server: serverToBlock })
243 const body = await commands[0].getAdminList()
244 expect(body.total).to.equal(3)
248 it('Should keep the video abuse when deleting the video', async function () {
249 await servers[1].videos.remove({ id: abuseServer2.video.uuid })
251 await waitJobs(servers)
253 const body = await commands[1].getAdminList()
254 expect(body.total).to.equal(2, 'wrong number of videos returned')
255 expect(body.data).to.have.lengthOf(2, 'wrong number of videos returned')
257 const abuse = body.data[0]
258 expect(abuse.id).to.equal(abuseServer2.id, 'wrong origin server id for first video')
259 expect(abuse.video.id).to.equal(abuseServer2.video.id, 'wrong video id')
260 expect(abuse.video.channel).to.exist
261 expect(abuse.video.deleted).to.be.true
264 it('Should include counts of reports from reporter and reportee', async function () {
265 // register a second user to have two reporters/reportees
266 const user = { username: 'user2', password: 'password' }
267 await servers[0].users.create({ ...user })
268 const userAccessToken = await servers[0].login.getAccessToken(user)
270 // upload a third video via this user
272 name: 'my second super name for server 1',
273 description: 'my second super description for server 1'
275 const { id } = await servers[0].videos.upload({ token: userAccessToken, attributes })
278 // resume with the test
279 const reason3 = 'my super bad reason 3'
280 await commands[0].report({ videoId: video3Id, reason: reason3 })
282 const reason4 = 'my super bad reason 4'
283 await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: reason4 })
286 const body = await commands[0].getAdminList()
287 const abuses = body.data
289 const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
290 expect(abuseVideo3).to.not.be.undefined
291 expect(abuseVideo3.video.countReports).to.equal(1, 'wrong reports count for video 3')
292 expect(abuseVideo3.video.nthReport).to.equal(1, 'wrong report position in report list for video 3')
293 expect(abuseVideo3.countReportsForReportee).to.equal(1, 'wrong reports count for reporter on video 3 abuse')
294 expect(abuseVideo3.countReportsForReporter).to.equal(3, 'wrong reports count for reportee on video 3 abuse')
296 const abuseServer1 = abuses.find(a => a.video.id === servers[0].store.videoCreated.id)
297 expect(abuseServer1.countReportsForReportee).to.equal(3, 'wrong reports count for reporter on video 1 abuse')
301 it('Should list predefined reasons as well as timestamps for the reported video', async function () {
302 const reason5 = 'my super bad reason 5'
303 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
304 const createRes = await commands[0].report({
305 videoId: servers[0].store.videoCreated.id,
307 predefinedReasons: predefinedReasons5,
312 const body = await commands[0].getAdminList()
315 const abuse = body.data.find(a => a.id === createRes.abuse.id)
316 expect(abuse.reason).to.equals(reason5)
317 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, 'predefined reasons do not match the one reported')
318 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
319 expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
323 it('Should delete the video abuse', async function () {
324 await commands[1].delete({ abuseId: abuseServer2.id })
326 await waitJobs(servers)
329 const body = await commands[1].getAdminList()
330 expect(body.total).to.equal(1)
331 expect(body.data.length).to.equal(1)
332 expect(body.data[0].id).to.not.equal(abuseServer2.id)
336 const body = await commands[0].getAdminList()
337 expect(body.total).to.equal(6)
341 it('Should list and filter video abuses', async function () {
342 async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) {
343 const body = await commands[0].getAdminList(query)
348 expect(await list({ id: 56 })).to.have.lengthOf(0)
349 expect(await list({ id: 1 })).to.have.lengthOf(1)
351 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4)
352 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
354 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
356 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4)
357 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
359 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
360 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5)
362 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5)
363 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
365 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
366 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
368 expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0)
369 expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6)
371 expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1)
372 expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0)
376 describe('Comment abuses', function () {
378 async function getComment (server: PeerTubeServer, videoIdArg: number | string) {
379 const videoId = typeof videoIdArg === 'string'
380 ? await server.videos.getId({ uuid: videoIdArg })
383 const { data } = await server.comments.listThreads({ videoId })
388 before(async function () {
391 servers[0].store.videoCreated = await servers[0].videos.quickUpload({ name: 'server 1' })
392 servers[1].store.videoCreated = await servers[1].videos.quickUpload({ name: 'server 2' })
394 await servers[0].comments.createThread({ videoId: servers[0].store.videoCreated.id, text: 'comment server 1' })
395 await servers[1].comments.createThread({ videoId: servers[1].store.videoCreated.id, text: 'comment server 2' })
397 await waitJobs(servers)
400 it('Should report abuse on a comment', async function () {
403 const comment = await getComment(servers[0], servers[0].store.videoCreated.id)
405 const reason = 'it is a bad comment'
406 await commands[0].report({ commentId: comment.id, reason })
408 await waitJobs(servers)
411 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
413 const comment = await getComment(servers[0], servers[0].store.videoCreated.id)
414 const body = await commands[0].getAdminList({ filter: 'comment' })
416 expect(body.total).to.equal(1)
417 expect(body.data).to.have.lengthOf(1)
419 const abuse = body.data[0]
420 expect(abuse.reason).to.equal('it is a bad comment')
422 expect(abuse.reporterAccount.name).to.equal('root')
423 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
425 expect(abuse.video).to.be.null
427 expect(abuse.comment.deleted).to.be.false
428 expect(abuse.comment.id).to.equal(comment.id)
429 expect(abuse.comment.text).to.equal(comment.text)
430 expect(abuse.comment.video.name).to.equal('server 1')
431 expect(abuse.comment.video.id).to.equal(servers[0].store.videoCreated.id)
432 expect(abuse.comment.video.uuid).to.equal(servers[0].store.videoCreated.uuid)
434 expect(abuse.countReportsForReporter).to.equal(5)
435 expect(abuse.countReportsForReportee).to.equal(5)
439 const body = await commands[1].getAdminList({ filter: 'comment' })
440 expect(body.total).to.equal(0)
441 expect(body.data.length).to.equal(0)
445 it('Should report abuse on a remote comment', async function () {
446 const comment = await getComment(servers[0], servers[1].store.videoCreated.uuid)
448 const reason = 'it is a really bad comment'
449 await commands[0].report({ commentId: comment.id, reason })
451 await waitJobs(servers)
454 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
455 const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.shortUUID)
458 const body = await commands[0].getAdminList({ filter: 'comment' })
459 expect(body.total).to.equal(2)
460 expect(body.data.length).to.equal(2)
462 const abuse = body.data[0]
463 expect(abuse.reason).to.equal('it is a bad comment')
464 expect(abuse.countReportsForReporter).to.equal(6)
465 expect(abuse.countReportsForReportee).to.equal(5)
467 const abuse2 = body.data[1]
469 expect(abuse2.reason).to.equal('it is a really bad comment')
471 expect(abuse2.reporterAccount.name).to.equal('root')
472 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
474 expect(abuse2.video).to.be.null
476 expect(abuse2.comment.deleted).to.be.false
477 expect(abuse2.comment.id).to.equal(commentServer2.id)
478 expect(abuse2.comment.text).to.equal(commentServer2.text)
479 expect(abuse2.comment.video.name).to.equal('server 2')
480 expect(abuse2.comment.video.uuid).to.equal(servers[1].store.videoCreated.uuid)
482 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
483 expect(abuse2.state.label).to.equal('Pending')
485 expect(abuse2.moderationComment).to.be.null
487 expect(abuse2.countReportsForReporter).to.equal(6)
488 expect(abuse2.countReportsForReportee).to.equal(2)
492 const body = await commands[1].getAdminList({ filter: 'comment' })
493 expect(body.total).to.equal(1)
494 expect(body.data.length).to.equal(1)
496 abuseServer2 = body.data[0]
497 expect(abuseServer2.reason).to.equal('it is a really bad comment')
498 expect(abuseServer2.reporterAccount.name).to.equal('root')
499 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
501 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
502 expect(abuseServer2.state.label).to.equal('Pending')
504 expect(abuseServer2.moderationComment).to.be.null
506 expect(abuseServer2.countReportsForReporter).to.equal(1)
507 expect(abuseServer2.countReportsForReportee).to.equal(1)
511 it('Should keep the comment abuse when deleting the comment', async function () {
512 const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.uuid)
514 await servers[0].comments.delete({ videoId: servers[1].store.videoCreated.uuid, commentId: commentServer2.id })
516 await waitJobs(servers)
518 const body = await commands[0].getAdminList({ filter: 'comment' })
519 expect(body.total).to.equal(2)
520 expect(body.data).to.have.lengthOf(2)
522 const abuse = body.data.find(a => a.comment?.id === commentServer2.id)
523 expect(abuse).to.not.be.undefined
525 expect(abuse.comment.text).to.be.empty
526 expect(abuse.comment.video.name).to.equal('server 2')
527 expect(abuse.comment.deleted).to.be.true
530 it('Should delete the comment abuse', async function () {
531 await commands[1].delete({ abuseId: abuseServer2.id })
533 await waitJobs(servers)
536 const body = await commands[1].getAdminList({ filter: 'comment' })
537 expect(body.total).to.equal(0)
538 expect(body.data.length).to.equal(0)
542 const body = await commands[0].getAdminList({ filter: 'comment' })
543 expect(body.total).to.equal(2)
547 it('Should list and filter video abuses', async function () {
549 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' })
550 expect(body.total).to.equal(0)
554 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' })
555 expect(body.total).to.equal(2)
559 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' })
560 expect(body.data).to.have.lengthOf(1)
561 expect(body.data[0].comment.text).to.be.empty
565 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' })
566 expect(body.data).to.have.lengthOf(1)
567 expect(body.data[0].comment.text).to.equal('comment server 1')
572 describe('Account abuses', function () {
574 function getAccountFromServer (server: PeerTubeServer, targetName: string, targetServer: PeerTubeServer) {
575 return server.accounts.get({ accountName: targetName + '@' + targetServer.host })
578 before(async function () {
581 await servers[0].users.create({ username: 'user_1', password: 'donald' })
583 const token = await servers[1].users.generateUserAndToken('user_2')
584 await servers[1].videos.upload({ token, attributes: { name: 'super video' } })
586 await waitJobs(servers)
589 it('Should report abuse on an account', async function () {
592 const account = await getAccountFromServer(servers[0], 'user_1', servers[0])
594 const reason = 'it is a bad account'
595 await commands[0].report({ accountId: account.id, reason })
597 await waitJobs(servers)
600 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
602 const body = await commands[0].getAdminList({ filter: 'account' })
604 expect(body.total).to.equal(1)
605 expect(body.data).to.have.lengthOf(1)
607 const abuse = body.data[0]
608 expect(abuse.reason).to.equal('it is a bad account')
610 expect(abuse.reporterAccount.name).to.equal('root')
611 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
613 expect(abuse.video).to.be.null
614 expect(abuse.comment).to.be.null
616 expect(abuse.flaggedAccount.name).to.equal('user_1')
617 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
621 const body = await commands[1].getAdminList({ filter: 'comment' })
622 expect(body.total).to.equal(0)
623 expect(body.data.length).to.equal(0)
627 it('Should report abuse on a remote account', async function () {
628 const account = await getAccountFromServer(servers[0], 'user_2', servers[1])
630 const reason = 'it is a really bad account'
631 await commands[0].report({ accountId: account.id, reason })
633 await waitJobs(servers)
636 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
638 const body = await commands[0].getAdminList({ filter: 'account' })
639 expect(body.total).to.equal(2)
640 expect(body.data.length).to.equal(2)
642 const abuse: AdminAbuse = body.data[0]
643 expect(abuse.reason).to.equal('it is a bad account')
645 const abuse2: AdminAbuse = body.data[1]
646 expect(abuse2.reason).to.equal('it is a really bad account')
648 expect(abuse2.reporterAccount.name).to.equal('root')
649 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
651 expect(abuse2.video).to.be.null
652 expect(abuse2.comment).to.be.null
654 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
655 expect(abuse2.state.label).to.equal('Pending')
657 expect(abuse2.moderationComment).to.be.null
661 const body = await commands[1].getAdminList({ filter: 'account' })
662 expect(body.total).to.equal(1)
663 expect(body.data.length).to.equal(1)
665 abuseServer2 = body.data[0]
667 expect(abuseServer2.reason).to.equal('it is a really bad account')
669 expect(abuseServer2.reporterAccount.name).to.equal('root')
670 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
672 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
673 expect(abuseServer2.state.label).to.equal('Pending')
675 expect(abuseServer2.moderationComment).to.be.null
679 it('Should keep the account abuse when deleting the account', async function () {
680 const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
681 await servers[1].users.remove({ userId: account.userId })
683 await waitJobs(servers)
685 const body = await commands[0].getAdminList({ filter: 'account' })
686 expect(body.total).to.equal(2)
687 expect(body.data).to.have.lengthOf(2)
689 const abuse = body.data.find(a => a.reason === 'it is a really bad account')
690 expect(abuse).to.not.be.undefined
693 it('Should delete the account abuse', async function () {
694 await commands[1].delete({ abuseId: abuseServer2.id })
696 await waitJobs(servers)
699 const body = await commands[1].getAdminList({ filter: 'account' })
700 expect(body.total).to.equal(0)
701 expect(body.data.length).to.equal(0)
705 const body = await commands[0].getAdminList({ filter: 'account' })
706 expect(body.total).to.equal(2)
708 abuseServer1 = body.data[0]
713 describe('Common actions on abuses', function () {
715 it('Should update the state of an abuse', async function () {
716 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } })
718 const body = await commands[0].getAdminList({ id: abuseServer1.id })
719 expect(body.data[0].state.id).to.equal(AbuseState.REJECTED)
722 it('Should add a moderation comment', async function () {
723 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } })
725 const body = await commands[0].getAdminList({ id: abuseServer1.id })
726 expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
727 expect(body.data[0].moderationComment).to.equal('Valid')
731 describe('My abuses', async function () {
733 let userAccessToken: string
735 before(async function () {
736 userAccessToken = await servers[0].users.generateUserAndToken('user_42')
738 await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: 'user reason 1' })
740 const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid })
741 await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
744 it('Should correctly list my abuses', async function () {
746 const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
747 expect(body.total).to.equal(2)
749 const abuses = body.data
750 expect(abuses[0].reason).to.equal('user reason 1')
751 expect(abuses[1].reason).to.equal('user reason 2')
753 abuseId1 = abuses[0].id
757 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
758 expect(body.total).to.equal(2)
760 const abuses: UserAbuse[] = body.data
761 expect(abuses[0].reason).to.equal('user reason 2')
765 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
766 expect(body.total).to.equal(2)
768 const abuses: UserAbuse[] = body.data
769 expect(abuses[0].reason).to.equal('user reason 1')
773 it('Should correctly filter my abuses by id', async function () {
774 const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 })
775 expect(body.total).to.equal(1)
777 const abuses: UserAbuse[] = body.data
778 expect(abuses[0].reason).to.equal('user reason 1')
781 it('Should correctly filter my abuses by search', async function () {
782 const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' })
783 expect(body.total).to.equal(1)
785 const abuses: UserAbuse[] = body.data
786 expect(abuses[0].reason).to.equal('user reason 2')
789 it('Should correctly filter my abuses by state', async function () {
790 await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } })
792 const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED })
793 expect(body.total).to.equal(1)
795 const abuses: UserAbuse[] = body.data
796 expect(abuses[0].reason).to.equal('user reason 1')
800 describe('Abuse messages', async function () {
802 let userToken: string
803 let abuseMessageUserId: number
804 let abuseMessageModerationId: number
806 before(async function () {
807 userToken = await servers[0].users.generateUserAndToken('user_43')
809 const body = await commands[0].report({ token: userToken, videoId: servers[0].store.videoCreated.id, reason: 'user 43 reason 1' })
810 abuseId = body.abuse.id
813 it('Should create some messages on the abuse', async function () {
814 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' })
815 await commands[0].addMessage({ abuseId, message: 'message 2' })
816 await commands[0].addMessage({ abuseId, message: 'message 3' })
817 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' })
820 it('Should have the correct messages count when listing abuses', async function () {
821 const results = await Promise.all([
822 commands[0].getAdminList({ start: 0, count: 50 }),
823 commands[0].getUserList({ token: userToken, start: 0, count: 50 })
826 for (const body of results) {
827 const abuses = body.data
828 const abuse = abuses.find(a => a.id === abuseId)
829 expect(abuse.countMessages).to.equal(4)
833 it('Should correctly list messages of this abuse', async function () {
834 const results = await Promise.all([
835 commands[0].listMessages({ abuseId }),
836 commands[0].listMessages({ token: userToken, abuseId })
839 for (const body of results) {
840 expect(body.total).to.equal(4)
842 const abuseMessages: AbuseMessage[] = body.data
844 expect(abuseMessages[0].message).to.equal('message 1')
845 expect(abuseMessages[0].byModerator).to.be.false
846 expect(abuseMessages[0].account.name).to.equal('user_43')
848 abuseMessageUserId = abuseMessages[0].id
850 expect(abuseMessages[1].message).to.equal('message 2')
851 expect(abuseMessages[1].byModerator).to.be.true
852 expect(abuseMessages[1].account.name).to.equal('root')
854 expect(abuseMessages[2].message).to.equal('message 3')
855 expect(abuseMessages[2].byModerator).to.be.true
856 expect(abuseMessages[2].account.name).to.equal('root')
857 abuseMessageModerationId = abuseMessages[2].id
859 expect(abuseMessages[3].message).to.equal('message 4')
860 expect(abuseMessages[3].byModerator).to.be.false
861 expect(abuseMessages[3].account.name).to.equal('user_43')
865 it('Should delete messages', async function () {
866 await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId })
867 await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId })
869 const results = await Promise.all([
870 commands[0].listMessages({ abuseId }),
871 commands[0].listMessages({ token: userToken, abuseId })
874 for (const body of results) {
875 expect(body.total).to.equal(2)
877 const abuseMessages: AbuseMessage[] = body.data
878 expect(abuseMessages[0].message).to.equal('message 2')
879 expect(abuseMessages[1].message).to.equal('message 4')
884 after(async function () {
885 await cleanupTests(servers)