]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/videos.js
1 /* eslint-disable no-unused-expressions */
5 const chai
= require('chai')
6 const expect
= chai
.expect
7 const pathUtils
= require('path')
8 const request
= require('supertest')
9 const series
= require('async/series')
11 const loginUtils
= require('../../utils/login')
12 const requestsUtils
= require('../../utils/requests')
13 const serversUtils
= require('../../utils/servers')
14 const videosUtils
= require('../../utils/videos')
16 describe('Test videos API validator', function () {
17 const path
= '/api/v1/videos/'
20 // ---------------------------------------------------------------
22 before(function (done
) {
27 serversUtils
.flushTests(next
)
30 serversUtils
.runServer(1, function (server1
) {
37 loginUtils
.loginAndGetAccessToken(server
, function (err
, token
) {
39 server
.accessToken
= token
47 describe('When listing a video', function () {
48 it('Should fail with a bad start pagination', function (done
) {
51 .query({ start: 'hello' })
52 .set('Accept', 'application/json')
56 it('Should fail with a bad count pagination', function (done
) {
59 .query({ count: 'hello' })
60 .set('Accept', 'application/json')
64 it('Should fail with an incorrect sort', function (done
) {
67 .query({ sort: 'hello' })
68 .set('Accept', 'application/json')
73 describe('When searching a video', function () {
74 it('Should fail with nothing', function (done
) {
76 .get(pathUtils
.join(path
, 'search'))
77 .set('Accept', 'application/json')
81 it('Should fail with a bad start pagination', function (done
) {
83 .get(pathUtils
.join(path
, 'search', 'test'))
84 .query({ start: 'hello' })
85 .set('Accept', 'application/json')
89 it('Should fail with a bad count pagination', function (done
) {
91 .get(pathUtils
.join(path
, 'search', 'test'))
92 .query({ count: 'hello' })
93 .set('Accept', 'application/json')
97 it('Should fail with an incorrect sort', function (done
) {
99 .get(pathUtils
.join(path
, 'search', 'test'))
100 .query({ sort: 'hello' })
101 .set('Accept', 'application/json')
106 describe('When adding a video', function () {
107 it('Should fail with nothing', function (done
) {
110 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
113 it('Should fail without name', function (done
) {
115 description: 'my super description',
116 tags: [ 'tag1', 'tag2' ]
119 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
121 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
124 it('Should fail with a long name', function (done
) {
126 name: 'My very very very very very very very very very very very very very very very very long name',
127 description: 'my super description',
128 tags: [ 'tag1', 'tag2' ]
131 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
133 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
136 it('Should fail without description', function (done
) {
138 name: 'my super name',
139 tags: [ 'tag1', 'tag2' ]
142 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
144 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
147 it('Should fail with a long description', function (done
) {
149 name: 'my super name',
150 description: 'my super description which is very very very very very very very very very very very very very very' +
151 'very very very very very very very very very very very very very very very very very very very very very' +
152 'very very very very very very very very very very very very very very very long',
153 tags: [ 'tag1', 'tag2' ]
156 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
158 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
161 it('Should fail without tags', function (done
) {
163 name: 'my super name',
164 description: 'my super description'
167 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
169 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
172 it('Should fail with too many tags', function (done
) {
174 name: 'my super name',
175 description: 'my super description',
176 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
179 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
181 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
184 it('Should fail with not enough tags', function (done
) {
186 name: 'my super name',
187 description: 'my super description',
191 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
193 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
196 it('Should fail with a tag length too low', function (done
) {
198 name: 'my super name',
199 description: 'my super description',
200 tags: [ 'tag1', 't' ]
203 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
205 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
208 it('Should fail with a tag length too big', function (done
) {
210 name: 'my super name',
211 description: 'my super description',
212 tags: [ 'mysupertagtoolong', 'tag1' ]
215 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
217 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
220 it('Should fail with malformed tags', function (done
) {
222 name: 'my super name',
223 description: 'my super description',
227 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
229 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
232 it('Should fail without an input file', function (done
) {
234 name: 'my super name',
235 description: 'my super description',
236 tags: [ 'tag1', 'tag2' ]
239 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
242 it('Should fail without an incorrect input file', function (done
) {
244 name: 'my super name',
245 description: 'my super description',
246 tags: [ 'tag1', 'tag2' ]
249 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short_fake.webm')
251 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
254 it('Should fail with a too big duration', function (done
) {
256 name: 'my super name',
257 description: 'my super description',
258 tags: [ 'tag1', 'tag2' ]
261 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_too_long.webm')
263 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
266 it('Should succeed with the correct parameters', function (done
) {
268 name: 'my super name',
269 description: 'my super description',
270 tags: [ 'tag1', 'tag2' ]
273 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
275 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
276 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.mp4')
277 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
278 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.ogv')
279 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
, 204)
285 describe('When updating a video', function () {
288 before(function (done
) {
289 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
292 videoId
= res
.body
.data
[0].id
298 it('Should fail with nothing', function (done
) {
300 requestsUtils
.makePutBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
303 it('Should fail without a valid uuid', function (done
) {
305 description: 'my super description',
306 tags: [ 'tag1', 'tag2' ]
308 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla', server
.accessToken
, data
, done
)
311 it('Should fail with an unknown id', function (done
) {
313 description: 'my super description',
314 tags: [ 'tag1', 'tag2' ]
316 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06', server
.accessToken
, data
, done
, 404)
319 it('Should fail with a long name', function (done
) {
321 name: 'My very very very very very very very very very very very very very very very very long name',
322 description: 'my super description',
323 tags: [ 'tag1', 'tag2' ]
325 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
328 it('Should fail with a long description', function (done
) {
330 name: 'my super name',
331 description: 'my super description which is very very very very very very very very very very very very very very' +
332 'very very very very very very very very very very very very very very very very very very very very very' +
333 'very very very very very very very very very very very very very very very long',
334 tags: [ 'tag1', 'tag2' ]
336 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
339 it('Should fail with too many tags', function (done
) {
341 name: 'my super name',
342 description: 'my super description',
343 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
345 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
348 it('Should fail with not enough tags', function (done
) {
350 name: 'my super name',
351 description: 'my super description',
354 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
357 it('Should fail with a tag length too low', function (done
) {
359 name: 'my super name',
360 description: 'my super description',
361 tags: [ 'tag1', 't' ]
363 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
366 it('Should fail with a tag length too big', function (done
) {
368 name: 'my super name',
369 description: 'my super description',
370 tags: [ 'mysupertagtoolong', 'tag1' ]
372 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
375 it('Should fail with malformed tags', function (done
) {
377 name: 'my super name',
378 description: 'my super description',
381 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
384 it('Should fail with a video of another user')
386 it('Should fail with a video of another pod')
389 describe('When getting a video', function () {
390 it('Should return the list of the videos with nothing', function (done
) {
393 .set('Accept', 'application/json')
395 .expect('Content-Type', /json/)
396 .end(function (err
, res
) {
399 expect(res
.body
.data
).to
.be
.an('array')
400 expect(res
.body
.data
.length
).to
.equal(3)
406 it('Should fail without a correct uuid', function (done
) {
408 .get(path
+ 'coucou')
409 .set('Accept', 'application/json')
413 it('Should return 404 with an incorrect video', function (done
) {
415 .get(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
416 .set('Accept', 'application/json')
420 it('Should succeed with the correct parameters')
423 describe('When removing a video', function () {
424 it('Should have 404 with nothing', function (done
) {
427 .set('Authorization', 'Bearer ' + server
.accessToken
)
431 it('Should fail without a correct uuid', function (done
) {
433 .delete(path
+ 'hello')
434 .set('Authorization', 'Bearer ' + server
.accessToken
)
438 it('Should fail with a video which does not exist', function (done
) {
440 .delete(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
441 .set('Authorization', 'Bearer ' + server
.accessToken
)
445 it('Should fail with a video of another user')
447 it('Should fail with a video of another pod')
449 it('Should succeed with the correct parameters')
452 after(function (done
) {
453 process
.kill(-server
.app
.pid
)
455 // Keep the logs if the test failed
457 serversUtils
.flushTests(done
)