]>
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'
66 const description
= 'my super description for pod'
67 const tags
= [ 'tag' ]
68 const file
= 'video_short2.webm'
69 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, name
, category
, description
, tags
, file
, next
)
72 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
75 const videos
= res
.body
.data
76 server
.video
= videos
[0]
84 describe('When listing video abuses', function () {
85 const path
= '/api/v1/videos/abuse'
87 it('Should fail with a bad start pagination', function (done
) {
90 .query({ start: 'hello' })
91 .set('Authorization', 'Bearer ' + server
.accessToken
)
92 .set('Accept', 'application/json')
96 it('Should fail with a bad count pagination', function (done
) {
99 .query({ count: 'hello' })
100 .set('Accept', 'application/json')
101 .set('Authorization', 'Bearer ' + server
.accessToken
)
105 it('Should fail with an incorrect sort', function (done
) {
108 .query({ sort: 'hello' })
109 .set('Accept', 'application/json')
110 .set('Authorization', 'Bearer ' + server
.accessToken
)
114 it('Should fail with a non authenticated user', function (done
) {
117 .query({ sort: 'hello' })
118 .set('Accept', 'application/json')
122 it('Should fail with a non admin user', function (done
) {
125 .query({ sort: 'hello' })
126 .set('Accept', 'application/json')
127 .set('Authorization', 'Bearer ' + userAccessToken
)
132 describe('When reporting a video abuse', function () {
133 const basePath
= '/api/v1/videos/'
135 it('Should fail with nothing', function (done
) {
136 const path
= basePath
+ server
.video
+ '/abuse'
138 requestsUtils
.makePostBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
141 it('Should fail with a wrong video', function (done
) {
142 const wrongPath
= '/api/v1/videos/blabla/abuse'
144 requestsUtils
.makePostBodyRequest(server
.url
, wrongPath
, server
.accessToken
, data
, done
)
147 it('Should fail with a non authenticated user', function (done
) {
149 const path
= basePath
+ server
.video
+ '/abuse'
150 requestsUtils
.makePostBodyRequest(server
.url
, path
, 'hello', data
, done
, 401)
153 it('Should fail with a reason too short', function (done
) {
157 const path
= basePath
+ server
.video
+ '/abuse'
158 requestsUtils
.makePostBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
161 it('Should fail with a reason too big', function (done
) {
163 reason: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
164 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
165 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
166 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
168 const path
= basePath
+ server
.video
+ '/abuse'
169 requestsUtils
.makePostBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
173 after(function (done
) {
174 process
.kill(-server
.app
.pid
)
176 // Keep the logs if the test failed
178 serversUtils
.flushTests(done
)