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, uploadVideo,
11 runServer, ServerInfo, setAccessTokensToServers, userLogin, updateCustomSubConfig
12 } from '../../../../shared/utils'
14 checkBadCountPagination,
15 checkBadSortPagination,
16 checkBadStartPagination
17 } from '../../../../shared/utils/requests/check-api-params'
18 import { getAccountsList } from '../../../../shared/utils/users/accounts'
20 const expect = chai.expect
22 describe('Test videos API validator', function () {
23 const path = '/api/v1/videos/'
24 let server: ServerInfo
25 let userAccessToken = ''
26 let accountName: string
28 let channelName: string
31 // ---------------------------------------------------------------
33 before(async function () {
38 server = await runServer(1)
40 await setAccessTokensToServers([ server ])
42 const username = 'user1'
43 const password = 'my super password'
44 await createUser(server.url, server.accessToken, username, password)
45 userAccessToken = await userLogin(server, { username, password })
48 const res = await getMyUserInformation(server.url, server.accessToken)
49 channelId = res.body.videoChannels[ 0 ].id
50 channelName = res.body.videoChannels[ 0 ].name
51 accountName = res.body.account.name + '@' + res.body.account.host
55 describe('When listing a video', function () {
56 it('Should fail with a bad start pagination', async function () {
57 await checkBadStartPagination(server.url, path)
60 it('Should fail with a bad count pagination', async function () {
61 await checkBadCountPagination(server.url, path)
64 it('Should fail with an incorrect sort', async function () {
65 await checkBadSortPagination(server.url, path)
68 it('Should success with the correct parameters', async function () {
69 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
73 describe('When searching a video', function () {
75 it('Should fail with nothing', async function () {
76 await makeGetRequest({
78 path: join(path, 'search'),
79 statusCodeExpected: 400
83 it('Should fail with a bad start pagination', async function () {
84 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
87 it('Should fail with a bad count pagination', async function () {
88 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
91 it('Should fail with an incorrect sort', async function () {
92 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
95 it('Should success with the correct parameters', async function () {
96 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
100 describe('When listing my videos', function () {
101 const path = '/api/v1/users/me/videos'
103 it('Should fail with a bad start pagination', async function () {
104 await checkBadStartPagination(server.url, path, server.accessToken)
107 it('Should fail with a bad count pagination', async function () {
108 await checkBadCountPagination(server.url, path, server.accessToken)
111 it('Should fail with an incorrect sort', async function () {
112 await checkBadSortPagination(server.url, path, server.accessToken)
115 it('Should success with the correct parameters', async function () {
116 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 })
120 describe('When listing account videos', function () {
123 before(async function () {
124 path = '/api/v1/accounts/' + accountName + '/videos'
127 it('Should fail with a bad start pagination', async function () {
128 await checkBadStartPagination(server.url, path, server.accessToken)
131 it('Should fail with a bad count pagination', async function () {
132 await checkBadCountPagination(server.url, path, server.accessToken)
135 it('Should fail with an incorrect sort', async function () {
136 await checkBadSortPagination(server.url, path, server.accessToken)
139 it('Should success with the correct parameters', async function () {
140 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
144 describe('When listing video channel videos', function () {
147 before(async function () {
148 path = '/api/v1/video-channels/' + channelName + '/videos'
151 it('Should fail with a bad start pagination', async function () {
152 await checkBadStartPagination(server.url, path, server.accessToken)
155 it('Should fail with a bad count pagination', async function () {
156 await checkBadCountPagination(server.url, path, server.accessToken)
159 it('Should fail with an incorrect sort', async function () {
160 await checkBadSortPagination(server.url, path, server.accessToken)
163 it('Should success with the correct parameters', async function () {
164 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
168 describe('When adding a video', function () {
169 let baseCorrectParams
170 const baseCorrectAttaches = {
171 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.webm')
175 // Put in before to have channelId
176 baseCorrectParams = {
177 name: 'my super name',
182 commentsEnabled: true,
183 downloadEnabled: true,
184 waitTranscoding: true,
185 description: 'my super description',
186 support: 'my super support text',
187 tags: [ 'tag1', 'tag2' ],
188 privacy: VideoPrivacy.PUBLIC,
189 channelId: channelId,
190 originallyPublishedAt: new Date().toISOString()
194 it('Should fail with nothing', async function () {
197 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
200 it('Should fail without name', async function () {
201 const fields = omit(baseCorrectParams, 'name')
202 const attaches = baseCorrectAttaches
204 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
207 it('Should fail with a long name', async function () {
208 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
209 const attaches = baseCorrectAttaches
211 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
214 it('Should fail with a bad category', async function () {
215 const fields = immutableAssign(baseCorrectParams, { category: 125 })
216 const attaches = baseCorrectAttaches
218 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
221 it('Should fail with a bad licence', async function () {
222 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
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 language', async function () {
229 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
230 const attaches = baseCorrectAttaches
232 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
235 it('Should fail with a long description', async function () {
236 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
237 const attaches = baseCorrectAttaches
239 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
242 it('Should fail with a long support text', async function () {
243 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
244 const attaches = baseCorrectAttaches
246 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
249 it('Should fail without a channel', async function () {
250 const fields = omit(baseCorrectParams, 'channelId')
251 const attaches = baseCorrectAttaches
253 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
256 it('Should fail with a bad channel', async function () {
257 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
258 const attaches = baseCorrectAttaches
260 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
263 it('Should fail with another user channel', async function () {
266 password: 'fake_password'
268 await createUser(server.url, server.accessToken, user.username, user.password)
270 const accessTokenUser = await userLogin(server, user)
271 const res = await getMyUserInformation(server.url, accessTokenUser)
272 const customChannelId = res.body.videoChannels[0].id
274 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
275 const attaches = baseCorrectAttaches
277 await makeUploadRequest({ url: server.url, path: path + '/upload', token: userAccessToken, fields, attaches })
280 it('Should fail with too many tags', async function () {
281 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
282 const attaches = baseCorrectAttaches
284 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
287 it('Should fail with a tag length too low', async function () {
288 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
289 const attaches = baseCorrectAttaches
291 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
294 it('Should fail with a tag length too big', async function () {
295 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
296 const attaches = baseCorrectAttaches
298 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
301 it('Should fail with a bad schedule update (miss updateAt)', async function () {
302 const fields = immutableAssign(baseCorrectParams, { 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC })
303 const attaches = baseCorrectAttaches
305 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
308 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
309 const fields = immutableAssign(baseCorrectParams, {
310 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC,
311 'scheduleUpdate[updateAt]': 'toto'
313 const attaches = baseCorrectAttaches
315 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
318 it('Should fail with a bad originally published at attribute', async function () {
319 const fields = immutableAssign(baseCorrectParams, { 'originallyPublishedAt': 'toto' })
320 const attaches = baseCorrectAttaches
322 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
325 it('Should fail without an input file', async function () {
326 const fields = baseCorrectParams
328 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
331 it('Should fail without an incorrect input file', async function () {
332 const fields = baseCorrectParams
334 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm')
336 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
339 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mkv')
341 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
344 it('Should fail with an incorrect thumbnail file', async function () {
345 const fields = baseCorrectParams
347 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.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 a big thumbnail file', async function () {
355 const fields = baseCorrectParams
357 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.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 an incorrect preview file', async function () {
365 const fields = baseCorrectParams
367 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.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 fail with a big preview file', async function () {
375 const fields = baseCorrectParams
377 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
378 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
381 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
384 it('Should succeed with the correct parameters', async function () {
387 const fields = baseCorrectParams
390 const attaches = baseCorrectAttaches
391 await makeUploadRequest({
393 path: path + '/upload',
394 token: server.accessToken,
397 statusCodeExpected: 200
402 const attaches = immutableAssign(baseCorrectAttaches, {
403 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
406 await makeUploadRequest({
408 path: path + '/upload',
409 token: server.accessToken,
412 statusCodeExpected: 200
417 const attaches = immutableAssign(baseCorrectAttaches, {
418 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.ogv')
421 await makeUploadRequest({
423 path: path + '/upload',
424 token: server.accessToken,
427 statusCodeExpected: 200
433 describe('When updating a video', function () {
434 const baseCorrectParams = {
435 name: 'my super name',
440 commentsEnabled: false,
441 downloadEnabled: false,
442 description: 'my super description',
443 privacy: VideoPrivacy.PUBLIC,
444 tags: [ 'tag1', 'tag2' ]
447 before(async function () {
448 const res = await getVideosList(server.url)
449 videoId = res.body.data[0].uuid
452 it('Should fail with nothing', async function () {
454 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
457 it('Should fail without a valid uuid', async function () {
458 const fields = baseCorrectParams
459 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
462 it('Should fail with an unknown id', async function () {
463 const fields = baseCorrectParams
465 await makePutBodyRequest({
467 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
468 token: server.accessToken,
470 statusCodeExpected: 404
474 it('Should fail with a long name', async function () {
475 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
477 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
480 it('Should fail with a bad category', async function () {
481 const fields = immutableAssign(baseCorrectParams, { category: 125 })
483 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
486 it('Should fail with a bad licence', async function () {
487 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
489 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
492 it('Should fail with a bad language', async function () {
493 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
495 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
498 it('Should fail with a long description', async function () {
499 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
501 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
504 it('Should fail with a long support text', async function () {
505 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
507 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
510 it('Should fail with a bad channel', async function () {
511 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
513 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
516 it('Should fail with too many tags', async function () {
517 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
519 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
522 it('Should fail with a tag length too low', async function () {
523 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
525 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
528 it('Should fail with a tag length too big', async function () {
529 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
531 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
534 it('Should fail with a bad schedule update (miss updateAt)', async function () {
535 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
537 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
540 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
541 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
543 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
546 it('Should fail with a bad originally published at param', async function () {
547 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
549 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
552 it('Should fail with an incorrect thumbnail file', async function () {
553 const fields = baseCorrectParams
555 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
558 await makeUploadRequest({
561 path: path + videoId,
562 token: server.accessToken,
568 it('Should fail with a big thumbnail file', async function () {
569 const fields = baseCorrectParams
571 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
574 await makeUploadRequest({
577 path: path + videoId,
578 token: server.accessToken,
584 it('Should fail with an incorrect preview file', async function () {
585 const fields = baseCorrectParams
587 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
590 await makeUploadRequest({
593 path: path + videoId,
594 token: server.accessToken,
600 it('Should fail with a big preview file', async function () {
601 const fields = baseCorrectParams
603 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
606 await makeUploadRequest({
609 path: path + videoId,
610 token: server.accessToken,
616 it('Should fail with a video of another user without the appropriate right', async function () {
617 const fields = baseCorrectParams
619 await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 })
622 it('Should fail with a video of another server')
624 it('Should succeed with the correct parameters', async function () {
625 const fields = baseCorrectParams
627 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
631 describe('When getting a video', function () {
632 it('Should return the list of the videos with nothing', async function () {
633 const res = await makeGetRequest({
636 statusCodeExpected: 200
639 expect(res.body.data).to.be.an('array')
640 expect(res.body.data.length).to.equal(3)
643 it('Should fail without a correct uuid', async function () {
644 await getVideo(server.url, 'coucou', 400)
647 it('Should return 404 with an incorrect video', async function () {
648 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
651 it('Should succeed with the correct parameters', async function () {
652 await getVideo(server.url, videoId)
656 describe('When rating a video', function () {
659 before(async function () {
660 const res = await getVideosList(server.url)
661 videoId = res.body.data[0].id
664 it('Should fail without a valid uuid', async function () {
668 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
671 it('Should fail with an unknown id', async function () {
675 await makePutBodyRequest({
677 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
678 token: server.accessToken,
680 statusCodeExpected: 404
684 it('Should fail with a wrong rating', async function () {
688 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
691 it('Should succeed with the correct parameters', async function () {
695 await makePutBodyRequest({
697 path: path + videoId + '/rate',
698 token: server.accessToken,
700 statusCodeExpected: 204
705 describe('When removing a video', function () {
706 it('Should have 404 with nothing', async function () {
707 await makeDeleteRequest({
710 statusCodeExpected: 400
714 it('Should fail without a correct uuid', async function () {
715 await removeVideo(server.url, server.accessToken, 'hello', 400)
718 it('Should fail with a video which does not exist', async function () {
719 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
722 it('Should fail with a video of another user without the appropriate right', async function () {
723 await removeVideo(server.url, userAccessToken, videoId, 403)
726 it('Should fail with a video of another server')
728 it('Should succeed with the correct parameters', async function () {
729 await removeVideo(server.url, server.accessToken, videoId)
733 after(async function () {
734 killallServers([ server ])
736 // Keep the logs if the test failed