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({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
354 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv')
356 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
359 it('Should fail with an incorrect thumbnail file', async function () {
360 const fields = baseCorrectParams
362 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png'),
363 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
366 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
369 it('Should fail with a big thumbnail file', async function () {
370 const fields = baseCorrectParams
372 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'),
373 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
376 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
379 it('Should fail with an incorrect preview file', async function () {
380 const fields = baseCorrectParams
382 previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png'),
383 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
386 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
389 it('Should fail with a big preview file', async function () {
390 const fields = baseCorrectParams
392 previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'),
393 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
396 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
399 it('Should succeed with the correct parameters', async function () {
402 const fields = baseCorrectParams
405 const attaches = baseCorrectAttaches
406 await makeUploadRequest({
408 path: path + '/upload',
409 token: server.accessToken,
412 statusCodeExpected: HttpStatusCode.OK_200
417 const attaches = immutableAssign(baseCorrectAttaches, {
418 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
421 await makeUploadRequest({
423 path: path + '/upload',
424 token: server.accessToken,
427 statusCodeExpected: HttpStatusCode.OK_200
432 const attaches = immutableAssign(baseCorrectAttaches, {
433 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
436 await makeUploadRequest({
438 path: path + '/upload',
439 token: server.accessToken,
442 statusCodeExpected: HttpStatusCode.OK_200
448 describe('When updating a video', function () {
449 const baseCorrectParams = {
450 name: 'my super name',
455 commentsEnabled: false,
456 downloadEnabled: false,
457 description: 'my super description',
458 privacy: VideoPrivacy.PUBLIC,
459 tags: [ 'tag1', 'tag2' ]
462 before(async function () {
463 const res = await getVideosList(server.url)
464 videoId = res.body.data[0].uuid
467 it('Should fail with nothing', async function () {
469 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
472 it('Should fail without a valid uuid', async function () {
473 const fields = baseCorrectParams
474 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
477 it('Should fail with an unknown id', async function () {
478 const fields = baseCorrectParams
480 await makePutBodyRequest({
482 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
483 token: server.accessToken,
485 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
489 it('Should fail with a long name', async function () {
490 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
492 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
495 it('Should fail with a bad category', async function () {
496 const fields = immutableAssign(baseCorrectParams, { category: 125 })
498 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
501 it('Should fail with a bad licence', async function () {
502 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
504 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
507 it('Should fail with a bad language', async function () {
508 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
510 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
513 it('Should fail with a long description', async function () {
514 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
516 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
519 it('Should fail with a long support text', async function () {
520 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
522 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
525 it('Should fail with a bad channel', async function () {
526 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
528 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
531 it('Should fail with too many tags', async function () {
532 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
534 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
537 it('Should fail with a tag length too low', async function () {
538 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
540 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
543 it('Should fail with a tag length too big', async function () {
544 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
546 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
549 it('Should fail with a bad schedule update (miss updateAt)', async function () {
550 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
552 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
555 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
556 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
558 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
561 it('Should fail with a bad originally published at param', async function () {
562 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
564 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
567 it('Should fail with an incorrect thumbnail file', async function () {
568 const fields = baseCorrectParams
570 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png')
573 await makeUploadRequest({
576 path: path + videoId,
577 token: server.accessToken,
583 it('Should fail with a big thumbnail file', async function () {
584 const fields = baseCorrectParams
586 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png')
589 await makeUploadRequest({
592 path: path + videoId,
593 token: server.accessToken,
599 it('Should fail with an incorrect preview file', async function () {
600 const fields = baseCorrectParams
602 previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png')
605 await makeUploadRequest({
608 path: path + videoId,
609 token: server.accessToken,
615 it('Should fail with a big preview file', async function () {
616 const fields = baseCorrectParams
618 previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png')
621 await makeUploadRequest({
624 path: path + videoId,
625 token: server.accessToken,
631 it('Should fail with a video of another user without the appropriate right', async function () {
632 const fields = baseCorrectParams
634 await makePutBodyRequest({
636 path: path + videoId,
637 token: userAccessToken,
639 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
643 it('Should fail with a video of another server')
645 it('Should succeed with the correct parameters', async function () {
646 const fields = baseCorrectParams
648 await makePutBodyRequest({
650 path: path + videoId,
651 token: server.accessToken,
653 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
658 describe('When getting a video', function () {
659 it('Should return the list of the videos with nothing', async function () {
660 const res = await makeGetRequest({
663 statusCodeExpected: HttpStatusCode.OK_200
666 expect(res.body.data).to.be.an('array')
667 expect(res.body.data.length).to.equal(3)
670 it('Should fail without a correct uuid', async function () {
671 await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400)
674 it('Should return 404 with an incorrect video', async function () {
675 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
678 it('Should succeed with the correct parameters', async function () {
679 await getVideo(server.url, videoId)
683 describe('When rating a video', function () {
686 before(async function () {
687 const res = await getVideosList(server.url)
688 videoId = res.body.data[0].id
691 it('Should fail without a valid uuid', async function () {
695 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
698 it('Should fail with an unknown id', async function () {
702 await makePutBodyRequest({
704 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
705 token: server.accessToken,
707 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
711 it('Should fail with a wrong rating', async function () {
715 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
718 it('Should succeed with the correct parameters', async function () {
722 await makePutBodyRequest({
724 path: path + videoId + '/rate',
725 token: server.accessToken,
727 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
732 describe('When removing a video', function () {
733 it('Should have 404 with nothing', async function () {
734 await makeDeleteRequest({
737 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
741 it('Should fail without a correct uuid', async function () {
742 await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
745 it('Should fail with a video which does not exist', async function () {
746 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
749 it('Should fail with a video of another user without the appropriate right', async function () {
750 await removeVideo(server.url, userAccessToken, videoId, HttpStatusCode.FORBIDDEN_403)
753 it('Should fail with a video of another server')
755 it('Should succeed with the correct parameters', async function () {
756 await removeVideo(server.url, server.accessToken, videoId)
760 after(async function () {
761 await cleanupTests([ server ])