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'
32 const expect = chai.expect
34 describe('Test videos API validator', function () {
35 const path = '/api/v1/videos/'
36 let server: ServerInfo
37 let userAccessToken = ''
38 let accountName: string
40 let channelName: string
43 // ---------------------------------------------------------------
45 before(async function () {
48 server = await flushAndRunServer(1)
50 await setAccessTokensToServers([ server ])
52 const username = 'user1'
53 const password = 'my super password'
54 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
55 userAccessToken = await userLogin(server, { username, password })
58 const res = await getMyUserInformation(server.url, server.accessToken)
59 channelId = res.body.videoChannels[0].id
60 channelName = res.body.videoChannels[0].name
61 accountName = res.body.account.name + '@' + res.body.account.host
65 describe('When listing videos', function () {
66 it('Should fail with a bad start pagination', async function () {
67 await checkBadStartPagination(server.url, path)
70 it('Should fail with a bad count pagination', async function () {
71 await checkBadCountPagination(server.url, path)
74 it('Should fail with an incorrect sort', async function () {
75 await checkBadSortPagination(server.url, path)
78 it('Should fail with a bad skipVideos query', async function () {
79 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: 'toto' } })
82 it('Should success with the correct parameters', async function () {
83 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: false } })
87 describe('When searching a video', function () {
89 it('Should fail with nothing', async function () {
90 await makeGetRequest({
92 path: join(path, 'search'),
93 statusCodeExpected: 400
97 it('Should fail with a bad start pagination', async function () {
98 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
101 it('Should fail with a bad count pagination', async function () {
102 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
105 it('Should fail with an incorrect sort', async function () {
106 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
109 it('Should success with the correct parameters', async function () {
110 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
114 describe('When listing my videos', function () {
115 const path = '/api/v1/users/me/videos'
117 it('Should fail with a bad start pagination', async function () {
118 await checkBadStartPagination(server.url, path, server.accessToken)
121 it('Should fail with a bad count pagination', async function () {
122 await checkBadCountPagination(server.url, path, server.accessToken)
125 it('Should fail with an incorrect sort', async function () {
126 await checkBadSortPagination(server.url, path, server.accessToken)
129 it('Should success with the correct parameters', async function () {
130 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 })
134 describe('When listing account videos', function () {
137 before(async function () {
138 path = '/api/v1/accounts/' + accountName + '/videos'
141 it('Should fail with a bad start pagination', async function () {
142 await checkBadStartPagination(server.url, path, server.accessToken)
145 it('Should fail with a bad count pagination', async function () {
146 await checkBadCountPagination(server.url, path, server.accessToken)
149 it('Should fail with an incorrect sort', async function () {
150 await checkBadSortPagination(server.url, path, server.accessToken)
153 it('Should success with the correct parameters', async function () {
154 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
158 describe('When listing video channel videos', function () {
161 before(async function () {
162 path = '/api/v1/video-channels/' + channelName + '/videos'
165 it('Should fail with a bad start pagination', async function () {
166 await checkBadStartPagination(server.url, path, server.accessToken)
169 it('Should fail with a bad count pagination', async function () {
170 await checkBadCountPagination(server.url, path, server.accessToken)
173 it('Should fail with an incorrect sort', async function () {
174 await checkBadSortPagination(server.url, path, server.accessToken)
177 it('Should success with the correct parameters', async function () {
178 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
182 describe('When adding a video', function () {
183 let baseCorrectParams
184 const baseCorrectAttaches = {
185 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.webm')
189 // Put in before to have channelId
190 baseCorrectParams = {
191 name: 'my super name',
196 commentsEnabled: true,
197 downloadEnabled: true,
198 waitTranscoding: true,
199 description: 'my super description',
200 support: 'my super support text',
201 tags: [ 'tag1', 'tag2' ],
202 privacy: VideoPrivacy.PUBLIC,
203 channelId: channelId,
204 originallyPublishedAt: new Date().toISOString()
208 it('Should fail with nothing', async function () {
211 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
214 it('Should fail without name', async function () {
215 const fields = omit(baseCorrectParams, 'name')
216 const attaches = baseCorrectAttaches
218 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
221 it('Should fail with a long name', async function () {
222 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
223 const attaches = baseCorrectAttaches
225 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
228 it('Should fail with a bad category', async function () {
229 const fields = immutableAssign(baseCorrectParams, { category: 125 })
230 const attaches = baseCorrectAttaches
232 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
235 it('Should fail with a bad licence', async function () {
236 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
237 const attaches = baseCorrectAttaches
239 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
242 it('Should fail with a bad language', async function () {
243 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
244 const attaches = baseCorrectAttaches
246 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
249 it('Should fail with a long description', async function () {
250 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
251 const attaches = baseCorrectAttaches
253 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
256 it('Should fail with a long support text', async function () {
257 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
258 const attaches = baseCorrectAttaches
260 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
263 it('Should fail without a channel', async function () {
264 const fields = omit(baseCorrectParams, 'channelId')
265 const attaches = baseCorrectAttaches
267 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
270 it('Should fail with a bad channel', async function () {
271 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
272 const attaches = baseCorrectAttaches
274 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
277 it('Should fail with another user channel', async function () {
280 password: 'fake_password'
282 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
284 const accessTokenUser = await userLogin(server, user)
285 const res = await getMyUserInformation(server.url, accessTokenUser)
286 const customChannelId = res.body.videoChannels[0].id
288 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
289 const attaches = baseCorrectAttaches
291 await makeUploadRequest({ url: server.url, path: path + '/upload', token: userAccessToken, fields, attaches })
294 it('Should fail with too many tags', async function () {
295 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
296 const attaches = baseCorrectAttaches
298 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
301 it('Should fail with a tag length too low', async function () {
302 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
303 const attaches = baseCorrectAttaches
305 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
308 it('Should fail with a tag length too big', async function () {
309 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
310 const attaches = baseCorrectAttaches
312 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
315 it('Should fail with a bad schedule update (miss updateAt)', async function () {
316 const fields = immutableAssign(baseCorrectParams, { 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC })
317 const attaches = baseCorrectAttaches
319 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
322 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
323 const fields = immutableAssign(baseCorrectParams, {
324 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC,
325 'scheduleUpdate[updateAt]': 'toto'
327 const attaches = baseCorrectAttaches
329 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
332 it('Should fail with a bad originally published at attribute', async function () {
333 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
334 const attaches = baseCorrectAttaches
336 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
339 it('Should fail without an input file', async function () {
340 const fields = baseCorrectParams
342 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
345 it('Should fail with an incorrect input file', async function () {
346 const fields = baseCorrectParams
348 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm')
350 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
353 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv')
355 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
358 it('Should fail with an incorrect thumbnail file', async function () {
359 const fields = baseCorrectParams
361 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png'),
362 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
365 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
368 it('Should fail with a big thumbnail file', async function () {
369 const fields = baseCorrectParams
371 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'),
372 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
375 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
378 it('Should fail with an incorrect preview file', async function () {
379 const fields = baseCorrectParams
381 previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png'),
382 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
385 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
388 it('Should fail with a big preview file', async function () {
389 const fields = baseCorrectParams
391 previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'),
392 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
395 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
398 it('Should succeed with the correct parameters', async function () {
401 const fields = baseCorrectParams
404 const attaches = baseCorrectAttaches
405 await makeUploadRequest({
407 path: path + '/upload',
408 token: server.accessToken,
411 statusCodeExpected: 200
416 const attaches = immutableAssign(baseCorrectAttaches, {
417 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
420 await makeUploadRequest({
422 path: path + '/upload',
423 token: server.accessToken,
426 statusCodeExpected: 200
431 const attaches = immutableAssign(baseCorrectAttaches, {
432 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
435 await makeUploadRequest({
437 path: path + '/upload',
438 token: server.accessToken,
441 statusCodeExpected: 200
447 describe('When updating a video', function () {
448 const baseCorrectParams = {
449 name: 'my super name',
454 commentsEnabled: false,
455 downloadEnabled: false,
456 description: 'my super description',
457 privacy: VideoPrivacy.PUBLIC,
458 tags: [ 'tag1', 'tag2' ]
461 before(async function () {
462 const res = await getVideosList(server.url)
463 videoId = res.body.data[0].uuid
466 it('Should fail with nothing', async function () {
468 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
471 it('Should fail without a valid uuid', async function () {
472 const fields = baseCorrectParams
473 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
476 it('Should fail with an unknown id', async function () {
477 const fields = baseCorrectParams
479 await makePutBodyRequest({
481 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
482 token: server.accessToken,
484 statusCodeExpected: 404
488 it('Should fail with a long name', async function () {
489 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
491 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
494 it('Should fail with a bad category', async function () {
495 const fields = immutableAssign(baseCorrectParams, { category: 125 })
497 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
500 it('Should fail with a bad licence', async function () {
501 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
503 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
506 it('Should fail with a bad language', async function () {
507 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
509 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
512 it('Should fail with a long description', async function () {
513 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
515 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
518 it('Should fail with a long support text', async function () {
519 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
521 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
524 it('Should fail with a bad channel', async function () {
525 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
527 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
530 it('Should fail with too many tags', async function () {
531 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
533 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
536 it('Should fail with a tag length too low', async function () {
537 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
539 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
542 it('Should fail with a tag length too big', async function () {
543 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
545 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
548 it('Should fail with a bad schedule update (miss updateAt)', async function () {
549 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
551 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
554 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
555 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
557 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
560 it('Should fail with a bad originally published at param', async function () {
561 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
563 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
566 it('Should fail with an incorrect thumbnail file', async function () {
567 const fields = baseCorrectParams
569 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png')
572 await makeUploadRequest({
575 path: path + videoId,
576 token: server.accessToken,
582 it('Should fail with a big thumbnail file', async function () {
583 const fields = baseCorrectParams
585 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png')
588 await makeUploadRequest({
591 path: path + videoId,
592 token: server.accessToken,
598 it('Should fail with an incorrect preview file', async function () {
599 const fields = baseCorrectParams
601 previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png')
604 await makeUploadRequest({
607 path: path + videoId,
608 token: server.accessToken,
614 it('Should fail with a big preview file', async function () {
615 const fields = baseCorrectParams
617 previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png')
620 await makeUploadRequest({
623 path: path + videoId,
624 token: server.accessToken,
630 it('Should fail with a video of another user without the appropriate right', async function () {
631 const fields = baseCorrectParams
633 await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 })
636 it('Should fail with a video of another server')
638 it('Should succeed with the correct parameters', async function () {
639 const fields = baseCorrectParams
641 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
645 describe('When getting a video', function () {
646 it('Should return the list of the videos with nothing', async function () {
647 const res = await makeGetRequest({
650 statusCodeExpected: 200
653 expect(res.body.data).to.be.an('array')
654 expect(res.body.data.length).to.equal(3)
657 it('Should fail without a correct uuid', async function () {
658 await getVideo(server.url, 'coucou', 400)
661 it('Should return 404 with an incorrect video', async function () {
662 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
665 it('Should succeed with the correct parameters', async function () {
666 await getVideo(server.url, videoId)
670 describe('When rating a video', function () {
673 before(async function () {
674 const res = await getVideosList(server.url)
675 videoId = res.body.data[0].id
678 it('Should fail without a valid uuid', async function () {
682 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
685 it('Should fail with an unknown id', async function () {
689 await makePutBodyRequest({
691 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
692 token: server.accessToken,
694 statusCodeExpected: 404
698 it('Should fail with a wrong rating', async function () {
702 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
705 it('Should succeed with the correct parameters', async function () {
709 await makePutBodyRequest({
711 path: path + videoId + '/rate',
712 token: server.accessToken,
714 statusCodeExpected: 204
719 describe('When removing a video', function () {
720 it('Should have 404 with nothing', async function () {
721 await makeDeleteRequest({
724 statusCodeExpected: 400
728 it('Should fail without a correct uuid', async function () {
729 await removeVideo(server.url, server.accessToken, 'hello', 400)
732 it('Should fail with a video which does not exist', async function () {
733 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
736 it('Should fail with a video of another user without the appropriate right', async function () {
737 await removeVideo(server.url, userAccessToken, videoId, 403)
740 it('Should fail with a video of another server')
742 it('Should succeed with the correct parameters', async function () {
743 await removeVideo(server.url, server.accessToken, videoId)
747 after(async function () {
748 await cleanupTests([ server ])