]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/video-abuses.js
1 /* eslint-disable no-unused-expressions */
5 const request
= require('supertest')
6 const series
= require('async/series')
8 const loginUtils
= require('../../utils/login')
9 const requestsUtils
= require('../../utils/requests')
10 const serversUtils
= require('../../utils/servers')
11 const usersUtils
= require('../../utils/users')
12 const videosUtils
= require('../../utils/videos')
14 describe('Test video abuses API validators', function () {
16 let userAccessToken
= null
18 // ---------------------------------------------------------------
20 before(function (done
) {
25 serversUtils
.flushTests(next
)
28 serversUtils
.runServer(1, function (server1
) {
35 loginUtils
.loginAndGetAccessToken(server
, function (err
, token
) {
37 server
.accessToken
= token
43 const username
= 'user1'
44 const password
= 'my super password'
46 usersUtils
.createUser(server
.url
, server
.accessToken
, username
, password
, next
)
51 password: 'my super password'
54 loginUtils
.getUserAccessToken(server
, user
, function (err
, accessToken
) {
57 userAccessToken
= accessToken
62 // Upload some videos on each pods
64 const name
= 'my super name for pod'
65 const description
= 'my super description for pod'
66 const tags
= [ 'tag' ]
67 const file
= 'video_short2.webm'
68 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, name
, description
, tags
, file
, next
)
71 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
74 const videos
= res
.body
.data
75 server
.video
= videos
[0]
83 describe('When listing video abuses', function () {
84 const path
= '/api/v1/videos/abuse'
86 it('Should fail with a bad start pagination', function (done
) {
89 .query({ start: 'hello' })
90 .set('Authorization', 'Bearer ' + server
.accessToken
)
91 .set('Accept', 'application/json')
95 it('Should fail with a bad count pagination', function (done
) {
98 .query({ count: 'hello' })
99 .set('Accept', 'application/json')
100 .set('Authorization', 'Bearer ' + server
.accessToken
)
104 it('Should fail with an incorrect sort', function (done
) {
107 .query({ sort: 'hello' })
108 .set('Accept', 'application/json')
109 .set('Authorization', 'Bearer ' + server
.accessToken
)
113 it('Should fail with a non authenticated user', function (done
) {
116 .query({ sort: 'hello' })
117 .set('Accept', 'application/json')
121 it('Should fail with a non admin user', function (done
) {
124 .query({ sort: 'hello' })
125 .set('Accept', 'application/json')
126 .set('Authorization', 'Bearer ' + userAccessToken
)
131 describe('When reporting a video abuse', function () {
132 const basePath
= '/api/v1/videos/'
134 it('Should fail with nothing', function (done
) {
135 const path
= basePath
+ server
.video
+ '/abuse'
137 requestsUtils
.makePostBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
140 it('Should fail with a wrong video', function (done
) {
141 const wrongPath
= '/api/v1/videos/blabla/abuse'
143 requestsUtils
.makePostBodyRequest(server
.url
, wrongPath
, server
.accessToken
, data
, done
)
146 it('Should fail with a non authenticated user', function (done
) {
148 const path
= basePath
+ server
.video
+ '/abuse'
149 requestsUtils
.makePostBodyRequest(server
.url
, path
, 'hello', data
, done
, 401)
152 it('Should fail with a reason too short', function (done
) {
156 const path
= basePath
+ server
.video
+ '/abuse'
157 requestsUtils
.makePostBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
160 it('Should fail with a reason too big', function (done
) {
162 reason: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
163 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
164 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
165 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
167 const path
= basePath
+ server
.video
+ '/abuse'
168 requestsUtils
.makePostBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
172 after(function (done
) {
173 process
.kill(-server
.app
.pid
)
175 // Keep the logs if the test failed
177 serversUtils
.flushTests(done
)