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' +
284 'very very very very very very very very very very very very very very very very very very very very very' +
285 'very very very very very very very very very very very very very very very long',
286 tags: [ 'tag1', 'tag2' ],
290 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
292 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
295 it('Should fail without a channel', async function () {
297 name: 'my super name',
302 description: 'my super description',
303 tags: [ 'tag1', 'tag2' ]
306 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
308 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
311 it('Should fail with a bad channel', async function () {
313 name: 'my super name',
318 description: 'my super description',
319 tags: [ 'tag1', 'tag2' ],
323 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
325 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
328 it('Should fail with another user channel', async function () {
331 password: 'fake_password'
333 await createUser(server.url, server.accessToken, user.username, user.password)
335 const accessTokenUser = await getUserAccessToken(server, user)
336 const res = await getMyUserInformation(server.url, accessTokenUser)
337 const channelId = res.body.videoChannels[0].id
340 name: 'my super name',
345 description: 'my super description',
346 tags: [ 'tag1', 'tag2' ],
350 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
352 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
355 it('Should fail with too many tags', async function () {
357 name: 'my super name',
362 description: 'my super description',
363 tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ],
367 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
369 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
372 it('Should fail with a tag length too low', async function () {
374 name: 'my super name',
379 description: 'my super description',
380 tags: [ 'tag1', 't' ],
384 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
386 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
389 it('Should fail with a tag length too big', async function () {
391 name: 'my super name',
396 description: 'my super description',
397 tags: [ 'my_super_tag_too_long_long_long_long_long_long', 'tag1' ],
401 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
403 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
406 it('Should fail without an input file', async function () {
408 name: 'my super name',
413 description: 'my super description',
414 tags: [ 'tag1', 'tag2' ],
418 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
421 it('Should fail without an incorrect input file', async function () {
423 name: 'my super name',
428 description: 'my super description',
429 tags: [ 'tag1', 'tag2' ],
433 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
435 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
438 it('Should fail with a too big duration', async function () {
440 name: 'my super name',
445 description: 'my super description',
446 tags: [ 'tag1', 'tag2' ],
450 'videofile': join(__dirname, '..', 'fixtures', 'video_too_long.webm')
452 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
455 it('Should succeed with the correct parameters', async function () {
459 name: 'my super name',
464 description: 'my super description',
465 tags: [ 'tag1', 'tag2' ],
469 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
472 await makePostUploadRequest({
474 path: path + '/upload',
475 token: server.accessToken,
478 statusCodeExpected: 204
481 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.mp4')
482 await makePostUploadRequest({
484 path: path + '/upload',
485 token: server.accessToken,
488 statusCodeExpected: 204
491 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.ogv')
492 await makePostUploadRequest({
494 path: path + '/upload',
495 token: server.accessToken,
498 statusCodeExpected: 204
503 describe('When updating a video', function () {
506 before(async function () {
507 const res = await getVideosList(server.url)
508 videoId = res.body.data[0].id
511 it('Should fail with nothing', async function () {
513 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
516 it('Should fail without a valid uuid', async function () {
522 description: 'my super description',
523 tags: [ 'tag1', 'tag2' ]
525 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
528 it('Should fail with an unknown id', async function () {
534 description: 'my super description',
535 tags: [ 'tag1', 'tag2' ]
537 await makePutBodyRequest({
539 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
540 token: server.accessToken,
542 statusCodeExpected: 404
546 it('Should fail with a long name', async function () {
548 name: 'My very very very very very very very very very very very very very very very very very ' +
549 'very very very very very very very very very very very very very very very very long long' +
550 'very very very very very very very very very very very very very very very very long name',
555 description: 'my super description',
556 tags: [ 'tag1', 'tag2' ]
558 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
561 it('Should fail with a bad category', async function () {
563 name: 'my super name',
568 description: 'my super description',
569 tags: [ 'tag1', 'tag2' ]
571 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
574 it('Should fail with a bad licence', async function () {
576 name: 'my super name',
581 description: 'my super description',
582 tags: [ 'tag1', 'tag2' ]
584 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
587 it('Should fail with a bad language', async function () {
589 name: 'my super name',
594 description: 'my super description',
595 tags: [ 'tag1', 'tag2' ]
597 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
600 it('Should fail with a bad nsfw attribute', async function () {
602 name: 'my super name',
607 description: 'my super description',
608 tags: [ 'tag1', 'tag2' ]
610 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
613 it('Should fail with a long description', async function () {
615 name: 'my super name',
620 description: 'my super description which is very very very very very very very very very very very very very very' +
621 'very very very very very very very very very very very very very very very very very very very very very' +
622 'very very very very very very very very very very very very very very very long',
623 tags: [ 'tag1', 'tag2' ]
625 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
628 it('Should fail with too many tags', async function () {
630 name: 'my super name',
635 description: 'my super description',
636 tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ]
638 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
641 it('Should fail with a tag length too low', async function () {
643 name: 'my super name',
648 description: 'my super description',
649 tags: [ 'tag1', 't' ]
651 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
654 it('Should fail with a tag length too big', async function () {
656 name: 'my super name',
661 description: 'my super description',
662 tags: [ 'my_super_tag_too_long_long_long_long', 'tag1' ]
664 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
667 it('Should fail with a video of another user')
669 it('Should fail with a video of another pod')
672 describe('When getting a video', function () {
673 it('Should return the list of the videos with nothing', async function () {
674 const res = await request(server.url)
676 .set('Accept', 'application/json')
678 .expect('Content-Type', /json/)
680 expect(res.body.data).to.be.an('array')
681 expect(res.body.data.length).to.equal(3)
684 it('Should fail without a correct uuid', async function () {
685 await request(server.url)
686 .get(path + 'coucou')
687 .set('Accept', 'application/json')
691 it('Should return 404 with an incorrect video', async function () {
692 await request(server.url)
693 .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
694 .set('Accept', 'application/json')
698 it('Should succeed with the correct parameters')
701 describe('When rating a video', function () {
704 before(async function () {
705 const res = await getVideosList(server.url)
706 videoId = res.body.data[0].id
709 it('Should fail without a valid uuid', async function () {
713 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
716 it('Should fail with an unknown id', async function () {
720 await makePutBodyRequest({
722 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
723 token: server.accessToken,
725 statusCodeExpected: 404
729 it('Should fail with a wrong rating', async function () {
733 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
736 it('Should succeed with the correct parameters', async function () {
740 await makePutBodyRequest({
742 path: path + videoId + '/rate',
743 token: server.accessToken,
745 statusCodeExpected: 204
750 describe('When removing a video', function () {
751 it('Should have 404 with nothing', async function () {
752 await request(server.url)
754 .set('Authorization', 'Bearer ' + server.accessToken)
758 it('Should fail without a correct uuid', async function () {
759 await request(server.url)
760 .delete(path + 'hello')
761 .set('Authorization', 'Bearer ' + server.accessToken)
765 it('Should fail with a video which does not exist', async function () {
766 await request(server.url)
767 .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
768 .set('Authorization', 'Bearer ' + server.accessToken)
772 it('Should fail with a video of another user')
774 it('Should fail with a video of another pod')
776 it('Should succeed with the correct parameters')
779 after(async function () {
780 killallServers([ server ])
782 // Keep the logs if the test failed