1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
4 import { omit } from 'lodash'
6 import { join } from 'path'
7 import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
22 setAccessTokensToServers,
25 } from '../../../../shared/extra-utils'
27 checkBadCountPagination,
28 checkBadSortPagination,
29 checkBadStartPagination
30 } from '../../../../shared/extra-utils/requests/check-api-params'
31 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
33 const expect = chai.expect
35 describe('Test videos API validator', function () {
36 const path = '/api/v1/videos/'
37 let server: ServerInfo
38 let userAccessToken = ''
39 let accountName: string
41 let channelName: string
44 // ---------------------------------------------------------------
46 before(async function () {
49 server = await flushAndRunServer(1)
51 await setAccessTokensToServers([ server ])
53 const username = 'user1'
54 const password = 'my super password'
55 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
56 userAccessToken = await userLogin(server, { username, password })
59 const res = await getMyUserInformation(server.url, server.accessToken)
60 channelId = res.body.videoChannels[0].id
61 channelName = res.body.videoChannels[0].name
62 accountName = res.body.account.name + '@' + res.body.account.host
66 describe('When listing videos', function () {
67 it('Should fail with a bad start pagination', async function () {
68 await checkBadStartPagination(server.url, path)
71 it('Should fail with a bad count pagination', async function () {
72 await checkBadCountPagination(server.url, path)
75 it('Should fail with an incorrect sort', async function () {
76 await checkBadSortPagination(server.url, path)
79 it('Should fail with a bad skipVideos query', async function () {
80 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: 'toto' } })
83 it('Should success with the correct parameters', async function () {
84 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: false } })
88 describe('When searching a video', function () {
90 it('Should fail with nothing', async function () {
91 await makeGetRequest({
93 path: join(path, 'search'),
94 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
98 it('Should fail with a bad start pagination', async function () {
99 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
102 it('Should fail with a bad count pagination', async function () {
103 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
106 it('Should fail with an incorrect sort', async function () {
107 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
110 it('Should success with the correct parameters', async function () {
111 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
115 describe('When listing my videos', function () {
116 const path = '/api/v1/users/me/videos'
118 it('Should fail with a bad start pagination', async function () {
119 await checkBadStartPagination(server.url, path, server.accessToken)
122 it('Should fail with a bad count pagination', async function () {
123 await checkBadCountPagination(server.url, path, server.accessToken)
126 it('Should fail with an incorrect sort', async function () {
127 await checkBadSortPagination(server.url, path, server.accessToken)
130 it('Should success with the correct parameters', async function () {
131 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: HttpStatusCode.OK_200 })
135 describe('When listing account videos', function () {
138 before(async function () {
139 path = '/api/v1/accounts/' + accountName + '/videos'
142 it('Should fail with a bad start pagination', async function () {
143 await checkBadStartPagination(server.url, path, server.accessToken)
146 it('Should fail with a bad count pagination', async function () {
147 await checkBadCountPagination(server.url, path, server.accessToken)
150 it('Should fail with an incorrect sort', async function () {
151 await checkBadSortPagination(server.url, path, server.accessToken)
154 it('Should success with the correct parameters', async function () {
155 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
159 describe('When listing video channel videos', function () {
162 before(async function () {
163 path = '/api/v1/video-channels/' + channelName + '/videos'
166 it('Should fail with a bad start pagination', async function () {
167 await checkBadStartPagination(server.url, path, server.accessToken)
170 it('Should fail with a bad count pagination', async function () {
171 await checkBadCountPagination(server.url, path, server.accessToken)
174 it('Should fail with an incorrect sort', async function () {
175 await checkBadSortPagination(server.url, path, server.accessToken)
178 it('Should success with the correct parameters', async function () {
179 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
183 describe('When adding a video', function () {
184 let baseCorrectParams
185 const baseCorrectAttaches = {
186 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.webm')
190 // Put in before to have channelId
191 baseCorrectParams = {
192 name: 'my super name',
197 commentsEnabled: true,
198 downloadEnabled: true,
199 waitTranscoding: true,
200 description: 'my super description',
201 support: 'my super support text',
202 tags: [ 'tag1', 'tag2' ],
203 privacy: VideoPrivacy.PUBLIC,
204 channelId: channelId,
205 originallyPublishedAt: new Date().toISOString()
209 it('Should fail with nothing', async function () {
212 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
215 it('Should fail without name', async function () {
216 const fields = omit(baseCorrectParams, 'name')
217 const attaches = baseCorrectAttaches
219 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
222 it('Should fail with a long name', async function () {
223 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
224 const attaches = baseCorrectAttaches
226 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
229 it('Should fail with a bad category', async function () {
230 const fields = immutableAssign(baseCorrectParams, { category: 125 })
231 const attaches = baseCorrectAttaches
233 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
236 it('Should fail with a bad licence', async function () {
237 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
238 const attaches = baseCorrectAttaches
240 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
243 it('Should fail with a bad language', async function () {
244 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
245 const attaches = baseCorrectAttaches
247 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
250 it('Should fail with a long description', async function () {
251 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
252 const attaches = baseCorrectAttaches
254 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
257 it('Should fail with a long support text', async function () {
258 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
259 const attaches = baseCorrectAttaches
261 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
264 it('Should fail without a channel', async function () {
265 const fields = omit(baseCorrectParams, 'channelId')
266 const attaches = baseCorrectAttaches
268 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
271 it('Should fail with a bad channel', async function () {
272 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
273 const attaches = baseCorrectAttaches
275 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
278 it('Should fail with another user channel', async function () {
281 password: 'fake_password'
283 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
285 const accessTokenUser = await userLogin(server, user)
286 const res = await getMyUserInformation(server.url, accessTokenUser)
287 const customChannelId = res.body.videoChannels[0].id
289 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
290 const attaches = baseCorrectAttaches
292 await makeUploadRequest({ url: server.url, path: path + '/upload', token: userAccessToken, fields, attaches })
295 it('Should fail with too many tags', async function () {
296 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
297 const attaches = baseCorrectAttaches
299 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
302 it('Should fail with a tag length too low', async function () {
303 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
304 const attaches = baseCorrectAttaches
306 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
309 it('Should fail with a tag length too big', async function () {
310 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
311 const attaches = baseCorrectAttaches
313 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
316 it('Should fail with a bad schedule update (miss updateAt)', async function () {
317 const fields = immutableAssign(baseCorrectParams, { 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC })
318 const attaches = baseCorrectAttaches
320 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
323 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
324 const fields = immutableAssign(baseCorrectParams, {
325 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC,
326 'scheduleUpdate[updateAt]': 'toto'
328 const attaches = baseCorrectAttaches
330 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
333 it('Should fail with a bad originally published at attribute', async function () {
334 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
335 const attaches = baseCorrectAttaches
337 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
340 it('Should fail without an input file', async function () {
341 const fields = baseCorrectParams
343 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
346 it('Should fail with an incorrect input file', async function () {
347 const fields = baseCorrectParams
349 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm')
351 await makeUploadRequest({
353 path: path + '/upload',
354 token: server.accessToken,
357 statusCodeExpected: HttpStatusCode.UNPROCESSABLE_ENTITY_422
361 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv')
363 await makeUploadRequest({
365 path: path + '/upload',
366 token: server.accessToken,
369 statusCodeExpected: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415
373 it('Should fail with an incorrect thumbnail file', async function () {
374 const fields = baseCorrectParams
376 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
377 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
380 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
383 it('Should fail with a big thumbnail file', async function () {
384 const fields = baseCorrectParams
386 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
387 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
390 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
393 it('Should fail with an incorrect preview file', async function () {
394 const fields = baseCorrectParams
396 previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
397 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
400 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
403 it('Should fail with a big preview file', async function () {
404 const fields = baseCorrectParams
406 previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
407 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
410 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
413 it('Should succeed with the correct parameters', async function () {
416 const fields = baseCorrectParams
419 const attaches = baseCorrectAttaches
420 await makeUploadRequest({
422 path: path + '/upload',
423 token: server.accessToken,
426 statusCodeExpected: HttpStatusCode.OK_200
431 const attaches = immutableAssign(baseCorrectAttaches, {
432 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
435 await makeUploadRequest({
437 path: path + '/upload',
438 token: server.accessToken,
441 statusCodeExpected: HttpStatusCode.OK_200
446 const attaches = immutableAssign(baseCorrectAttaches, {
447 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
450 await makeUploadRequest({
452 path: path + '/upload',
453 token: server.accessToken,
456 statusCodeExpected: HttpStatusCode.OK_200
462 describe('When updating a video', function () {
463 const baseCorrectParams = {
464 name: 'my super name',
469 commentsEnabled: false,
470 downloadEnabled: false,
471 description: 'my super description',
472 privacy: VideoPrivacy.PUBLIC,
473 tags: [ 'tag1', 'tag2' ]
476 before(async function () {
477 const res = await getVideosList(server.url)
478 videoId = res.body.data[0].uuid
481 it('Should fail with nothing', async function () {
483 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
486 it('Should fail without a valid uuid', async function () {
487 const fields = baseCorrectParams
488 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
491 it('Should fail with an unknown id', async function () {
492 const fields = baseCorrectParams
494 await makePutBodyRequest({
496 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
497 token: server.accessToken,
499 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
503 it('Should fail with a long name', async function () {
504 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
506 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
509 it('Should fail with a bad category', async function () {
510 const fields = immutableAssign(baseCorrectParams, { category: 125 })
512 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
515 it('Should fail with a bad licence', async function () {
516 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
518 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
521 it('Should fail with a bad language', async function () {
522 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
524 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
527 it('Should fail with a long description', async function () {
528 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
530 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
533 it('Should fail with a long support text', async function () {
534 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
536 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
539 it('Should fail with a bad channel', async function () {
540 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
542 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
545 it('Should fail with too many tags', async function () {
546 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
548 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
551 it('Should fail with a tag length too low', async function () {
552 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
554 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
557 it('Should fail with a tag length too big', async function () {
558 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
560 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
563 it('Should fail with a bad schedule update (miss updateAt)', async function () {
564 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
566 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
569 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
570 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
572 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
575 it('Should fail with a bad originally published at param', async function () {
576 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
578 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
581 it('Should fail with an incorrect thumbnail file', async function () {
582 const fields = baseCorrectParams
584 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
587 await makeUploadRequest({
590 path: path + videoId,
591 token: server.accessToken,
597 it('Should fail with a big thumbnail file', async function () {
598 const fields = baseCorrectParams
600 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png')
603 await makeUploadRequest({
606 path: path + videoId,
607 token: server.accessToken,
613 it('Should fail with an incorrect preview file', async function () {
614 const fields = baseCorrectParams
616 previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
619 await makeUploadRequest({
622 path: path + videoId,
623 token: server.accessToken,
629 it('Should fail with a big preview file', async function () {
630 const fields = baseCorrectParams
632 previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png')
635 await makeUploadRequest({
638 path: path + videoId,
639 token: server.accessToken,
645 it('Should fail with a video of another user without the appropriate right', async function () {
646 const fields = baseCorrectParams
648 await makePutBodyRequest({
650 path: path + videoId,
651 token: userAccessToken,
653 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
657 it('Should fail with a video of another server')
659 it('Should succeed with the correct parameters', async function () {
660 const fields = baseCorrectParams
662 await makePutBodyRequest({
664 path: path + videoId,
665 token: server.accessToken,
667 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
672 describe('When getting a video', function () {
673 it('Should return the list of the videos with nothing', async function () {
674 const res = await makeGetRequest({
677 statusCodeExpected: HttpStatusCode.OK_200
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 getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400)
688 it('Should return 404 with an incorrect video', async function () {
689 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
692 it('Should succeed with the correct parameters', async function () {
693 await getVideo(server.url, videoId)
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: HttpStatusCode.NOT_FOUND_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: HttpStatusCode.NO_CONTENT_204
746 describe('When removing a video', function () {
747 it('Should have 404 with nothing', async function () {
748 await makeDeleteRequest({
751 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
755 it('Should fail without a correct uuid', async function () {
756 await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
759 it('Should fail with a video which does not exist', async function () {
760 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
763 it('Should fail with a video of another user without the appropriate right', async function () {
764 await removeVideo(server.url, userAccessToken, videoId, HttpStatusCode.FORBIDDEN_403)
767 it('Should fail with a video of another server')
769 it('Should succeed with the correct parameters', async function () {
770 await removeVideo(server.url, server.accessToken, videoId)
774 after(async function () {
775 await cleanupTests([ server ])