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 long name',
132 description: 'my super description',
133 tags: [ 'tag1', 'tag2' ],
137 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
139 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
142 it('Should fail without a category', async function () {
144 name: 'my super name',
148 description: 'my super description',
149 tags: [ 'tag1', 'tag2' ],
153 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
155 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
158 it('Should fail with a bad category', async function () {
160 name: 'my super name',
165 description: 'my super description',
166 tags: [ 'tag1', 'tag2' ],
170 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
172 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
175 it('Should fail without a licence', async function () {
177 name: 'my super name',
181 description: 'my super description',
182 tags: [ 'tag1', 'tag2' ],
186 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
188 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
191 it('Should fail with a bad licence', async function () {
193 name: 'my super name',
198 description: 'my super description',
199 tags: [ 'tag1', 'tag2' ],
203 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
205 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
208 it('Should fail with a bad language', async function () {
210 name: 'my super name',
215 description: 'my super description',
216 tags: [ 'tag1', 'tag2' ],
220 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
222 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
225 it('Should fail without nsfw attribute', async function () {
227 name: 'my super name',
231 description: 'my super description',
232 tags: [ 'tag1', 'tag2' ],
236 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
238 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
241 it('Should fail with a bad nsfw attribute', async function () {
243 name: 'my super name',
248 description: 'my super description',
249 tags: [ 'tag1', 'tag2' ],
253 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
255 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
258 it('Should fail without description', async function () {
260 name: 'my super name',
265 tags: [ 'tag1', 'tag2' ],
269 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
271 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
274 it('Should fail with a long description', async function () {
276 name: 'my super name',
281 description: 'my super description which is very very very very very very very very very very very very very very' +
282 'very very very very very very very very very very very very very very very very very very very very very' +
283 'very very very very very very very very very very very very very very very long',
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' ],
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', '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 long name',
551 description: 'my super description',
552 tags: [ 'tag1', 'tag2' ]
554 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
557 it('Should fail with a bad category', async function () {
559 name: 'my super name',
564 description: 'my super description',
565 tags: [ 'tag1', 'tag2' ]
567 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
570 it('Should fail with a bad licence', async function () {
572 name: 'my super name',
577 description: 'my super description',
578 tags: [ 'tag1', 'tag2' ]
580 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
583 it('Should fail with a bad language', async function () {
585 name: 'my super name',
590 description: 'my super description',
591 tags: [ 'tag1', 'tag2' ]
593 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
596 it('Should fail with a bad nsfw attribute', async function () {
598 name: 'my super name',
603 description: 'my super description',
604 tags: [ 'tag1', 'tag2' ]
606 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
609 it('Should fail with a long description', async function () {
611 name: 'my super name',
616 description: 'my super description which is very very very very very very very very very very very very very very' +
617 'very very very very very very very very very very very very very very very very very very very very very' +
618 'very very very very very very very very very very very very very very very long',
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' ]
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', '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