aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/videos.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/videos.js')
-rw-r--r--server/tests/api/check-params/videos.js456
1 files changed, 456 insertions, 0 deletions
diff --git a/server/tests/api/check-params/videos.js b/server/tests/api/check-params/videos.js
new file mode 100644
index 000000000..d18305291
--- /dev/null
+++ b/server/tests/api/check-params/videos.js
@@ -0,0 +1,456 @@
1'use strict'
2
3const chai = require('chai')
4const expect = chai.expect
5const pathUtils = require('path')
6const request = require('supertest')
7const series = require('async/series')
8
9const loginUtils = require('../../utils/login')
10const requestsUtils = require('../../utils/requests')
11const serversUtils = require('../../utils/servers')
12const videosUtils = require('../../utils/videos')
13
14describe('Test videos API validator', function () {
15 const path = '/api/v1/videos/'
16 let server = null
17
18 // ---------------------------------------------------------------
19
20 before(function (done) {
21 this.timeout(20000)
22
23 series([
24 function (next) {
25 serversUtils.flushTests(next)
26 },
27 function (next) {
28 serversUtils.runServer(1, function (server1) {
29 server = server1
30
31 next()
32 })
33 },
34 function (next) {
35 loginUtils.loginAndGetAccessToken(server, function (err, token) {
36 if (err) throw err
37 server.accessToken = token
38
39 next()
40 })
41 }
42 ], done)
43 })
44
45 describe('When listing a video', function () {
46 it('Should fail with a bad start pagination', function (done) {
47 request(server.url)
48 .get(path)
49 .query({ start: 'hello' })
50 .set('Accept', 'application/json')
51 .expect(400, done)
52 })
53
54 it('Should fail with a bad count pagination', function (done) {
55 request(server.url)
56 .get(path)
57 .query({ count: 'hello' })
58 .set('Accept', 'application/json')
59 .expect(400, done)
60 })
61
62 it('Should fail with an incorrect sort', function (done) {
63 request(server.url)
64 .get(path)
65 .query({ sort: 'hello' })
66 .set('Accept', 'application/json')
67 .expect(400, done)
68 })
69 })
70
71 describe('When searching a video', function () {
72 it('Should fail with nothing', function (done) {
73 request(server.url)
74 .get(pathUtils.join(path, 'search'))
75 .set('Accept', 'application/json')
76 .expect(400, done)
77 })
78
79 it('Should fail with a bad start pagination', function (done) {
80 request(server.url)
81 .get(pathUtils.join(path, 'search', 'test'))
82 .query({ start: 'hello' })
83 .set('Accept', 'application/json')
84 .expect(400, done)
85 })
86
87 it('Should fail with a bad count pagination', function (done) {
88 request(server.url)
89 .get(pathUtils.join(path, 'search', 'test'))
90 .query({ count: 'hello' })
91 .set('Accept', 'application/json')
92 .expect(400, done)
93 })
94
95 it('Should fail with an incorrect sort', function (done) {
96 request(server.url)
97 .get(pathUtils.join(path, 'search', 'test'))
98 .query({ sort: 'hello' })
99 .set('Accept', 'application/json')
100 .expect(400, done)
101 })
102 })
103
104 describe('When adding a video', function () {
105 it('Should fail with nothing', function (done) {
106 const data = {}
107 const attach = {}
108 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
109 })
110
111 it('Should fail without name', function (done) {
112 const data = {
113 description: 'my super description',
114 tags: [ 'tag1', 'tag2' ]
115 }
116 const attach = {
117 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
118 }
119 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
120 })
121
122 it('Should fail with a long name', function (done) {
123 const data = {
124 name: 'My very very very very very very very very very very very very very very very very long name',
125 description: 'my super description',
126 tags: [ 'tag1', 'tag2' ]
127 }
128 const attach = {
129 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
130 }
131 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
132 })
133
134 it('Should fail without description', function (done) {
135 const data = {
136 name: 'my super name',
137 tags: [ 'tag1', 'tag2' ]
138 }
139 const attach = {
140 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
141 }
142 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
143 })
144
145 it('Should fail with a long description', function (done) {
146 const data = {
147 name: 'my super name',
148 description: 'my super description which is very very very very very very very very very very very very very very' +
149 'very very very very very very very very very very very very very very very very very very very very very' +
150 'very very very very very very very very very very very very very very very long',
151 tags: [ 'tag1', 'tag2' ]
152 }
153 const attach = {
154 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
155 }
156 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
157 })
158
159 it('Should fail without tags', function (done) {
160 const data = {
161 name: 'my super name',
162 description: 'my super description'
163 }
164 const attach = {
165 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
166 }
167 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
168 })
169
170 it('Should fail with too many tags', function (done) {
171 const data = {
172 name: 'my super name',
173 description: 'my super description',
174 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
175 }
176 const attach = {
177 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
178 }
179 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
180 })
181
182 it('Should fail with not enough tags', function (done) {
183 const data = {
184 name: 'my super name',
185 description: 'my super description',
186 tags: [ ]
187 }
188 const attach = {
189 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
190 }
191 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
192 })
193
194 it('Should fail with a tag length too low', function (done) {
195 const data = {
196 name: 'my super name',
197 description: 'my super description',
198 tags: [ 'tag1', 't' ]
199 }
200 const attach = {
201 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
202 }
203 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
204 })
205
206 it('Should fail with a tag length too big', function (done) {
207 const data = {
208 name: 'my super name',
209 description: 'my super description',
210 tags: [ 'mysupertagtoolong', 'tag1' ]
211 }
212 const attach = {
213 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
214 }
215 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
216 })
217
218 it('Should fail with malformed tags', function (done) {
219 const data = {
220 name: 'my super name',
221 description: 'my super description',
222 tags: [ 'my tag' ]
223 }
224 const attach = {
225 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
226 }
227 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
228 })
229
230 it('Should fail without an input file', function (done) {
231 const data = {
232 name: 'my super name',
233 description: 'my super description',
234 tags: [ 'tag1', 'tag2' ]
235 }
236 const attach = {}
237 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
238 })
239
240 it('Should fail without an incorrect input file', function (done) {
241 const data = {
242 name: 'my super name',
243 description: 'my super description',
244 tags: [ 'tag1', 'tag2' ]
245 }
246 const attach = {
247 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
248 }
249 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
250 })
251
252 it('Should fail with a too big duration', function (done) {
253 const data = {
254 name: 'my super name',
255 description: 'my super description',
256 tags: [ 'tag1', 'tag2' ]
257 }
258 const attach = {
259 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_too_long.webm')
260 }
261 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
262 })
263
264 it('Should succeed with the correct parameters', function (done) {
265 const data = {
266 name: 'my super name',
267 description: 'my super description',
268 tags: [ 'tag1', 'tag2' ]
269 }
270 const attach = {
271 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
272 }
273 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () {
274 attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.mp4')
275 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () {
276 attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.ogv')
277 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204)
278 }, false)
279 }, false)
280 })
281 })
282
283 describe('When updating a video', function () {
284 let videoId
285
286 before(function (done) {
287 videosUtils.getVideosList(server.url, function (err, res) {
288 if (err) throw err
289
290 videoId = res.body.data[0].id
291
292 return done()
293 })
294 })
295
296 it('Should fail with nothing', function (done) {
297 const data = {}
298 requestsUtils.makePutBodyRequest(server.url, path, server.accessToken, data, done)
299 })
300
301 it('Should fail without a valid uuid', function (done) {
302 const data = {
303 description: 'my super description',
304 tags: [ 'tag1', 'tag2' ]
305 }
306 requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done)
307 })
308
309 it('Should fail with an unknown id', function (done) {
310 const data = {
311 description: 'my super description',
312 tags: [ 'tag1', 'tag2' ]
313 }
314 requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done, 404)
315 })
316
317 it('Should fail with a long name', function (done) {
318 const data = {
319 name: 'My very very very very very very very very very very very very very very very very long name',
320 description: 'my super description',
321 tags: [ 'tag1', 'tag2' ]
322 }
323 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
324 })
325
326 it('Should fail with a long description', function (done) {
327 const data = {
328 name: 'my super name',
329 description: 'my super description which is very very very very very very very very very very very very very very' +
330 'very very very very very very very very very very very very very very very very very very very very very' +
331 'very very very very very very very very very very very very very very very long',
332 tags: [ 'tag1', 'tag2' ]
333 }
334 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
335 })
336
337 it('Should fail with too many tags', function (done) {
338 const data = {
339 name: 'my super name',
340 description: 'my super description',
341 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
342 }
343 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
344 })
345
346 it('Should fail with not enough tags', function (done) {
347 const data = {
348 name: 'my super name',
349 description: 'my super description',
350 tags: [ ]
351 }
352 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
353 })
354
355 it('Should fail with a tag length too low', function (done) {
356 const data = {
357 name: 'my super name',
358 description: 'my super description',
359 tags: [ 'tag1', 't' ]
360 }
361 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
362 })
363
364 it('Should fail with a tag length too big', function (done) {
365 const data = {
366 name: 'my super name',
367 description: 'my super description',
368 tags: [ 'mysupertagtoolong', 'tag1' ]
369 }
370 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
371 })
372
373 it('Should fail with malformed tags', function (done) {
374 const data = {
375 name: 'my super name',
376 description: 'my super description',
377 tags: [ 'my tag' ]
378 }
379 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
380 })
381 })
382
383 describe('When getting a video', function () {
384 it('Should return the list of the videos with nothing', function (done) {
385 request(server.url)
386 .get(path)
387 .set('Accept', 'application/json')
388 .expect(200)
389 .expect('Content-Type', /json/)
390 .end(function (err, res) {
391 if (err) throw err
392
393 expect(res.body.data).to.be.an('array')
394 expect(res.body.data.length).to.equal(3)
395
396 done()
397 })
398 })
399
400 it('Should fail without a correct uuid', function (done) {
401 request(server.url)
402 .get(path + 'coucou')
403 .set('Accept', 'application/json')
404 .expect(400, done)
405 })
406
407 it('Should return 404 with an incorrect video', function (done) {
408 request(server.url)
409 .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
410 .set('Accept', 'application/json')
411 .expect(404, done)
412 })
413
414 it('Should succeed with the correct parameters')
415 })
416
417 describe('When removing a video', function () {
418 it('Should have 404 with nothing', function (done) {
419 request(server.url)
420 .delete(path)
421 .set('Authorization', 'Bearer ' + server.accessToken)
422 .expect(400, done)
423 })
424
425 it('Should fail without a correct uuid', function (done) {
426 request(server.url)
427 .delete(path + 'hello')
428 .set('Authorization', 'Bearer ' + server.accessToken)
429 .expect(400, done)
430 })
431
432 it('Should fail with a video which does not exist', function (done) {
433 request(server.url)
434 .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
435 .set('Authorization', 'Bearer ' + server.accessToken)
436 .expect(404, done)
437 })
438
439 it('Should fail with a video of another user')
440
441 it('Should fail with a video of another pod')
442
443 it('Should succeed with the correct parameters')
444 })
445
446 after(function (done) {
447 process.kill(-server.app.pid)
448
449 // Keep the logs if the test failed
450 if (this.ok) {
451 serversUtils.flushTests(done)
452 } else {
453 done()
454 }
455 })
456})