1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { omit } from 'lodash'
6 import { join } from 'path'
7 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
24 setAccessTokensToServers,
26 } from '../../../../shared/extra-utils'
28 checkBadCountPagination,
29 checkBadSortPagination,
30 checkBadStartPagination
31 } from '../../../../shared/extra-utils/requests/check-api-params'
32 import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
33 import { randomInt } from '@shared/core-utils'
35 const expect = chai.expect
37 describe('Test videos API validator', function () {
38 const path = '/api/v1/videos/'
39 let server: ServerInfo
40 let userAccessToken = ''
41 let accountName: string
43 let channelName: string
46 // ---------------------------------------------------------------
48 before(async function () {
51 server = await flushAndRunServer(1)
53 await setAccessTokensToServers([ server ])
55 const username = 'user1'
56 const password = 'my super password'
57 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
58 userAccessToken = await userLogin(server, { username, password })
61 const res = await getMyUserInformation(server.url, server.accessToken)
62 channelId = res.body.videoChannels[0].id
63 channelName = res.body.videoChannels[0].name
64 accountName = res.body.account.name + '@' + res.body.account.host
68 describe('When listing videos', function () {
69 it('Should fail with a bad start pagination', async function () {
70 await checkBadStartPagination(server.url, path)
73 it('Should fail with a bad count pagination', async function () {
74 await checkBadCountPagination(server.url, path)
77 it('Should fail with an incorrect sort', async function () {
78 await checkBadSortPagination(server.url, path)
81 it('Should fail with a bad skipVideos query', async function () {
82 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: 'toto' } })
85 it('Should success with the correct parameters', async function () {
86 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: false } })
90 describe('When searching a video', function () {
92 it('Should fail with nothing', async function () {
93 await makeGetRequest({
95 path: join(path, 'search'),
96 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
100 it('Should fail with a bad start pagination', async function () {
101 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
104 it('Should fail with a bad count pagination', async function () {
105 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
108 it('Should fail with an incorrect sort', async function () {
109 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
112 it('Should success with the correct parameters', async function () {
113 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
117 describe('When listing my videos', function () {
118 const path = '/api/v1/users/me/videos'
120 it('Should fail with a bad start pagination', async function () {
121 await checkBadStartPagination(server.url, path, server.accessToken)
124 it('Should fail with a bad count pagination', async function () {
125 await checkBadCountPagination(server.url, path, server.accessToken)
128 it('Should fail with an incorrect sort', async function () {
129 await checkBadSortPagination(server.url, path, server.accessToken)
132 it('Should success with the correct parameters', async function () {
133 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: HttpStatusCode.OK_200 })
137 describe('When listing account videos', function () {
140 before(async function () {
141 path = '/api/v1/accounts/' + accountName + '/videos'
144 it('Should fail with a bad start pagination', async function () {
145 await checkBadStartPagination(server.url, path, server.accessToken)
148 it('Should fail with a bad count pagination', async function () {
149 await checkBadCountPagination(server.url, path, server.accessToken)
152 it('Should fail with an incorrect sort', async function () {
153 await checkBadSortPagination(server.url, path, server.accessToken)
156 it('Should success with the correct parameters', async function () {
157 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
161 describe('When listing video channel videos', function () {
164 before(async function () {
165 path = '/api/v1/video-channels/' + channelName + '/videos'
168 it('Should fail with a bad start pagination', async function () {
169 await checkBadStartPagination(server.url, path, server.accessToken)
172 it('Should fail with a bad count pagination', async function () {
173 await checkBadCountPagination(server.url, path, server.accessToken)
176 it('Should fail with an incorrect sort', async function () {
177 await checkBadSortPagination(server.url, path, server.accessToken)
180 it('Should success with the correct parameters', async function () {
181 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
185 describe('When adding a video', function () {
186 let baseCorrectParams
187 const baseCorrectAttaches = {
188 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.webm')
192 // Put in before to have channelId
193 baseCorrectParams = {
194 name: 'my super name',
199 commentsEnabled: true,
200 downloadEnabled: true,
201 waitTranscoding: true,
202 description: 'my super description',
203 support: 'my super support text',
204 tags: [ 'tag1', 'tag2' ],
205 privacy: VideoPrivacy.PUBLIC,
206 channelId: channelId,
207 originallyPublishedAt: new Date().toISOString()
211 function runSuite (mode: 'legacy' | 'resumable') {
213 it('Should fail with nothing', async function () {
216 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
219 it('Should fail without name', async function () {
220 const fields = omit(baseCorrectParams, 'name')
221 const attaches = baseCorrectAttaches
223 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
226 it('Should fail with a long name', async function () {
227 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
228 const attaches = baseCorrectAttaches
230 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
233 it('Should fail with a bad category', async function () {
234 const fields = immutableAssign(baseCorrectParams, { category: 125 })
235 const attaches = baseCorrectAttaches
237 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
240 it('Should fail with a bad licence', async function () {
241 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
242 const attaches = baseCorrectAttaches
244 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
247 it('Should fail with a bad language', async function () {
248 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
249 const attaches = baseCorrectAttaches
251 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
254 it('Should fail with a long description', async function () {
255 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
256 const attaches = baseCorrectAttaches
258 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
261 it('Should fail with a long support text', async function () {
262 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
263 const attaches = baseCorrectAttaches
265 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
268 it('Should fail without a channel', async function () {
269 const fields = omit(baseCorrectParams, 'channelId')
270 const attaches = baseCorrectAttaches
272 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
275 it('Should fail with a bad channel', async function () {
276 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
277 const attaches = baseCorrectAttaches
279 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
282 it('Should fail with another user channel', async function () {
284 username: 'fake' + randomInt(0, 1500),
285 password: 'fake_password'
287 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
289 const accessTokenUser = await userLogin(server, user)
290 const res = await getMyUserInformation(server.url, accessTokenUser)
291 const customChannelId = res.body.videoChannels[0].id
293 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
294 const attaches = baseCorrectAttaches
296 await checkUploadVideoParam(server.url, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
299 it('Should fail with too many tags', async function () {
300 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
301 const attaches = baseCorrectAttaches
303 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
306 it('Should fail with a tag length too low', async function () {
307 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
308 const attaches = baseCorrectAttaches
310 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
313 it('Should fail with a tag length too big', async function () {
314 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
315 const attaches = baseCorrectAttaches
317 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
320 it('Should fail with a bad schedule update (miss updateAt)', async function () {
321 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
322 const attaches = baseCorrectAttaches
324 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
327 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
328 const fields = immutableAssign(baseCorrectParams, {
330 privacy: VideoPrivacy.PUBLIC,
334 const attaches = baseCorrectAttaches
336 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
339 it('Should fail with a bad originally published at attribute', async function () {
340 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
341 const attaches = baseCorrectAttaches
343 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
346 it('Should fail without an input file', async function () {
347 const fields = baseCorrectParams
349 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
352 it('Should fail with an incorrect input file', async function () {
353 const fields = baseCorrectParams
354 let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') }
356 await checkUploadVideoParam(
359 { ...fields, ...attaches },
360 HttpStatusCode.UNPROCESSABLE_ENTITY_422,
364 attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') }
365 await checkUploadVideoParam(
368 { ...fields, ...attaches },
369 HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415,
374 it('Should fail with an incorrect thumbnail file', async function () {
375 const fields = baseCorrectParams
377 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
378 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
381 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
384 it('Should fail with a big thumbnail file', async function () {
385 const fields = baseCorrectParams
387 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
388 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
391 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
394 it('Should fail with an incorrect preview file', async function () {
395 const fields = baseCorrectParams
397 previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
398 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
401 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
404 it('Should fail with a big preview file', async function () {
405 const fields = baseCorrectParams
407 previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
408 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
411 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
414 it('Should succeed with the correct parameters', async function () {
417 const fields = baseCorrectParams
420 const attaches = baseCorrectAttaches
421 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
425 const attaches = immutableAssign(baseCorrectAttaches, {
426 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
429 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
433 const attaches = immutableAssign(baseCorrectAttaches, {
434 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
437 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
442 describe('Resumable upload', function () {
443 runSuite('resumable')
446 describe('Legacy upload', function () {
451 describe('When updating a video', function () {
452 const baseCorrectParams = {
453 name: 'my super name',
458 commentsEnabled: false,
459 downloadEnabled: false,
460 description: 'my super description',
461 privacy: VideoPrivacy.PUBLIC,
462 tags: [ 'tag1', 'tag2' ]
465 before(async function () {
466 const res = await getVideosList(server.url)
467 videoId = res.body.data[0].uuid
470 it('Should fail with nothing', async function () {
472 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
475 it('Should fail without a valid uuid', async function () {
476 const fields = baseCorrectParams
477 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
480 it('Should fail with an unknown id', async function () {
481 const fields = baseCorrectParams
483 await makePutBodyRequest({
485 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
486 token: server.accessToken,
488 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
492 it('Should fail with a long name', async function () {
493 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
495 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
498 it('Should fail with a bad category', async function () {
499 const fields = immutableAssign(baseCorrectParams, { category: 125 })
501 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
504 it('Should fail with a bad licence', async function () {
505 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
507 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
510 it('Should fail with a bad language', async function () {
511 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
513 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
516 it('Should fail with a long description', async function () {
517 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
519 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
522 it('Should fail with a long support text', async function () {
523 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
525 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
528 it('Should fail with a bad channel', async function () {
529 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
531 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
534 it('Should fail with too many tags', async function () {
535 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
537 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
540 it('Should fail with a tag length too low', async function () {
541 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
543 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
546 it('Should fail with a tag length too big', async function () {
547 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
549 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
552 it('Should fail with a bad schedule update (miss updateAt)', async function () {
553 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
555 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
558 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
559 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
561 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
564 it('Should fail with a bad originally published at param', async function () {
565 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
567 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
570 it('Should fail with an incorrect thumbnail file', async function () {
571 const fields = baseCorrectParams
573 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
576 await makeUploadRequest({
579 path: path + videoId,
580 token: server.accessToken,
586 it('Should fail with a big thumbnail file', async function () {
587 const fields = baseCorrectParams
589 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png')
592 await makeUploadRequest({
595 path: path + videoId,
596 token: server.accessToken,
602 it('Should fail with an incorrect preview file', async function () {
603 const fields = baseCorrectParams
605 previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
608 await makeUploadRequest({
611 path: path + videoId,
612 token: server.accessToken,
618 it('Should fail with a big preview file', async function () {
619 const fields = baseCorrectParams
621 previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png')
624 await makeUploadRequest({
627 path: path + videoId,
628 token: server.accessToken,
634 it('Should fail with a video of another user without the appropriate right', async function () {
635 const fields = baseCorrectParams
637 await makePutBodyRequest({
639 path: path + videoId,
640 token: userAccessToken,
642 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
646 it('Should fail with a video of another server')
648 it('Should succeed with the correct parameters', async function () {
649 const fields = baseCorrectParams
651 await makePutBodyRequest({
653 path: path + videoId,
654 token: server.accessToken,
656 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
661 describe('When getting a video', function () {
662 it('Should return the list of the videos with nothing', async function () {
663 const res = await makeGetRequest({
666 statusCodeExpected: HttpStatusCode.OK_200
669 expect(res.body.data).to.be.an('array')
670 expect(res.body.data.length).to.equal(6)
673 it('Should fail without a correct uuid', async function () {
674 await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400)
677 it('Should return 404 with an incorrect video', async function () {
678 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
681 it('Should succeed with the correct parameters', async function () {
682 await getVideo(server.url, videoId)
686 describe('When rating a video', function () {
689 before(async function () {
690 const res = await getVideosList(server.url)
691 videoId = res.body.data[0].id
694 it('Should fail without a valid uuid', async function () {
698 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
701 it('Should fail with an unknown id', async function () {
705 await makePutBodyRequest({
707 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
708 token: server.accessToken,
710 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
714 it('Should fail with a wrong rating', async function () {
718 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
721 it('Should succeed with the correct parameters', async function () {
725 await makePutBodyRequest({
727 path: path + videoId + '/rate',
728 token: server.accessToken,
730 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
735 describe('When removing a video', function () {
736 it('Should have 404 with nothing', async function () {
737 await makeDeleteRequest({
740 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
744 it('Should fail without a correct uuid', async function () {
745 await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
748 it('Should fail with a video which does not exist', async function () {
749 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
752 it('Should fail with a video of another user without the appropriate right', async function () {
753 await removeVideo(server.url, userAccessToken, videoId, HttpStatusCode.FORBIDDEN_403)
756 it('Should fail with a video of another server')
758 it('Should succeed with the correct parameters', async function () {
759 await removeVideo(server.url, server.accessToken, videoId)
763 after(async function () {
764 await cleanupTests([ server ])