]>
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 videoAttributes
= {}
65 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, videoAttributes
, next
)
68 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
71 const videos
= res
.body
.data
72 server
.video
= videos
[0]
80 describe('When listing video abuses', function () {
81 const path
= '/api/v1/videos/abuse'
83 it('Should fail with a bad start pagination', function (done
) {
86 .query({ start: 'hello' })
87 .set('Authorization', 'Bearer ' + server
.accessToken
)
88 .set('Accept', 'application/json')
92 it('Should fail with a bad count pagination', function (done
) {
95 .query({ count: 'hello' })
96 .set('Accept', 'application/json')
97 .set('Authorization', 'Bearer ' + server
.accessToken
)
101 it('Should fail with an incorrect sort', function (done
) {
104 .query({ sort: 'hello' })
105 .set('Accept', 'application/json')
106 .set('Authorization', 'Bearer ' + server
.accessToken
)
110 it('Should fail with a non authenticated user', function (done
) {
113 .query({ sort: 'hello' })
114 .set('Accept', 'application/json')
118 it('Should fail with a non admin user', function (done
) {
121 .query({ sort: 'hello' })
122 .set('Accept', 'application/json')
123 .set('Authorization', 'Bearer ' + userAccessToken
)
128 describe('When reporting a video abuse', function () {
129 const basePath
= '/api/v1/videos/'
131 it('Should fail with nothing', function (done
) {
132 const path
= basePath
+ server
.video
.id
+ '/abuse'
134 requestsUtils
.makePostBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
137 it('Should fail with a wrong video', function (done
) {
138 const wrongPath
= '/api/v1/videos/blabla/abuse'
140 requestsUtils
.makePostBodyRequest(server
.url
, wrongPath
, server
.accessToken
, data
, done
)
143 it('Should fail with a non authenticated user', function (done
) {
145 const path
= basePath
+ server
.video
.id
+ '/abuse'
146 requestsUtils
.makePostBodyRequest(server
.url
, path
, 'hello', data
, done
, 401)
149 it('Should fail with a reason too short', function (done
) {
153 const path
= basePath
+ server
.video
.id
+ '/abuse'
154 requestsUtils
.makePostBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
157 it('Should fail with a reason too big', function (done
) {
159 reason: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
160 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
161 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
162 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
164 const path
= basePath
+ server
.video
.id
+ '/abuse'
165 requestsUtils
.makePostBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
169 after(function (done
) {
170 process
.kill(-server
.app
.pid
)
172 // Keep the logs if the test failed
174 serversUtils
.flushTests(done
)