1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { VideoAbuse, VideoAbuseState } from '../../../../shared/models/videos'
9 flushAndRunMultipleServers,
15 setAccessTokensToServers,
18 } from '../../../../shared/extra-utils/index'
19 import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
20 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
22 const expect = chai.expect
24 describe('Test video abuses', function () {
25 let servers: ServerInfo[] = []
26 let abuseServer2: VideoAbuse
28 before(async function () {
32 servers = await flushAndRunMultipleServers(2)
34 // Get the access tokens
35 await setAccessTokensToServers(servers)
37 // Server 1 and server 2 follow each other
38 await doubleFollow(servers[0], servers[1])
40 // Upload some videos on each servers
41 const video1Attributes = {
42 name: 'my super name for server 1',
43 description: 'my super description for server 1'
45 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
47 const video2Attributes = {
48 name: 'my super name for server 2',
49 description: 'my super description for server 2'
51 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
53 // Wait videos propagation, server 2 has transcoding enabled
54 await waitJobs(servers)
56 const res = await getVideosList(servers[0].url)
57 const videos = res.body.data
59 expect(videos.length).to.equal(2)
61 servers[0].video = videos.find(video => video.name === 'my super name for server 1')
62 servers[1].video = videos.find(video => video.name === 'my super name for server 2')
65 it('Should not have video abuses', async function () {
66 const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
68 expect(res.body.total).to.equal(0)
69 expect(res.body.data).to.be.an('array')
70 expect(res.body.data.length).to.equal(0)
73 it('Should report abuse on a local video', async function () {
76 const reason = 'my super bad reason'
77 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason)
79 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
80 await waitJobs(servers)
83 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
84 const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
86 expect(res1.body.total).to.equal(1)
87 expect(res1.body.data).to.be.an('array')
88 expect(res1.body.data.length).to.equal(1)
90 const abuse: VideoAbuse = res1.body.data[0]
91 expect(abuse.reason).to.equal('my super bad reason')
92 expect(abuse.reporterAccount.name).to.equal('root')
93 expect(abuse.reporterAccount.host).to.equal('localhost:9001')
94 expect(abuse.video.id).to.equal(servers[0].video.id)
96 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
97 expect(res2.body.total).to.equal(0)
98 expect(res2.body.data).to.be.an('array')
99 expect(res2.body.data.length).to.equal(0)
102 it('Should report abuse on a remote video', async function () {
105 const reason = 'my super bad reason 2'
106 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason)
108 // We wait requests propagation
109 await waitJobs(servers)
112 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
113 const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
114 expect(res1.body.total).to.equal(2)
115 expect(res1.body.data).to.be.an('array')
116 expect(res1.body.data.length).to.equal(2)
118 const abuse1: VideoAbuse = res1.body.data[0]
119 expect(abuse1.reason).to.equal('my super bad reason')
120 expect(abuse1.reporterAccount.name).to.equal('root')
121 expect(abuse1.reporterAccount.host).to.equal('localhost:9001')
122 expect(abuse1.video.id).to.equal(servers[0].video.id)
123 expect(abuse1.state.id).to.equal(VideoAbuseState.PENDING)
124 expect(abuse1.state.label).to.equal('Pending')
125 expect(abuse1.moderationComment).to.be.null
127 const abuse2: VideoAbuse = res1.body.data[1]
128 expect(abuse2.reason).to.equal('my super bad reason 2')
129 expect(abuse2.reporterAccount.name).to.equal('root')
130 expect(abuse2.reporterAccount.host).to.equal('localhost:9001')
131 expect(abuse2.video.id).to.equal(servers[1].video.id)
132 expect(abuse2.state.id).to.equal(VideoAbuseState.PENDING)
133 expect(abuse2.state.label).to.equal('Pending')
134 expect(abuse2.moderationComment).to.be.null
136 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
137 expect(res2.body.total).to.equal(1)
138 expect(res2.body.data).to.be.an('array')
139 expect(res2.body.data.length).to.equal(1)
141 abuseServer2 = res2.body.data[0]
142 expect(abuseServer2.reason).to.equal('my super bad reason 2')
143 expect(abuseServer2.reporterAccount.name).to.equal('root')
144 expect(abuseServer2.reporterAccount.host).to.equal('localhost:9001')
145 expect(abuseServer2.state.id).to.equal(VideoAbuseState.PENDING)
146 expect(abuseServer2.state.label).to.equal('Pending')
147 expect(abuseServer2.moderationComment).to.be.null
150 it('Should update the state of a video abuse', async function () {
151 const body = { state: VideoAbuseState.REJECTED }
152 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body)
154 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
155 expect(res.body.data[0].state.id).to.equal(VideoAbuseState.REJECTED)
158 it('Should add a moderation comment', async function () {
159 const body = { state: VideoAbuseState.ACCEPTED, moderationComment: 'It is valid' }
160 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body)
162 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
163 expect(res.body.data[0].state.id).to.equal(VideoAbuseState.ACCEPTED)
164 expect(res.body.data[0].moderationComment).to.equal('It is valid')
167 it('Should delete the video abuse', async function () {
168 await deleteVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id)
170 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
171 expect(res.body.total).to.equal(0)
172 expect(res.body.data).to.be.an('array')
173 expect(res.body.data.length).to.equal(0)
176 after(async function () {
177 await cleanupTests(servers)