1 /* tslint:disable:no-unused-expression */
3 import * as request from 'supertest'
4 import { join } from 'path'
6 import * as chai from 'chai'
7 const expect = chai.expect
15 setAccessTokensToServers,
20 describe('Test videos API validator', function () {
21 const path = '/api/v1/videos/'
22 let server: ServerInfo
24 // ---------------------------------------------------------------
26 before(async function () {
31 server = await runServer(1)
33 await setAccessTokensToServers([ server ])
36 describe('When listing a video', function () {
37 it('Should fail with a bad start pagination', async function () {
38 await request(server.url)
40 .query({ start: 'hello' })
41 .set('Accept', 'application/json')
45 it('Should fail with a bad count pagination', async function () {
46 await request(server.url)
48 .query({ count: 'hello' })
49 .set('Accept', 'application/json')
53 it('Should fail with an incorrect sort', async function () {
54 await request(server.url)
56 .query({ sort: 'hello' })
57 .set('Accept', 'application/json')
62 describe('When searching a video', function () {
63 it('Should fail with nothing', async function () {
64 await request(server.url)
65 .get(join(path, 'search'))
66 .set('Accept', 'application/json')
70 it('Should fail with a bad start pagination', async function () {
71 await request(server.url)
72 .get(join(path, 'search', 'test'))
73 .query({ start: 'hello' })
74 .set('Accept', 'application/json')
78 it('Should fail with a bad count pagination', async function () {
79 await request(server.url)
80 .get(join(path, 'search', 'test'))
81 .query({ count: 'hello' })
82 .set('Accept', 'application/json')
86 it('Should fail with an incorrect sort', async function () {
87 await request(server.url)
88 .get(join(path, 'search', 'test'))
89 .query({ sort: 'hello' })
90 .set('Accept', 'application/json')
95 describe('When adding a video', function () {
96 it('Should fail with nothing', async function () {
99 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
102 it('Should fail without name', async function () {
108 description: 'my super description',
109 tags: [ 'tag1', 'tag2' ]
112 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
114 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
117 it('Should fail with a long name', async function () {
119 name: 'My very very very very very very very very very very very very very very very very long name',
124 description: 'my super description',
125 tags: [ 'tag1', 'tag2' ]
128 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
130 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
133 it('Should fail without a category', async function () {
135 name: 'my super name',
139 description: 'my super description',
140 tags: [ 'tag1', 'tag2' ]
143 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
145 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
148 it('Should fail with a bad category', async function () {
150 name: 'my super name',
155 description: 'my super description',
156 tags: [ 'tag1', 'tag2' ]
159 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
161 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
164 it('Should fail without a licence', async function () {
166 name: 'my super name',
170 description: 'my super description',
171 tags: [ 'tag1', 'tag2' ]
174 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
176 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
179 it('Should fail with a bad licence', async function () {
181 name: 'my super name',
186 description: 'my super description',
187 tags: [ 'tag1', 'tag2' ]
190 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
192 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
195 it('Should fail with a bad language', async function () {
197 name: 'my super name',
202 description: 'my super description',
203 tags: [ 'tag1', 'tag2' ]
206 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
208 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
211 it('Should fail without nsfw attribute', async function () {
213 name: 'my super name',
217 description: 'my super description',
218 tags: [ 'tag1', 'tag2' ]
221 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
223 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
226 it('Should fail with a bad nsfw attribue', async function () {
228 name: 'my super name',
233 description: 'my super description',
234 tags: [ 'tag1', 'tag2' ]
237 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
239 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
242 it('Should fail without description', async function () {
244 name: 'my super name',
249 tags: [ 'tag1', 'tag2' ]
252 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
254 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
257 it('Should fail with a long description', async function () {
259 name: 'my super name',
264 description: 'my super description which is very very very very very very very very very very very very very very' +
265 'very very very very very very very very very very very very very very very very very very very very very' +
266 'very very very very very very very very very very very very very very very long',
267 tags: [ 'tag1', 'tag2' ]
270 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
272 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
275 it('Should fail with too many tags', async function () {
277 name: 'my super name',
282 description: 'my super description',
283 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
286 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
288 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
291 it('Should fail with a tag length too low', async function () {
293 name: 'my super name',
298 description: 'my super description',
299 tags: [ 'tag1', 't' ]
302 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
304 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
307 it('Should fail with a tag length too big', async function () {
309 name: 'my super name',
314 description: 'my super description',
315 tags: [ 'my_super_tag_too_long', 'tag1' ]
318 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
320 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
323 it('Should fail without an input file', async function () {
325 name: 'my super name',
330 description: 'my super description',
331 tags: [ 'tag1', 'tag2' ]
334 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
337 it('Should fail without an incorrect input file', async function () {
339 name: 'my super name',
344 description: 'my super description',
345 tags: [ 'tag1', 'tag2' ]
348 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
350 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
353 it('Should fail with a too big duration', async function () {
355 name: 'my super name',
360 description: 'my super description',
361 tags: [ 'tag1', 'tag2' ]
364 'videofile': join(__dirname, '..', 'fixtures', 'video_too_long.webm')
366 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
369 it('Should succeed with the correct parameters', async function () {
373 name: 'my super name',
378 description: 'my super description',
379 tags: [ 'tag1', 'tag2' ]
382 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
385 await makePostUploadRequest({
387 path: path + '/upload',
388 token: server.accessToken,
391 statusCodeExpected: 204
394 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.mp4')
395 await makePostUploadRequest({
397 path: path + '/upload',
398 token: server.accessToken,
401 statusCodeExpected: 204
404 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.ogv')
405 await makePostUploadRequest({
407 path: path + '/upload',
408 token: server.accessToken,
411 statusCodeExpected: 204
416 describe('When updating a video', function () {
419 before(async function () {
420 const res = await getVideosList(server.url)
421 videoId = res.body.data[0].id
424 it('Should fail with nothing', async function () {
426 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
429 it('Should fail without a valid uuid', async function () {
435 description: 'my super description',
436 tags: [ 'tag1', 'tag2' ]
438 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
441 it('Should fail with an unknown id', async function () {
447 description: 'my super description',
448 tags: [ 'tag1', 'tag2' ]
450 await makePutBodyRequest({
452 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
453 token: server.accessToken,
455 statusCodeExpected: 404
459 it('Should fail with a long name', async function () {
461 name: 'My very very very very very very very very very very very very very very very very long name',
466 description: 'my super description',
467 tags: [ 'tag1', 'tag2' ]
469 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
472 it('Should fail with a bad category', async function () {
474 name: 'my super name',
479 description: 'my super description',
480 tags: [ 'tag1', 'tag2' ]
482 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
485 it('Should fail with a bad licence', async function () {
487 name: 'my super name',
492 description: 'my super description',
493 tags: [ 'tag1', 'tag2' ]
495 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
498 it('Should fail with a bad language', async function () {
500 name: 'my super name',
505 description: 'my super description',
506 tags: [ 'tag1', 'tag2' ]
508 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
511 it('Should fail with a bad nsfw attribute', async function () {
513 name: 'my super name',
518 description: 'my super description',
519 tags: [ 'tag1', 'tag2' ]
521 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
524 it('Should fail with a long description', async function () {
526 name: 'my super name',
531 description: 'my super description which is very very very very very very very very very very very very very very' +
532 'very very very very very very very very very very very very very very very very very very very very very' +
533 'very very very very very very very very very very very very very very very long',
534 tags: [ 'tag1', 'tag2' ]
536 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
539 it('Should fail with too many tags', async function () {
541 name: 'my super name',
546 description: 'my super description',
547 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
549 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
552 it('Should fail with a tag length too low', async function () {
554 name: 'my super name',
559 description: 'my super description',
560 tags: [ 'tag1', 't' ]
562 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
565 it('Should fail with a tag length too big', async function () {
567 name: 'my super name',
572 description: 'my super description',
573 tags: [ 'my_super_tag_too_long', 'tag1' ]
575 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
578 it('Should fail with a video of another user')
580 it('Should fail with a video of another pod')
583 describe('When getting a video', function () {
584 it('Should return the list of the videos with nothing', async function () {
585 const res = await request(server.url)
587 .set('Accept', 'application/json')
589 .expect('Content-Type', /json/)
591 expect(res.body.data).to.be.an('array')
592 expect(res.body.data.length).to.equal(3)
595 it('Should fail without a correct uuid', async function () {
596 await request(server.url)
597 .get(path + 'coucou')
598 .set('Accept', 'application/json')
602 it('Should return 404 with an incorrect video', async function () {
603 await request(server.url)
604 .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
605 .set('Accept', 'application/json')
609 it('Should succeed with the correct parameters')
612 describe('When rating a video', function () {
615 before(async function () {
616 const res = await getVideosList(server.url)
617 videoId = res.body.data[0].id
620 it('Should fail without a valid uuid', async function () {
624 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
627 it('Should fail with an unknown id', async function () {
631 await makePutBodyRequest({
633 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
634 token: server.accessToken,
636 statusCodeExpected: 404
640 it('Should fail with a wrong rating', async function () {
644 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
647 it('Should succeed with the correct parameters', async function () {
651 await makePutBodyRequest({
653 path: path + videoId + '/rate',
654 token: server.accessToken,
656 statusCodeExpected: 204
661 describe('When removing a video', function () {
662 it('Should have 404 with nothing', async function () {
663 await request(server.url)
665 .set('Authorization', 'Bearer ' + server.accessToken)
669 it('Should fail without a correct uuid', async function () {
670 await request(server.url)
671 .delete(path + 'hello')
672 .set('Authorization', 'Bearer ' + server.accessToken)
676 it('Should fail with a video which does not exist', async function () {
677 await request(server.url)
678 .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
679 .set('Authorization', 'Bearer ' + server.accessToken)
683 it('Should fail with a video of another user')
685 it('Should fail with a video of another pod')
687 it('Should succeed with the correct parameters')
690 after(async function () {
691 killallServers([ server ])
693 // Keep the logs if the test failed