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,
17 makePostUploadRequest,
23 describe('Test videos API validator', function () {
24 const path = '/api/v1/videos/'
25 let server: ServerInfo
28 // ---------------------------------------------------------------
30 before(async function () {
35 server = await runServer(1)
37 await setAccessTokensToServers([ server ])
39 const res = await getMyUserInformation(server.url, server.accessToken)
40 channelId = res.body.videoChannels[0].id
43 describe('When listing a video', function () {
44 it('Should fail with a bad start pagination', async function () {
45 await request(server.url)
47 .query({ start: 'hello' })
48 .set('Accept', 'application/json')
52 it('Should fail with a bad count pagination', async function () {
53 await request(server.url)
55 .query({ count: 'hello' })
56 .set('Accept', 'application/json')
60 it('Should fail with an incorrect sort', async function () {
61 await request(server.url)
63 .query({ sort: 'hello' })
64 .set('Accept', 'application/json')
69 describe('When searching a video', function () {
70 it('Should fail with nothing', async function () {
71 await request(server.url)
72 .get(join(path, 'search'))
73 .set('Accept', 'application/json')
77 it('Should fail with a bad start pagination', async function () {
78 await request(server.url)
79 .get(join(path, 'search', 'test'))
80 .query({ start: 'hello' })
81 .set('Accept', 'application/json')
85 it('Should fail with a bad count pagination', async function () {
86 await request(server.url)
87 .get(join(path, 'search', 'test'))
88 .query({ count: 'hello' })
89 .set('Accept', 'application/json')
93 it('Should fail with an incorrect sort', async function () {
94 await request(server.url)
95 .get(join(path, 'search', 'test'))
96 .query({ sort: 'hello' })
97 .set('Accept', 'application/json')
102 describe('When adding a video', function () {
103 it('Should fail with nothing', async function () {
106 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
109 it('Should fail without name', async function () {
115 description: 'my super description',
116 tags: [ 'tag1', 'tag2' ],
120 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
122 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
125 it('Should fail with a long name', async function () {
127 name: 'My very very very very very very very very very very very very very very very very very ' +
128 'very very very very very very very very very very very very very very very very long long' +
129 'very very very very very very very very very very very very very very very very long name',
134 description: 'my super description',
135 tags: [ 'tag1', 'tag2' ],
139 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
141 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
144 it('Should fail without a category', async function () {
146 name: 'my super name',
150 description: 'my super description',
151 tags: [ 'tag1', 'tag2' ],
155 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
157 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
160 it('Should fail with a bad category', async function () {
162 name: 'my super name',
167 description: 'my super description',
168 tags: [ 'tag1', 'tag2' ],
172 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
174 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
177 it('Should fail without a licence', async function () {
179 name: 'my super name',
183 description: 'my super description',
184 tags: [ 'tag1', 'tag2' ],
188 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
190 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
193 it('Should fail with a bad licence', async function () {
195 name: 'my super name',
200 description: 'my super description',
201 tags: [ 'tag1', 'tag2' ],
205 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
207 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
210 it('Should fail with a bad language', async function () {
212 name: 'my super name',
217 description: 'my super description',
218 tags: [ 'tag1', 'tag2' ],
222 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
224 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
227 it('Should fail without nsfw attribute', async function () {
229 name: 'my super name',
233 description: 'my super description',
234 tags: [ 'tag1', 'tag2' ],
238 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
240 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
243 it('Should fail with a bad nsfw attribute', async function () {
245 name: 'my super name',
250 description: 'my super description',
251 tags: [ 'tag1', 'tag2' ],
255 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
257 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
260 it('Should fail without description', async function () {
262 name: 'my super name',
267 tags: [ 'tag1', 'tag2' ],
271 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
273 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
276 it('Should fail with a long description', async function () {
278 name: 'my super name',
283 description: 'my super description which is very very very very very very very very very very very very very very long'.repeat(35),
284 tags: [ 'tag1', 'tag2' ],
288 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
290 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
293 it('Should fail without a channel', async function () {
295 name: 'my super name',
300 description: 'my super description',
301 tags: [ 'tag1', 'tag2' ]
304 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
306 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
309 it('Should fail with a bad channel', async function () {
311 name: 'my super name',
316 description: 'my super description',
317 tags: [ 'tag1', 'tag2' ],
321 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
323 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
326 it('Should fail with another user channel', async function () {
329 password: 'fake_password'
331 await createUser(server.url, server.accessToken, user.username, user.password)
333 const accessTokenUser = await getUserAccessToken(server, user)
334 const res = await getMyUserInformation(server.url, accessTokenUser)
335 const channelId = res.body.videoChannels[0].id
338 name: 'my super name',
343 description: 'my super description',
344 tags: [ 'tag1', 'tag2' ],
348 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
350 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
353 it('Should fail with too many tags', async function () {
355 name: 'my super name',
360 description: 'my super description',
361 tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ],
365 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
367 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
370 it('Should fail with a tag length too low', async function () {
372 name: 'my super name',
377 description: 'my super description',
378 tags: [ 'tag1', 't' ],
382 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
384 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
387 it('Should fail with a tag length too big', async function () {
389 name: 'my super name',
394 description: 'my super description',
395 tags: [ 'my_super_tag_too_long_long_long_long_long_long', 'tag1' ],
399 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
401 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
404 it('Should fail without an input file', async function () {
406 name: 'my super name',
411 description: 'my super description',
412 tags: [ 'tag1', 'tag2' ],
416 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
419 it('Should fail without an incorrect input file', async function () {
421 name: 'my super name',
426 description: 'my super description',
427 tags: [ 'tag1', 'tag2' ],
431 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
433 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
436 it('Should fail with a too big duration', async function () {
438 name: 'my super name',
443 description: 'my super description',
444 tags: [ 'tag1', 'tag2' ],
448 'videofile': join(__dirname, '..', 'fixtures', 'video_too_long.webm')
450 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
453 it('Should succeed with the correct parameters', async function () {
457 name: 'my super name',
462 description: 'my super description',
463 tags: [ 'tag1', 'tag2' ],
467 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
470 await makePostUploadRequest({
472 path: path + '/upload',
473 token: server.accessToken,
476 statusCodeExpected: 204
479 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.mp4')
480 await makePostUploadRequest({
482 path: path + '/upload',
483 token: server.accessToken,
486 statusCodeExpected: 204
489 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.ogv')
490 await makePostUploadRequest({
492 path: path + '/upload',
493 token: server.accessToken,
496 statusCodeExpected: 204
501 describe('When updating a video', function () {
504 before(async function () {
505 const res = await getVideosList(server.url)
506 videoId = res.body.data[0].id
509 it('Should fail with nothing', async function () {
511 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
514 it('Should fail without a valid uuid', async function () {
520 description: 'my super description',
521 tags: [ 'tag1', 'tag2' ]
523 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
526 it('Should fail with an unknown id', async function () {
532 description: 'my super description',
533 tags: [ 'tag1', 'tag2' ]
535 await makePutBodyRequest({
537 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
538 token: server.accessToken,
540 statusCodeExpected: 404
544 it('Should fail with a long name', async function () {
546 name: 'My very very very very very very very very very very very very very very very very very ' +
547 'very very very very very very very very very very very very very very very very long long' +
548 'very very very very very very very very very very very very very very very very long name',
553 description: 'my super description',
554 tags: [ 'tag1', 'tag2' ]
556 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
559 it('Should fail with a bad category', async function () {
561 name: 'my super name',
566 description: 'my super description',
567 tags: [ 'tag1', 'tag2' ]
569 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
572 it('Should fail with a bad licence', async function () {
574 name: 'my super name',
579 description: 'my super description',
580 tags: [ 'tag1', 'tag2' ]
582 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
585 it('Should fail with a bad language', async function () {
587 name: 'my super name',
592 description: 'my super description',
593 tags: [ 'tag1', 'tag2' ]
595 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
598 it('Should fail with a bad nsfw attribute', async function () {
600 name: 'my super name',
605 description: 'my super description',
606 tags: [ 'tag1', 'tag2' ]
608 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
611 it('Should fail with a long description', async function () {
613 name: 'my super name',
618 description: 'my super description which is very very very very very very very very very very very very very long'.repeat(35),
619 tags: [ 'tag1', 'tag2' ]
621 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
624 it('Should fail with too many tags', async function () {
626 name: 'my super name',
631 description: 'my super description',
632 tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ]
634 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
637 it('Should fail with a tag length too low', async function () {
639 name: 'my super name',
644 description: 'my super description',
645 tags: [ 'tag1', 't' ]
647 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
650 it('Should fail with a tag length too big', async function () {
652 name: 'my super name',
657 description: 'my super description',
658 tags: [ 'my_super_tag_too_long_long_long_long', 'tag1' ]
660 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
663 it('Should fail with a video of another user')
665 it('Should fail with a video of another pod')
668 describe('When getting a video', function () {
669 it('Should return the list of the videos with nothing', async function () {
670 const res = await request(server.url)
672 .set('Accept', 'application/json')
674 .expect('Content-Type', /json/)
676 expect(res.body.data).to.be.an('array')
677 expect(res.body.data.length).to.equal(3)
680 it('Should fail without a correct uuid', async function () {
681 await request(server.url)
682 .get(path + 'coucou')
683 .set('Accept', 'application/json')
687 it('Should return 404 with an incorrect video', async function () {
688 await request(server.url)
689 .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
690 .set('Accept', 'application/json')
694 it('Should succeed with the correct parameters')
697 describe('When rating a video', function () {
700 before(async function () {
701 const res = await getVideosList(server.url)
702 videoId = res.body.data[0].id
705 it('Should fail without a valid uuid', async function () {
709 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
712 it('Should fail with an unknown id', async function () {
716 await makePutBodyRequest({
718 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
719 token: server.accessToken,
721 statusCodeExpected: 404
725 it('Should fail with a wrong rating', async function () {
729 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
732 it('Should succeed with the correct parameters', async function () {
736 await makePutBodyRequest({
738 path: path + videoId + '/rate',
739 token: server.accessToken,
741 statusCodeExpected: 204
746 describe('When removing a video', function () {
747 it('Should have 404 with nothing', async function () {
748 await request(server.url)
750 .set('Authorization', 'Bearer ' + server.accessToken)
754 it('Should fail without a correct uuid', async function () {
755 await request(server.url)
756 .delete(path + 'hello')
757 .set('Authorization', 'Bearer ' + server.accessToken)
761 it('Should fail with a video which does not exist', async function () {
762 await request(server.url)
763 .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
764 .set('Authorization', 'Bearer ' + server.accessToken)
768 it('Should fail with a video of another user')
770 it('Should fail with a video of another pod')
772 it('Should succeed with the correct parameters')
775 after(async function () {
776 killallServers([ server ])
778 // Keep the logs if the test failed