]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-abuse.ts
Add state and moderationComment for abuses on server side
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-abuse.ts
CommitLineData
0e1dc3e7
C
1/* tslint:disable:no-unused-expression */
2
0e1dc3e7 3import * as chai from 'chai'
afffe988 4import 'mocha'
268eebed 5import { VideoAbuse, VideoAbuseState } from '../../../../shared/models/videos'
0e1dc3e7 6import {
268eebed 7 deleteVideoAbuse,
0e1dc3e7 8 flushAndRunMultipleServers,
0e1dc3e7 9 getVideoAbusesList,
afffe988 10 getVideosList,
0e1dc3e7 11 killallServers,
afffe988
C
12 reportVideoAbuse,
13 ServerInfo,
14 setAccessTokensToServers,
268eebed 15 updateVideoAbuse,
3cd0734f 16 uploadVideo
c5d31dba
C
17} from '../../utils/index'
18import { doubleFollow } from '../../utils/server/follows'
3cd0734f 19import { waitJobs } from '../../utils/server/jobs'
afffe988
C
20
21const expect = chai.expect
0e1dc3e7
C
22
23describe('Test video abuses', function () {
24 let servers: ServerInfo[] = []
268eebed 25 let abuseServer2: VideoAbuse
0e1dc3e7
C
26
27 before(async function () {
572f8d3d 28 this.timeout(50000)
0e1dc3e7
C
29
30 // Run servers
31 servers = await flushAndRunMultipleServers(2)
32
33 // Get the access tokens
34 await setAccessTokensToServers(servers)
35
afffe988
C
36 // Server 1 and server 2 follow each other
37 await doubleFollow(servers[0], servers[1])
0e1dc3e7 38
afffe988 39 // Upload some videos on each servers
0e1dc3e7 40 const video1Attributes = {
afffe988
C
41 name: 'my super name for server 1',
42 description: 'my super description for server 1'
0e1dc3e7
C
43 }
44 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
45
46 const video2Attributes = {
afffe988
C
47 name: 'my super name for server 2',
48 description: 'my super description for server 2'
0e1dc3e7
C
49 }
50 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
51
572f8d3d 52 // Wait videos propagation, server 2 has transcoding enabled
3cd0734f 53 await waitJobs(servers)
0e1dc3e7
C
54
55 const res = await getVideosList(servers[0].url)
56 const videos = res.body.data
57
58 expect(videos.length).to.equal(2)
59
afffe988
C
60 servers[0].video = videos.find(video => video.name === 'my super name for server 1')
61 servers[1].video = videos.find(video => video.name === 'my super name for server 2')
0e1dc3e7
C
62 })
63
64 it('Should not have video abuses', async function () {
65 const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
66
67 expect(res.body.total).to.equal(0)
68 expect(res.body.data).to.be.an('array')
69 expect(res.body.data.length).to.equal(0)
70 })
71
72 it('Should report abuse on a local video', async function () {
3cd0734f 73 this.timeout(15000)
0e1dc3e7
C
74
75 const reason = 'my super bad reason'
76 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason)
77
afffe988 78 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
3cd0734f 79 await waitJobs(servers)
0e1dc3e7
C
80 })
81
afffe988 82 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
0e1dc3e7
C
83 const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
84
85 expect(res1.body.total).to.equal(1)
86 expect(res1.body.data).to.be.an('array')
87 expect(res1.body.data.length).to.equal(1)
88
19a3b914 89 const abuse: VideoAbuse = res1.body.data[0]
0e1dc3e7 90 expect(abuse.reason).to.equal('my super bad reason')
19a3b914
C
91 expect(abuse.reporterAccount.name).to.equal('root')
92 expect(abuse.reporterAccount.host).to.equal('localhost:9001')
93 expect(abuse.video.id).to.equal(servers[0].video.id)
0e1dc3e7
C
94
95 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
96 expect(res2.body.total).to.equal(0)
97 expect(res2.body.data).to.be.an('array')
98 expect(res2.body.data.length).to.equal(0)
99 })
100
101 it('Should report abuse on a remote video', async function () {
572f8d3d 102 this.timeout(10000)
0e1dc3e7
C
103
104 const reason = 'my super bad reason 2'
105 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason)
106
107 // We wait requests propagation
3cd0734f 108 await waitJobs(servers)
0e1dc3e7
C
109 })
110
268eebed 111 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
0e1dc3e7
C
112 const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
113 expect(res1.body.total).to.equal(2)
114 expect(res1.body.data).to.be.an('array')
115 expect(res1.body.data.length).to.equal(2)
116
19a3b914 117 const abuse1: VideoAbuse = res1.body.data[0]
0e1dc3e7 118 expect(abuse1.reason).to.equal('my super bad reason')
19a3b914
C
119 expect(abuse1.reporterAccount.name).to.equal('root')
120 expect(abuse1.reporterAccount.host).to.equal('localhost:9001')
121 expect(abuse1.video.id).to.equal(servers[0].video.id)
268eebed
C
122 expect(abuse1.state.id).to.equal(VideoAbuseState.PENDING)
123 expect(abuse1.state.label).to.equal('Pending')
124 expect(abuse1.moderationComment).to.be.null
0e1dc3e7 125
19a3b914 126 const abuse2: VideoAbuse = res1.body.data[1]
0e1dc3e7 127 expect(abuse2.reason).to.equal('my super bad reason 2')
19a3b914
C
128 expect(abuse2.reporterAccount.name).to.equal('root')
129 expect(abuse2.reporterAccount.host).to.equal('localhost:9001')
130 expect(abuse2.video.id).to.equal(servers[1].video.id)
268eebed
C
131 expect(abuse2.state.id).to.equal(VideoAbuseState.PENDING)
132 expect(abuse2.state.label).to.equal('Pending')
133 expect(abuse2.moderationComment).to.be.null
0e1dc3e7
C
134
135 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
136 expect(res2.body.total).to.equal(1)
137 expect(res2.body.data).to.be.an('array')
138 expect(res2.body.data.length).to.equal(1)
139
268eebed
C
140 abuseServer2 = res2.body.data[0]
141 expect(abuseServer2.reason).to.equal('my super bad reason 2')
142 expect(abuseServer2.reporterAccount.name).to.equal('root')
143 expect(abuseServer2.reporterAccount.host).to.equal('localhost:9001')
144 expect(abuseServer2.state.id).to.equal(VideoAbuseState.PENDING)
145 expect(abuseServer2.state.label).to.equal('Pending')
146 expect(abuseServer2.moderationComment).to.be.null
147 })
148
149 it('Should update the state of a video abuse', async function () {
150 const body = { state: VideoAbuseState.REJECTED }
151 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body)
152
153 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
154 expect(res.body.data[0].state.id).to.equal(VideoAbuseState.REJECTED)
155 })
156
157 it('Should add a moderation comment', async function () {
158 const body = { state: VideoAbuseState.ACCEPTED, moderationComment: 'It is valid' }
159 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body)
160
161 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
162 expect(res.body.data[0].state.id).to.equal(VideoAbuseState.ACCEPTED)
163 expect(res.body.data[0].moderationComment).to.equal('It is valid')
164 })
165
166 it('Should delete the video abuse', async function () {
167 await deleteVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id)
168
169 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
170 expect(res.body.total).to.equal(0)
171 expect(res.body.data).to.be.an('array')
172 expect(res.body.data.length).to.equal(0)
0e1dc3e7
C
173 })
174
175 after(async function () {
176 killallServers(servers)
0e1dc3e7
C
177 })
178})