1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
4 import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultAccountAvatar,
13 setDefaultChannelAvatar,
15 } from '@shared/server-commands'
17 const expect = chai.expect
19 describe('Test abuses', function () {
20 let servers: PeerTubeServer[] = []
21 let abuseServer1: AdminAbuse
22 let abuseServer2: AdminAbuse
23 let commands: AbusesCommand[]
25 before(async function () {
29 servers = await createMultipleServers(2)
31 await setAccessTokensToServers(servers)
32 await setDefaultChannelAvatar(servers)
33 await setDefaultAccountAvatar(servers)
35 // Server 1 and server 2 follow each other
36 await doubleFollow(servers[0], servers[1])
38 commands = servers.map(s => s.abuses)
41 describe('Video abuses', function () {
43 before(async function () {
46 // Upload some videos on each servers
49 name: 'my super name for server 1',
50 description: 'my super description for server 1'
52 await servers[0].videos.upload({ attributes })
57 name: 'my super name for server 2',
58 description: 'my super description for server 2'
60 await servers[1].videos.upload({ attributes })
63 // Wait videos propagation, server 2 has transcoding enabled
64 await waitJobs(servers)
66 const { data } = await servers[0].videos.list()
67 expect(data.length).to.equal(2)
69 servers[0].store.videoCreated = data.find(video => video.name === 'my super name for server 1')
70 servers[1].store.videoCreated = data.find(video => video.name === 'my super name for server 2')
73 it('Should not have abuses', async function () {
74 const body = await commands[0].getAdminList()
76 expect(body.total).to.equal(0)
77 expect(body.data).to.be.an('array')
78 expect(body.data.length).to.equal(0)
81 it('Should report abuse on a local video', async function () {
84 const reason = 'my super bad reason'
85 await commands[0].report({ videoId: servers[0].store.videoCreated.id, reason })
87 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
88 await waitJobs(servers)
91 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
93 const body = await commands[0].getAdminList()
95 expect(body.total).to.equal(1)
96 expect(body.data).to.be.an('array')
97 expect(body.data.length).to.equal(1)
99 const abuse = body.data[0]
100 expect(abuse.reason).to.equal('my super bad reason')
102 expect(abuse.reporterAccount.name).to.equal('root')
103 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
105 expect(abuse.video.id).to.equal(servers[0].store.videoCreated.id)
106 expect(abuse.video.channel).to.exist
108 expect(abuse.comment).to.be.null
110 expect(abuse.flaggedAccount.name).to.equal('root')
111 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
113 expect(abuse.video.countReports).to.equal(1)
114 expect(abuse.video.nthReport).to.equal(1)
116 expect(abuse.countReportsForReporter).to.equal(1)
117 expect(abuse.countReportsForReportee).to.equal(1)
121 const body = await commands[1].getAdminList()
122 expect(body.total).to.equal(0)
123 expect(body.data).to.be.an('array')
124 expect(body.data.length).to.equal(0)
128 it('Should report abuse on a remote video', async function () {
131 const reason = 'my super bad reason 2'
132 const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid })
133 await commands[0].report({ videoId, reason })
135 // We wait requests propagation
136 await waitJobs(servers)
139 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
141 const body = await commands[0].getAdminList()
143 expect(body.total).to.equal(2)
144 expect(body.data.length).to.equal(2)
146 const abuse1 = body.data[0]
147 expect(abuse1.reason).to.equal('my super bad reason')
148 expect(abuse1.reporterAccount.name).to.equal('root')
149 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
151 expect(abuse1.video.id).to.equal(servers[0].store.videoCreated.id)
152 expect(abuse1.video.countReports).to.equal(1)
153 expect(abuse1.video.nthReport).to.equal(1)
155 expect(abuse1.comment).to.be.null
157 expect(abuse1.flaggedAccount.name).to.equal('root')
158 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
160 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
161 expect(abuse1.state.label).to.equal('Pending')
162 expect(abuse1.moderationComment).to.be.null
164 const abuse2 = body.data[1]
165 expect(abuse2.reason).to.equal('my super bad reason 2')
167 expect(abuse2.reporterAccount.name).to.equal('root')
168 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
170 expect(abuse2.video.uuid).to.equal(servers[1].store.videoCreated.uuid)
172 expect(abuse2.comment).to.be.null
174 expect(abuse2.flaggedAccount.name).to.equal('root')
175 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
177 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
178 expect(abuse2.state.label).to.equal('Pending')
179 expect(abuse2.moderationComment).to.be.null
183 const body = await commands[1].getAdminList()
184 expect(body.total).to.equal(1)
185 expect(body.data.length).to.equal(1)
187 abuseServer2 = body.data[0]
188 expect(abuseServer2.reason).to.equal('my super bad reason 2')
189 expect(abuseServer2.reporterAccount.name).to.equal('root')
190 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
192 expect(abuseServer2.flaggedAccount.name).to.equal('root')
193 expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host)
195 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
196 expect(abuseServer2.state.label).to.equal('Pending')
197 expect(abuseServer2.moderationComment).to.be.null
201 it('Should hide video abuses from blocked accounts', async function () {
205 const videoId = await servers[1].videos.getId({ uuid: servers[0].store.videoCreated.uuid })
206 await commands[1].report({ videoId, reason: 'will mute this' })
207 await waitJobs(servers)
209 const body = await commands[0].getAdminList()
210 expect(body.total).to.equal(3)
213 const accountToBlock = 'root@' + servers[1].host
216 await servers[0].blocklist.addToServerBlocklist({ account: accountToBlock })
218 const body = await commands[0].getAdminList()
219 expect(body.total).to.equal(2)
221 const abuse = body.data.find(a => a.reason === 'will mute this')
222 expect(abuse).to.be.undefined
226 await servers[0].blocklist.removeFromServerBlocklist({ account: accountToBlock })
228 const body = await commands[0].getAdminList()
229 expect(body.total).to.equal(3)
233 it('Should hide video abuses from blocked servers', async function () {
234 const serverToBlock = servers[1].host
237 await servers[0].blocklist.addToServerBlocklist({ server: serverToBlock })
239 const body = await commands[0].getAdminList()
240 expect(body.total).to.equal(2)
242 const abuse = body.data.find(a => a.reason === 'will mute this')
243 expect(abuse).to.be.undefined
247 await servers[0].blocklist.removeFromServerBlocklist({ server: serverToBlock })
249 const body = await commands[0].getAdminList()
250 expect(body.total).to.equal(3)
254 it('Should keep the video abuse when deleting the video', async function () {
257 await servers[1].videos.remove({ id: abuseServer2.video.uuid })
259 await waitJobs(servers)
261 const body = await commands[1].getAdminList()
262 expect(body.total).to.equal(2, 'wrong number of videos returned')
263 expect(body.data).to.have.lengthOf(2, 'wrong number of videos returned')
265 const abuse = body.data[0]
266 expect(abuse.id).to.equal(abuseServer2.id, 'wrong origin server id for first video')
267 expect(abuse.video.id).to.equal(abuseServer2.video.id, 'wrong video id')
268 expect(abuse.video.channel).to.exist
269 expect(abuse.video.deleted).to.be.true
272 it('Should include counts of reports from reporter and reportee', async function () {
275 // register a second user to have two reporters/reportees
276 const user = { username: 'user2', password: 'password' }
277 await servers[0].users.create({ ...user })
278 const userAccessToken = await servers[0].login.getAccessToken(user)
280 // upload a third video via this user
282 name: 'my second super name for server 1',
283 description: 'my second super description for server 1'
285 const { id } = await servers[0].videos.upload({ token: userAccessToken, attributes })
288 // resume with the test
289 const reason3 = 'my super bad reason 3'
290 await commands[0].report({ videoId: video3Id, reason: reason3 })
292 const reason4 = 'my super bad reason 4'
293 await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: reason4 })
296 const body = await commands[0].getAdminList()
297 const abuses = body.data
299 const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
300 expect(abuseVideo3).to.not.be.undefined
301 expect(abuseVideo3.video.countReports).to.equal(1, 'wrong reports count for video 3')
302 expect(abuseVideo3.video.nthReport).to.equal(1, 'wrong report position in report list for video 3')
303 expect(abuseVideo3.countReportsForReportee).to.equal(1, 'wrong reports count for reporter on video 3 abuse')
304 expect(abuseVideo3.countReportsForReporter).to.equal(3, 'wrong reports count for reportee on video 3 abuse')
306 const abuseServer1 = abuses.find(a => a.video.id === servers[0].store.videoCreated.id)
307 expect(abuseServer1.countReportsForReportee).to.equal(3, 'wrong reports count for reporter on video 1 abuse')
311 it('Should list predefined reasons as well as timestamps for the reported video', async function () {
314 const reason5 = 'my super bad reason 5'
315 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
316 const createRes = await commands[0].report({
317 videoId: servers[0].store.videoCreated.id,
319 predefinedReasons: predefinedReasons5,
324 const body = await commands[0].getAdminList()
327 const abuse = body.data.find(a => a.id === createRes.abuse.id)
328 expect(abuse.reason).to.equals(reason5)
329 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, 'predefined reasons do not match the one reported')
330 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
331 expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
335 it('Should delete the video abuse', async function () {
338 await commands[1].delete({ abuseId: abuseServer2.id })
340 await waitJobs(servers)
343 const body = await commands[1].getAdminList()
344 expect(body.total).to.equal(1)
345 expect(body.data.length).to.equal(1)
346 expect(body.data[0].id).to.not.equal(abuseServer2.id)
350 const body = await commands[0].getAdminList()
351 expect(body.total).to.equal(6)
355 it('Should list and filter video abuses', async function () {
358 async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) {
359 const body = await commands[0].getAdminList(query)
364 expect(await list({ id: 56 })).to.have.lengthOf(0)
365 expect(await list({ id: 1 })).to.have.lengthOf(1)
367 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4)
368 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
370 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
372 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4)
373 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
375 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
376 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5)
378 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5)
379 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
381 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
382 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
384 expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0)
385 expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6)
387 expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1)
388 expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0)
392 describe('Comment abuses', function () {
394 async function getComment (server: PeerTubeServer, videoIdArg: number | string) {
395 const videoId = typeof videoIdArg === 'string'
396 ? await server.videos.getId({ uuid: videoIdArg })
399 const { data } = await server.comments.listThreads({ videoId })
404 before(async function () {
407 servers[0].store.videoCreated = await servers[0].videos.quickUpload({ name: 'server 1' })
408 servers[1].store.videoCreated = await servers[1].videos.quickUpload({ name: 'server 2' })
410 await servers[0].comments.createThread({ videoId: servers[0].store.videoCreated.id, text: 'comment server 1' })
411 await servers[1].comments.createThread({ videoId: servers[1].store.videoCreated.id, text: 'comment server 2' })
413 await waitJobs(servers)
416 it('Should report abuse on a comment', async function () {
419 const comment = await getComment(servers[0], servers[0].store.videoCreated.id)
421 const reason = 'it is a bad comment'
422 await commands[0].report({ commentId: comment.id, reason })
424 await waitJobs(servers)
427 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
429 const comment = await getComment(servers[0], servers[0].store.videoCreated.id)
430 const body = await commands[0].getAdminList({ filter: 'comment' })
432 expect(body.total).to.equal(1)
433 expect(body.data).to.have.lengthOf(1)
435 const abuse = body.data[0]
436 expect(abuse.reason).to.equal('it is a bad comment')
438 expect(abuse.reporterAccount.name).to.equal('root')
439 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
441 expect(abuse.video).to.be.null
443 expect(abuse.comment.deleted).to.be.false
444 expect(abuse.comment.id).to.equal(comment.id)
445 expect(abuse.comment.text).to.equal(comment.text)
446 expect(abuse.comment.video.name).to.equal('server 1')
447 expect(abuse.comment.video.id).to.equal(servers[0].store.videoCreated.id)
448 expect(abuse.comment.video.uuid).to.equal(servers[0].store.videoCreated.uuid)
450 expect(abuse.countReportsForReporter).to.equal(5)
451 expect(abuse.countReportsForReportee).to.equal(5)
455 const body = await commands[1].getAdminList({ filter: 'comment' })
456 expect(body.total).to.equal(0)
457 expect(body.data.length).to.equal(0)
461 it('Should report abuse on a remote comment', async function () {
464 const comment = await getComment(servers[0], servers[1].store.videoCreated.uuid)
466 const reason = 'it is a really bad comment'
467 await commands[0].report({ commentId: comment.id, reason })
469 await waitJobs(servers)
472 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
473 const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.shortUUID)
476 const body = await commands[0].getAdminList({ filter: 'comment' })
477 expect(body.total).to.equal(2)
478 expect(body.data.length).to.equal(2)
480 const abuse = body.data[0]
481 expect(abuse.reason).to.equal('it is a bad comment')
482 expect(abuse.countReportsForReporter).to.equal(6)
483 expect(abuse.countReportsForReportee).to.equal(5)
485 const abuse2 = body.data[1]
487 expect(abuse2.reason).to.equal('it is a really bad comment')
489 expect(abuse2.reporterAccount.name).to.equal('root')
490 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
492 expect(abuse2.video).to.be.null
494 expect(abuse2.comment.deleted).to.be.false
495 expect(abuse2.comment.id).to.equal(commentServer2.id)
496 expect(abuse2.comment.text).to.equal(commentServer2.text)
497 expect(abuse2.comment.video.name).to.equal('server 2')
498 expect(abuse2.comment.video.uuid).to.equal(servers[1].store.videoCreated.uuid)
500 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
501 expect(abuse2.state.label).to.equal('Pending')
503 expect(abuse2.moderationComment).to.be.null
505 expect(abuse2.countReportsForReporter).to.equal(6)
506 expect(abuse2.countReportsForReportee).to.equal(2)
510 const body = await commands[1].getAdminList({ filter: 'comment' })
511 expect(body.total).to.equal(1)
512 expect(body.data.length).to.equal(1)
514 abuseServer2 = body.data[0]
515 expect(abuseServer2.reason).to.equal('it is a really bad comment')
516 expect(abuseServer2.reporterAccount.name).to.equal('root')
517 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
519 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
520 expect(abuseServer2.state.label).to.equal('Pending')
522 expect(abuseServer2.moderationComment).to.be.null
524 expect(abuseServer2.countReportsForReporter).to.equal(1)
525 expect(abuseServer2.countReportsForReportee).to.equal(1)
529 it('Should keep the comment abuse when deleting the comment', async function () {
532 const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.uuid)
534 await servers[0].comments.delete({ videoId: servers[1].store.videoCreated.uuid, commentId: commentServer2.id })
536 await waitJobs(servers)
538 const body = await commands[0].getAdminList({ filter: 'comment' })
539 expect(body.total).to.equal(2)
540 expect(body.data).to.have.lengthOf(2)
542 const abuse = body.data.find(a => a.comment?.id === commentServer2.id)
543 expect(abuse).to.not.be.undefined
545 expect(abuse.comment.text).to.be.empty
546 expect(abuse.comment.video.name).to.equal('server 2')
547 expect(abuse.comment.deleted).to.be.true
550 it('Should delete the comment abuse', async function () {
553 await commands[1].delete({ abuseId: abuseServer2.id })
555 await waitJobs(servers)
558 const body = await commands[1].getAdminList({ filter: 'comment' })
559 expect(body.total).to.equal(0)
560 expect(body.data.length).to.equal(0)
564 const body = await commands[0].getAdminList({ filter: 'comment' })
565 expect(body.total).to.equal(2)
569 it('Should list and filter video abuses', async function () {
571 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' })
572 expect(body.total).to.equal(0)
576 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' })
577 expect(body.total).to.equal(2)
581 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' })
582 expect(body.data).to.have.lengthOf(1)
583 expect(body.data[0].comment.text).to.be.empty
587 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' })
588 expect(body.data).to.have.lengthOf(1)
589 expect(body.data[0].comment.text).to.equal('comment server 1')
594 describe('Account abuses', function () {
596 function getAccountFromServer (server: PeerTubeServer, targetName: string, targetServer: PeerTubeServer) {
597 return server.accounts.get({ accountName: targetName + '@' + targetServer.host })
600 before(async function () {
603 await servers[0].users.create({ username: 'user_1', password: 'donald' })
605 const token = await servers[1].users.generateUserAndToken('user_2')
606 await servers[1].videos.upload({ token, attributes: { name: 'super video' } })
608 await waitJobs(servers)
611 it('Should report abuse on an account', async function () {
614 const account = await getAccountFromServer(servers[0], 'user_1', servers[0])
616 const reason = 'it is a bad account'
617 await commands[0].report({ accountId: account.id, reason })
619 await waitJobs(servers)
622 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
624 const body = await commands[0].getAdminList({ filter: 'account' })
626 expect(body.total).to.equal(1)
627 expect(body.data).to.have.lengthOf(1)
629 const abuse = body.data[0]
630 expect(abuse.reason).to.equal('it is a bad account')
632 expect(abuse.reporterAccount.name).to.equal('root')
633 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
635 expect(abuse.video).to.be.null
636 expect(abuse.comment).to.be.null
638 expect(abuse.flaggedAccount.name).to.equal('user_1')
639 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
643 const body = await commands[1].getAdminList({ filter: 'comment' })
644 expect(body.total).to.equal(0)
645 expect(body.data.length).to.equal(0)
649 it('Should report abuse on a remote account', async function () {
652 const account = await getAccountFromServer(servers[0], 'user_2', servers[1])
654 const reason = 'it is a really bad account'
655 await commands[0].report({ accountId: account.id, reason })
657 await waitJobs(servers)
660 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
662 const body = await commands[0].getAdminList({ filter: 'account' })
663 expect(body.total).to.equal(2)
664 expect(body.data.length).to.equal(2)
666 const abuse: AdminAbuse = body.data[0]
667 expect(abuse.reason).to.equal('it is a bad account')
669 const abuse2: AdminAbuse = body.data[1]
670 expect(abuse2.reason).to.equal('it is a really bad account')
672 expect(abuse2.reporterAccount.name).to.equal('root')
673 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
675 expect(abuse2.video).to.be.null
676 expect(abuse2.comment).to.be.null
678 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
679 expect(abuse2.state.label).to.equal('Pending')
681 expect(abuse2.moderationComment).to.be.null
685 const body = await commands[1].getAdminList({ filter: 'account' })
686 expect(body.total).to.equal(1)
687 expect(body.data.length).to.equal(1)
689 abuseServer2 = body.data[0]
691 expect(abuseServer2.reason).to.equal('it is a really bad account')
693 expect(abuseServer2.reporterAccount.name).to.equal('root')
694 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
696 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
697 expect(abuseServer2.state.label).to.equal('Pending')
699 expect(abuseServer2.moderationComment).to.be.null
703 it('Should keep the account abuse when deleting the account', async function () {
706 const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
707 await servers[1].users.remove({ userId: account.userId })
709 await waitJobs(servers)
711 const body = await commands[0].getAdminList({ filter: 'account' })
712 expect(body.total).to.equal(2)
713 expect(body.data).to.have.lengthOf(2)
715 const abuse = body.data.find(a => a.reason === 'it is a really bad account')
716 expect(abuse).to.not.be.undefined
719 it('Should delete the account abuse', async function () {
722 await commands[1].delete({ abuseId: abuseServer2.id })
724 await waitJobs(servers)
727 const body = await commands[1].getAdminList({ filter: 'account' })
728 expect(body.total).to.equal(0)
729 expect(body.data.length).to.equal(0)
733 const body = await commands[0].getAdminList({ filter: 'account' })
734 expect(body.total).to.equal(2)
736 abuseServer1 = body.data[0]
741 describe('Common actions on abuses', function () {
743 it('Should update the state of an abuse', async function () {
744 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } })
746 const body = await commands[0].getAdminList({ id: abuseServer1.id })
747 expect(body.data[0].state.id).to.equal(AbuseState.REJECTED)
750 it('Should add a moderation comment', async function () {
751 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } })
753 const body = await commands[0].getAdminList({ id: abuseServer1.id })
754 expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
755 expect(body.data[0].moderationComment).to.equal('Valid')
759 describe('My abuses', async function () {
761 let userAccessToken: string
763 before(async function () {
764 userAccessToken = await servers[0].users.generateUserAndToken('user_42')
766 await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: 'user reason 1' })
768 const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid })
769 await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
772 it('Should correctly list my abuses', async function () {
774 const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
775 expect(body.total).to.equal(2)
777 const abuses = body.data
778 expect(abuses[0].reason).to.equal('user reason 1')
779 expect(abuses[1].reason).to.equal('user reason 2')
781 abuseId1 = abuses[0].id
785 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
786 expect(body.total).to.equal(2)
788 const abuses: UserAbuse[] = body.data
789 expect(abuses[0].reason).to.equal('user reason 2')
793 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
794 expect(body.total).to.equal(2)
796 const abuses: UserAbuse[] = body.data
797 expect(abuses[0].reason).to.equal('user reason 1')
801 it('Should correctly filter my abuses by id', async function () {
802 const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 })
803 expect(body.total).to.equal(1)
805 const abuses: UserAbuse[] = body.data
806 expect(abuses[0].reason).to.equal('user reason 1')
809 it('Should correctly filter my abuses by search', async function () {
810 const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' })
811 expect(body.total).to.equal(1)
813 const abuses: UserAbuse[] = body.data
814 expect(abuses[0].reason).to.equal('user reason 2')
817 it('Should correctly filter my abuses by state', async function () {
818 await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } })
820 const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED })
821 expect(body.total).to.equal(1)
823 const abuses: UserAbuse[] = body.data
824 expect(abuses[0].reason).to.equal('user reason 1')
828 describe('Abuse messages', async function () {
830 let userToken: string
831 let abuseMessageUserId: number
832 let abuseMessageModerationId: number
834 before(async function () {
835 userToken = await servers[0].users.generateUserAndToken('user_43')
837 const body = await commands[0].report({ token: userToken, videoId: servers[0].store.videoCreated.id, reason: 'user 43 reason 1' })
838 abuseId = body.abuse.id
841 it('Should create some messages on the abuse', async function () {
842 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' })
843 await commands[0].addMessage({ abuseId, message: 'message 2' })
844 await commands[0].addMessage({ abuseId, message: 'message 3' })
845 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' })
848 it('Should have the correct messages count when listing abuses', async function () {
849 const results = await Promise.all([
850 commands[0].getAdminList({ start: 0, count: 50 }),
851 commands[0].getUserList({ token: userToken, start: 0, count: 50 })
854 for (const body of results) {
855 const abuses = body.data
856 const abuse = abuses.find(a => a.id === abuseId)
857 expect(abuse.countMessages).to.equal(4)
861 it('Should correctly list messages of this abuse', async function () {
862 const results = await Promise.all([
863 commands[0].listMessages({ abuseId }),
864 commands[0].listMessages({ token: userToken, abuseId })
867 for (const body of results) {
868 expect(body.total).to.equal(4)
870 const abuseMessages: AbuseMessage[] = body.data
872 expect(abuseMessages[0].message).to.equal('message 1')
873 expect(abuseMessages[0].byModerator).to.be.false
874 expect(abuseMessages[0].account.name).to.equal('user_43')
876 abuseMessageUserId = abuseMessages[0].id
878 expect(abuseMessages[1].message).to.equal('message 2')
879 expect(abuseMessages[1].byModerator).to.be.true
880 expect(abuseMessages[1].account.name).to.equal('root')
882 expect(abuseMessages[2].message).to.equal('message 3')
883 expect(abuseMessages[2].byModerator).to.be.true
884 expect(abuseMessages[2].account.name).to.equal('root')
885 abuseMessageModerationId = abuseMessages[2].id
887 expect(abuseMessages[3].message).to.equal('message 4')
888 expect(abuseMessages[3].byModerator).to.be.false
889 expect(abuseMessages[3].account.name).to.equal('user_43')
893 it('Should delete messages', async function () {
894 await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId })
895 await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId })
897 const results = await Promise.all([
898 commands[0].listMessages({ abuseId }),
899 commands[0].listMessages({ token: userToken, abuseId })
902 for (const body of results) {
903 expect(body.total).to.equal(2)
905 const abuseMessages: AbuseMessage[] = body.data
906 expect(abuseMessages[0].message).to.equal('message 2')
907 expect(abuseMessages[1].message).to.equal('message 4')
912 after(async function () {
913 await cleanupTests(servers)