]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-abuse.ts
Merge branch 'master' into develop
[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 {
7c3b7976 7 cleanupTests,
268eebed 8 deleteVideoAbuse,
0e1dc3e7 9 flushAndRunMultipleServers,
0e1dc3e7 10 getVideoAbusesList,
afffe988 11 getVideosList,
0e1dc3e7 12 killallServers,
afffe988
C
13 reportVideoAbuse,
14 ServerInfo,
15 setAccessTokensToServers,
268eebed 16 updateVideoAbuse,
3cd0734f 17 uploadVideo
94565d52
C
18} from '../../../../shared/extra-utils/index'
19import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
20import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
afffe988
C
21
22const expect = chai.expect
0e1dc3e7
C
23
24describe('Test video abuses', function () {
25 let servers: ServerInfo[] = []
268eebed 26 let abuseServer2: VideoAbuse
0e1dc3e7
C
27
28 before(async function () {
572f8d3d 29 this.timeout(50000)
0e1dc3e7
C
30
31 // Run servers
32 servers = await flushAndRunMultipleServers(2)
33
34 // Get the access tokens
35 await setAccessTokensToServers(servers)
36
afffe988
C
37 // Server 1 and server 2 follow each other
38 await doubleFollow(servers[0], servers[1])
0e1dc3e7 39
afffe988 40 // Upload some videos on each servers
0e1dc3e7 41 const video1Attributes = {
afffe988
C
42 name: 'my super name for server 1',
43 description: 'my super description for server 1'
0e1dc3e7
C
44 }
45 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
46
47 const video2Attributes = {
afffe988
C
48 name: 'my super name for server 2',
49 description: 'my super description for server 2'
0e1dc3e7
C
50 }
51 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
52
572f8d3d 53 // Wait videos propagation, server 2 has transcoding enabled
3cd0734f 54 await waitJobs(servers)
0e1dc3e7
C
55
56 const res = await getVideosList(servers[0].url)
57 const videos = res.body.data
58
59 expect(videos.length).to.equal(2)
60
afffe988
C
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')
0e1dc3e7
C
63 })
64
65 it('Should not have video abuses', async function () {
66 const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
67
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)
71 })
72
73 it('Should report abuse on a local video', async function () {
3cd0734f 74 this.timeout(15000)
0e1dc3e7
C
75
76 const reason = 'my super bad reason'
77 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason)
78
afffe988 79 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
3cd0734f 80 await waitJobs(servers)
0e1dc3e7
C
81 })
82
afffe988 83 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
0e1dc3e7
C
84 const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
85
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)
89
19a3b914 90 const abuse: VideoAbuse = res1.body.data[0]
0e1dc3e7 91 expect(abuse.reason).to.equal('my super bad reason')
19a3b914
C
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)
0e1dc3e7
C
95
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)
100 })
101
102 it('Should report abuse on a remote video', async function () {
572f8d3d 103 this.timeout(10000)
0e1dc3e7
C
104
105 const reason = 'my super bad reason 2'
106 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason)
107
108 // We wait requests propagation
3cd0734f 109 await waitJobs(servers)
0e1dc3e7
C
110 })
111
268eebed 112 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
0e1dc3e7
C
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)
117
19a3b914 118 const abuse1: VideoAbuse = res1.body.data[0]
0e1dc3e7 119 expect(abuse1.reason).to.equal('my super bad reason')
19a3b914
C
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)
268eebed
C
123 expect(abuse1.state.id).to.equal(VideoAbuseState.PENDING)
124 expect(abuse1.state.label).to.equal('Pending')
125 expect(abuse1.moderationComment).to.be.null
0e1dc3e7 126
19a3b914 127 const abuse2: VideoAbuse = res1.body.data[1]
0e1dc3e7 128 expect(abuse2.reason).to.equal('my super bad reason 2')
19a3b914
C
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)
268eebed
C
132 expect(abuse2.state.id).to.equal(VideoAbuseState.PENDING)
133 expect(abuse2.state.label).to.equal('Pending')
134 expect(abuse2.moderationComment).to.be.null
0e1dc3e7
C
135
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)
140
268eebed
C
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
148 })
149
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)
153
154 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
155 expect(res.body.data[0].state.id).to.equal(VideoAbuseState.REJECTED)
156 })
157
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)
161
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')
165 })
166
167 it('Should delete the video abuse', async function () {
168 await deleteVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id)
169
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)
0e1dc3e7
C
174 })
175
7c3b7976
C
176 after(async function () {
177 await cleanupTests(servers)
0e1dc3e7
C
178 })
179})