1 /* tslint:disable:no-unused-expression */
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'
9 createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest,
10 makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin
11 } from '../../../../shared/utils'
13 checkBadCountPagination,
14 checkBadSortPagination,
15 checkBadStartPagination
16 } from '../../../../shared/utils/requests/check-api-params'
17 import { getAccountsList } from '../../../../shared/utils/users/accounts'
19 const expect = chai.expect
21 describe('Test videos API validator', function () {
22 const path = '/api/v1/videos/'
23 let server: ServerInfo
24 let userAccessToken = ''
25 let accountName: string
27 let channelName: string
30 // ---------------------------------------------------------------
32 before(async function () {
37 server = await runServer(1)
39 await setAccessTokensToServers([ server ])
41 const username = 'user1'
42 const password = 'my super password'
43 await createUser(server.url, server.accessToken, username, password)
44 userAccessToken = await userLogin(server, { username, password })
47 const res = await getMyUserInformation(server.url, server.accessToken)
48 channelId = res.body.videoChannels[ 0 ].id
49 channelName = res.body.videoChannels[ 0 ].name
50 accountName = res.body.account.name + '@' + res.body.account.host
54 describe('When listing a video', function () {
55 it('Should fail with a bad start pagination', async function () {
56 await checkBadStartPagination(server.url, path)
59 it('Should fail with a bad count pagination', async function () {
60 await checkBadCountPagination(server.url, path)
63 it('Should fail with an incorrect sort', async function () {
64 await checkBadSortPagination(server.url, path)
67 it('Should success with the correct parameters', async function () {
68 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
72 describe('When searching a video', function () {
74 it('Should fail with nothing', async function () {
75 await makeGetRequest({
77 path: join(path, 'search'),
78 statusCodeExpected: 400
82 it('Should fail with a bad start pagination', async function () {
83 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
86 it('Should fail with a bad count pagination', async function () {
87 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
90 it('Should fail with an incorrect sort', async function () {
91 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
94 it('Should success with the correct parameters', async function () {
95 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
99 describe('When listing my videos', function () {
100 const path = '/api/v1/users/me/videos'
102 it('Should fail with a bad start pagination', async function () {
103 await checkBadStartPagination(server.url, path, server.accessToken)
106 it('Should fail with a bad count pagination', async function () {
107 await checkBadCountPagination(server.url, path, server.accessToken)
110 it('Should fail with an incorrect sort', async function () {
111 await checkBadSortPagination(server.url, path, server.accessToken)
114 it('Should success with the correct parameters', async function () {
115 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 })
119 describe('When listing account videos', function () {
122 before(async function () {
123 path = '/api/v1/accounts/' + accountName + '/videos'
126 it('Should fail with a bad start pagination', async function () {
127 await checkBadStartPagination(server.url, path, server.accessToken)
130 it('Should fail with a bad count pagination', async function () {
131 await checkBadCountPagination(server.url, path, server.accessToken)
134 it('Should fail with an incorrect sort', async function () {
135 await checkBadSortPagination(server.url, path, server.accessToken)
138 it('Should success with the correct parameters', async function () {
139 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
143 describe('When listing video channel videos', function () {
146 before(async function () {
147 path = '/api/v1/video-channels/' + channelName + '/videos'
150 it('Should fail with a bad start pagination', async function () {
151 await checkBadStartPagination(server.url, path, server.accessToken)
154 it('Should fail with a bad count pagination', async function () {
155 await checkBadCountPagination(server.url, path, server.accessToken)
158 it('Should fail with an incorrect sort', async function () {
159 await checkBadSortPagination(server.url, path, server.accessToken)
162 it('Should success with the correct parameters', async function () {
163 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
167 describe('When adding a video', function () {
168 let baseCorrectParams
169 const baseCorrectAttaches = {
170 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.webm')
174 // Put in before to have channelId
175 baseCorrectParams = {
176 name: 'my super name',
181 commentsEnabled: true,
182 waitTranscoding: true,
183 description: 'my super description',
184 support: 'my super support text',
185 tags: [ 'tag1', 'tag2' ],
186 privacy: VideoPrivacy.PUBLIC,
191 it('Should fail with nothing', async function () {
194 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
197 it('Should fail without name', async function () {
198 const fields = omit(baseCorrectParams, 'name')
199 const attaches = baseCorrectAttaches
201 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
204 it('Should fail with a long name', async function () {
205 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
206 const attaches = baseCorrectAttaches
208 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
211 it('Should fail with a bad category', async function () {
212 const fields = immutableAssign(baseCorrectParams, { category: 125 })
213 const attaches = baseCorrectAttaches
215 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
218 it('Should fail with a bad licence', async function () {
219 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
220 const attaches = baseCorrectAttaches
222 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
225 it('Should fail with a bad language', async function () {
226 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
227 const attaches = baseCorrectAttaches
229 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
232 it('Should fail with a long description', async function () {
233 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
234 const attaches = baseCorrectAttaches
236 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
239 it('Should fail with a long support text', async function () {
240 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
241 const attaches = baseCorrectAttaches
243 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
246 it('Should fail without a channel', async function () {
247 const fields = omit(baseCorrectParams, 'channelId')
248 const attaches = baseCorrectAttaches
250 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
253 it('Should fail with a bad channel', async function () {
254 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
255 const attaches = baseCorrectAttaches
257 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
260 it('Should fail with another user channel', async function () {
263 password: 'fake_password'
265 await createUser(server.url, server.accessToken, user.username, user.password)
267 const accessTokenUser = await userLogin(server, user)
268 const res = await getMyUserInformation(server.url, accessTokenUser)
269 const customChannelId = res.body.videoChannels[0].id
271 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
272 const attaches = baseCorrectAttaches
274 await makeUploadRequest({ url: server.url, path: path + '/upload', token: userAccessToken, fields, attaches })
277 it('Should fail with too many tags', async function () {
278 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
279 const attaches = baseCorrectAttaches
281 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
284 it('Should fail with a tag length too low', async function () {
285 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
286 const attaches = baseCorrectAttaches
288 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
291 it('Should fail with a tag length too big', async function () {
292 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
293 const attaches = baseCorrectAttaches
295 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
298 it('Should fail with a bad schedule update (miss updateAt)', async function () {
299 const fields = immutableAssign(baseCorrectParams, { 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC })
300 const attaches = baseCorrectAttaches
302 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
305 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
306 const fields = immutableAssign(baseCorrectParams, {
307 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC,
308 'scheduleUpdate[updateAt]': 'toto'
310 const attaches = baseCorrectAttaches
312 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
315 it('Should fail without an input file', async function () {
316 const fields = baseCorrectParams
318 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
321 it('Should fail without an incorrect input file', async function () {
322 const fields = baseCorrectParams
324 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm')
326 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
329 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mkv')
331 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
334 it('Should fail with an incorrect thumbnail file', async function () {
335 const fields = baseCorrectParams
337 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'),
338 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
341 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
344 it('Should fail with a big thumbnail file', async function () {
345 const fields = baseCorrectParams
347 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
348 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
351 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
354 it('Should fail with an incorrect preview file', async function () {
355 const fields = baseCorrectParams
357 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'),
358 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
361 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
364 it('Should fail with a big preview file', async function () {
365 const fields = baseCorrectParams
367 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
368 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
371 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
374 it('Should succeed with the correct parameters', async function () {
377 const fields = baseCorrectParams
380 const attaches = baseCorrectAttaches
381 await makeUploadRequest({
383 path: path + '/upload',
384 token: server.accessToken,
387 statusCodeExpected: 200
392 const attaches = immutableAssign(baseCorrectAttaches, {
393 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
396 await makeUploadRequest({
398 path: path + '/upload',
399 token: server.accessToken,
402 statusCodeExpected: 200
407 const attaches = immutableAssign(baseCorrectAttaches, {
408 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.ogv')
411 await makeUploadRequest({
413 path: path + '/upload',
414 token: server.accessToken,
417 statusCodeExpected: 200
423 describe('When updating a video', function () {
424 const baseCorrectParams = {
425 name: 'my super name',
430 commentsEnabled: false,
431 description: 'my super description',
432 privacy: VideoPrivacy.PUBLIC,
433 tags: [ 'tag1', 'tag2' ]
436 before(async function () {
437 const res = await getVideosList(server.url)
438 videoId = res.body.data[0].uuid
441 it('Should fail with nothing', async function () {
443 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
446 it('Should fail without a valid uuid', async function () {
447 const fields = baseCorrectParams
448 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
451 it('Should fail with an unknown id', async function () {
452 const fields = baseCorrectParams
454 await makePutBodyRequest({
456 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
457 token: server.accessToken,
459 statusCodeExpected: 404
463 it('Should fail with a long name', async function () {
464 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
466 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
469 it('Should fail with a bad category', async function () {
470 const fields = immutableAssign(baseCorrectParams, { category: 125 })
472 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
475 it('Should fail with a bad licence', async function () {
476 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
478 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
481 it('Should fail with a bad language', async function () {
482 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
484 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
487 it('Should fail with a long description', async function () {
488 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
490 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
493 it('Should fail with a long support text', async function () {
494 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
496 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
499 it('Should fail with a bad channel', async function () {
500 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
502 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
505 it('Should fail with too many tags', async function () {
506 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
508 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
511 it('Should fail with a tag length too low', async function () {
512 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
514 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
517 it('Should fail with a tag length too big', async function () {
518 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
520 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
523 it('Should fail with a bad schedule update (miss updateAt)', async function () {
524 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
526 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
529 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
530 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
532 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
535 it('Should fail with an incorrect thumbnail file', async function () {
536 const fields = baseCorrectParams
538 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
541 await makeUploadRequest({
544 path: path + videoId,
545 token: server.accessToken,
551 it('Should fail with a big thumbnail file', async function () {
552 const fields = baseCorrectParams
554 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
557 await makeUploadRequest({
560 path: path + videoId,
561 token: server.accessToken,
567 it('Should fail with an incorrect preview file', async function () {
568 const fields = baseCorrectParams
570 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
573 await makeUploadRequest({
576 path: path + videoId,
577 token: server.accessToken,
583 it('Should fail with a big preview file', async function () {
584 const fields = baseCorrectParams
586 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
589 await makeUploadRequest({
592 path: path + videoId,
593 token: server.accessToken,
599 it('Should fail with a video of another user without the appropriate right', async function () {
600 const fields = baseCorrectParams
602 await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 })
605 it('Should fail with a video of another server')
607 it('Should succeed with the correct parameters', async function () {
608 const fields = baseCorrectParams
610 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
614 describe('When getting a video', function () {
615 it('Should return the list of the videos with nothing', async function () {
616 const res = await makeGetRequest({
619 statusCodeExpected: 200
622 expect(res.body.data).to.be.an('array')
623 expect(res.body.data.length).to.equal(3)
626 it('Should fail without a correct uuid', async function () {
627 await getVideo(server.url, 'coucou', 400)
630 it('Should return 404 with an incorrect video', async function () {
631 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
634 it('Should succeed with the correct parameters', async function () {
635 await getVideo(server.url, videoId)
639 describe('When rating a video', function () {
642 before(async function () {
643 const res = await getVideosList(server.url)
644 videoId = res.body.data[0].id
647 it('Should fail without a valid uuid', async function () {
651 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
654 it('Should fail with an unknown id', async function () {
658 await makePutBodyRequest({
660 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
661 token: server.accessToken,
663 statusCodeExpected: 404
667 it('Should fail with a wrong rating', async function () {
671 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
674 it('Should succeed with the correct parameters', async function () {
678 await makePutBodyRequest({
680 path: path + videoId + '/rate',
681 token: server.accessToken,
683 statusCodeExpected: 204
688 describe('When removing a video', function () {
689 it('Should have 404 with nothing', async function () {
690 await makeDeleteRequest({
693 statusCodeExpected: 400
697 it('Should fail without a correct uuid', async function () {
698 await removeVideo(server.url, server.accessToken, 'hello', 400)
701 it('Should fail with a video which does not exist', async function () {
702 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
705 it('Should fail with a video of another user without the appropriate right', async function () {
706 await removeVideo(server.url, userAccessToken, videoId, 403)
709 it('Should fail with a video of another server')
711 it('Should succeed with the correct parameters', async function () {
712 await removeVideo(server.url, server.accessToken, videoId)
716 after(async function () {
717 killallServers([ server ])
719 // Keep the logs if the test failed